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)))))));
 }
Example #2
0
        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);
        }
Example #3
0
        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)));
        }
Example #4
0
        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));
        }
Example #5
0
        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));
        }