C# Expression Trees

Just a quick example that you can try yourself. It can be hard to write and debug Expression Trees but they are very powerful.

using System;
using System.Linq.Expressions;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Func<int, int> f = (x) => x + 1; // Same as: x++
var result = f(1);
Console.WriteLine("My result: " + result);

// ------

var result2 = f.Invoke(1);
Console.WriteLine("My result (via Invoke): " + result2);

// ------

ParameterExpression param0 = Expression.Parameter(typeof(int)); // first parameter
ParameterExpression param1 = Expression.Parameter(typeof(int)); // second parameter
ConstantExpression const0 = Expression.Constant(1);             // a constant

BinaryExpression expr = Expression.Add(Expression.Subtract(param1, const0), param0); // Same as: param1 - constant + param0
Expression<Func<int, int, int>> lambdaExpr = Expression.Lambda<Func<int, int, int>>(expr, param0, param1); // creates the lambda delegate

Func<int, int, int> compiledExpr = lambdaExpr.Compile(); // compiles the expression tree
var result3 = compiledExpr(1, 1); // executes the epxression tree with param0 and param1

Console.WriteLine("My result via Expression: " + result3);

// Don't close the console directly
Console.ReadLine();
}
}
}

See also the ExpandoObject in C#.

Enjoy 😉

Advertisements

UX, UI, Prototyping and creating Sketches

SketchFlow:

SketchFlow is very easy to use!

Axure RP:

[ sketchflow ] [ axure rp ]

Microsoft Expression Blend SDK for Windows Phone 7

Expression Blend 4 for Windows Phone SDK enables support for the same streamlined development workflow for Windows Phone that was previously only available for Silverlight and .NET applications, including features such as behaviors and the visual state manager.

Download the Expression Blend Software Development Kit for Windows Phone 7 here!

[ source ]

Expression SuperPreview

Just found out about SuperPreview:

What is SuperPreview?

SuperPreview speeds browser compatibility testing

Expression Web speeds the essential task of browser compatibility testing. With SuperPreview, you can debug your pages on the same machine that you use for development. You can view your pages in multiple browsers simultaneously or view how a page renders in a browser and compare it to a comp or mock-up image of a page. SuperPreview includes a local client as well as a Web service.

SuperPreview not only shows a high-fidelity rendering of how pages will look on different browsers, but it also identifies the element’s tag, size and position, applied styles, and location in the DOM (Document Object Model) tree so you can quickly fix the error.

SuperPreview installs with Expression Web. You can easily test pages at any stage in the design process, and launch SuperPreview from directly from Expression Web.

[ source ]