public Expression Mutate(Expression oldExpression, Expression processor, Expression owner, IStateMember member, Expression descriptor) { if (!_nullProcessorImplemented) { return(oldExpression); } Type memberType = member.MemberType; if (!member.CanRead || // Currently the INullProcessor gets a IWriteOnlyValueDescriptor<T>, thats why we check // if the member can write. !member.CanWrite || (memberType.IsValueType && !memberType.IsNullable())) { return(oldExpression); } MethodInfo method = _processNull.MakeGenericMethod(member.MemberType); // if (value == null) // { // processor.ProcessNull<TField>(descriptor); // } // else // { // oldExpression(); // } var value = member.GetGetExpression(owner); Expression body = Expression.Condition(Expression.Equal(value, ExpressionExtensions.Null), Expression.Call(processor, method, descriptor), oldExpression); return(body); }
public Expression Mutate(Expression oldExpression, Expression processor, Expression owner, IStateMember member, Expression descriptor) { if (!_isRevisitedFilter && !_isRevisitedProcessor) { return(oldExpression); } Type memberType = member.MemberType; if (!member.CanRead || (memberType.IsValueType && !memberType.IsNullable())) { return(oldExpression); } Expression processRevisited = GetProcessRevisitedExpression(processor, descriptor, memberType); // Generated code should look like this : // if (processor.Visited(value) // { // processor.ProcessRevisited(descriptor); || Empty Expression // } // else // { // oldValue(); // } var value = member.GetGetExpression(owner); Expression body = Expression.Condition(Expression.Call(processor, _visitedMethod, value), processRevisited, oldExpression); return(body); }
public Expression Mutate(Expression oldExpression, Expression processor, Expression owner, IStateMember member, Expression descriptor) { if (!member.CanRead) { return(oldExpression); } Type memberType = member.MemberType; if (memberType.IsValueType || memberType.IsSealed) { return(oldExpression); } ParameterExpression runtimeType = Expression.Variable(typeof(Type), member.Name.FirstLowerCase() + "RuntimeType"); var memberTypeConstant = memberType.Constant(); var value = member.GetGetExpression(owner); var runtimeTypeAssign = Expression.Condition(Expression.Equal(value, ExpressionExtensions.Null), Expression.Assign(runtimeType, memberTypeConstant), Expression.Assign(runtimeType, Expression.Call(value, _getTypeMethod))); var routeCall = Expression.Call(descriptor, _routeMethod, Expression.Constant(member), runtimeType, owner.Convert <object>(), Expression.Constant(true)); if (memberType.IsAbstract || memberType.IsInterface) { // Replace the call with a route in this case. BlockExpression block = Expression.Block(new[] { runtimeType }, runtimeTypeAssign, routeCall); return(block); } else { // The code that should be generated is this : // Type runtimeType; // if (value != null) // { // runtimeType = value.GetType(); // } // else // { // runtimeType = memberType; // } // // if (runtimeType == memberType) // { // oldExpression(); // } // else // { // descriptor.Route(member, runtimeType, owner, true); // } // Expression result = Expression.Block(new[] { runtimeType }, runtimeTypeAssign, Expression.Condition (Expression.Equal(runtimeType, member.MemberType.Constant()), oldExpression, routeCall)); return(result); } }
private static Expression GetGetterExpression <T>(IStateMember member, Expression instance) { // We need to convert to the type, since sometimes we fake the member type. return(member.GetGetExpression(instance).Convert(typeof(T))); }
public Expression GetGetExpression(Expression obj) { return(_underlying.GetGetExpression(obj)); }
public Expression GetGetExpression(Expression obj) { return(_underlying.GetGetExpression(obj).Convert(MemberType)); }
public Expression GetGetExpression(Expression obj) { return(_stateMember.GetGetExpression(obj)); }