15. protected virtual Expression VisitBinary(BinaryExpression b)
{
Expression left = this.Visit(b.Left);
Expression right = this.Visit(b.Right);
return b;
}
16. protected virtual Expression VisitBinary(BinaryExpression b)
{
Expression left = this.Visit(b.Left);
Expression right = this.Visit(b.Right);
if (left != b.Left || right != b.Right)
{
return Expression.MakeBinary(
b.NodeType, left, right, b.Method
);
}
return b;
}
17.
18.
19.
20.
21.
22. IQueryable<Tree> forest = // ...
var queryable = from tree in forest
where tree.HasHollow
select tree.ColectSomeHoney();
var queryable = forest.Where(tree => tree.HasHollow)
.Select(tree => tree.ColectSomeHoney());
var queryable = Queryable.Select(
Queryable.Where(forest, tree => tree.HasHollow),
tree => tree.ColectSomeHoney() );
var queryable = Enumerable.Select(
Enumerable.Where(forest.AsEnumerable (), tree => tree.HasHollow),
tree => tree.ColectSomeHoney() );
23. internal override Expression VisitMethodCall(MethodCallExpression m)
{
Expression instance = base.VisitMethodCall(m);
if (m.Method.DeclaringType == typeof(Queryable))
{
MethodInfo info = FindEnumerableMethod(m.Method);
return Expression.Call(instance, info, source);
}
return m;
}
24. internal override Expression VisitMethodCall(MethodCallExpression m)
{
Expression instance = base.VisitMethodCall(m);
if (m.Method.DeclaringType == typeof(Queryable))
{
MethodInfo info = FindEnumerableMethod(m.Method);
return Expression.Call(instance, info, source);
}
return m;
}
30. Reflection in compile time
public class Tree
{
public Honey ColectSomeHoney()
{
//...
return new Honey();
}
}
private static void Main()
{
MethodInfo method =
typeof(Tree).GetMethod( "ColectSomeHoney",
BindingFlags.Public | BindingFlags.Instance
);
}
31. Reflection in compile time
public class Tree
{
public Honey CollectSomeHoney()
{
//...
return new Honey();
}
}
private static void Main()
{
MethodInfo method =
typeof(Tree).GetMethod( "ColectSomeHoney",
BindingFlags.Public | BindingFlags.Instance
);
}
32. Reflection in compile time
public class Tree
{
public Honey CollectSomeHoney()
{
//...
return new Honey();
}
}
private static void Main()
{
MethodInfo method =
typeof(Tree).GetMethod( "ColectSomeHoney",
BindingFlags.Public | BindingFlags.Instance
);
}
33. Reflection in compile time
private static void Main()
{
var method = GetMethod<Tree>(x => x.ColectSomeHoney());
}
public static MethodInfo GetMethod<T>(Expression<Action<T>> e)
{
return ((MethodCallExpression) e.Body)
.Method;
}
34. Reflection in compile time
private static void Main()
{
var method = GetMethod<Tree>(x => x.CollectSomeHoney());
}
public static MethodInfo GetMethod<T>(Expression<Action<T>> e)
{
return ((MethodCallExpression) e.Body)
.Method;
}