Expression Tree Tutorial TypeAs
You can build an expression tree which contains an explicit reference or boxing conversion using
Expression.TypeAs method. For example, you have the following code.
Employee e = new Employee(); object objEmp = e as object;
Here is the code that is required to build the same functionality using expression tree.
UnaryExpression typeAsExpression = Expression.TypeAs( Expression.Constant(e, typeof(Employee)),typeof(object)); Console.WriteLine(typeAsExpression.ToString());