private static Expression CreateInvoke(DuplexCallback callback, Type returnType, IEnumerable <Expression> arguments = null) { return(Expression.Call( Expression.Constant(callback), returnType == typeof(void) ? DuplexCallback.serverInvokeVoidMethod : DuplexCallback.serverInvokeMethod.MakeGenericMethod(returnType), Expression.NewArrayInit( typeof(object), (arguments == null ? new Expression[0] : arguments.Select(a => (Expression)Expression.Convert(a, typeof(object))))))); }
protected override Expression TryEvaluateObservable(object value, Type type, QbservableProtocol protocol) { var observableType = value.GetType().GetGenericInterfaceFromDefinition(typeof(IObservable <>)); if (observableType != null) { return(DuplexCallback.CreateObservable(protocol, value, observableType.GetGenericArguments()[0], type)); } return(null); }
public override Expression Invoke(MethodCallExpression call, ExpressionVisitor visitor, QbservableProtocol protocol) { object instance; if (call.Method.ReturnType == typeof(void)) { instance = null; } else { instance = Evaluate(call.Object, visitor, Errors.ExpressionCallMissingLocalInstanceFormat, call.Method); } return(DuplexCallback.Create(protocol, instance, call.Method, visitor.Visit(call.Arguments))); }
protected override Either <object, Expression> TryEvaluateEnumerable(object value, Type type, QbservableProtocol protocol) { Expression expression = null; if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable <>)) { expression = DuplexCallback.CreateEnumerable(protocol, value, type.GetGenericArguments()[0], type); } else if (type == typeof(IEnumerable)) { var enumerable = (IEnumerable)value; expression = DuplexCallback.CreateEnumerable(protocol, enumerable.Cast <object>(), typeof(object), type); } return(expression == null ? null : Either.Right <object, Expression>(expression)); }
public override Expression GetValue(FieldInfo field, MemberExpression member, ExpressionVisitor visitor, QbservableProtocol protocol) { object instance = Evaluate(member.Expression, visitor, Errors.ExpressionMemberMissingLocalInstanceFormat, member.Member); return(DuplexCallback.Create(protocol, instance, field)); }
public override Expression GetValue(FieldInfo field, MemberExpression member, ExpressionVisitor visitor, IQbservableProtocol protocol) => DuplexCallback.Create( field.DeclaringType.Name + "." + field.Name, protocol, Evaluate(member.Expression, visitor, _ => Errors.ExpressionMemberMissingLocalInstanceFormat, member.Member), field);