Beispiel #1
0
        /// <summary>
        /// Creates a CallSite with the given delegate type and binder.
        /// </summary>
        /// <param name="delegateType">The CallSite delegate type.</param>
        /// <param name="binder">The CallSite binder.</param>
        /// <returns>The new CallSite.</returns>
        public static CallSite Create(Type delegateType, CallSiteBinder binder)
        {
            ContractUtils.RequiresNotNull(delegateType, "delegateType");
            ContractUtils.RequiresNotNull(binder, "binder");
            if (!delegateType.IsSubclassOf(typeof(MulticastDelegate))) throw Error.TypeMustBeDerivedFromSystemDelegate();

            var ctors = s_siteCtors;
            if (ctors == null) {
                // It's okay to just set this, worst case we're just throwing away some data
                s_siteCtors = ctors = new CacheDict<Type, Func<CallSiteBinder, CallSite>>(100);
            }

            Func<CallSiteBinder, CallSite> ctor;
            MethodInfo method = null;
            if (!ctors.TryGetValue(delegateType, out ctor))
            {
                method = typeof(CallSite<>).MakeGenericType(delegateType).GetMethod("Create");

                if (TypeUtils.CanCache(delegateType))
                {
                    ctor = (Func<CallSiteBinder, CallSite>)method.CreateDelegate(typeof(Func<CallSiteBinder, CallSite>));
                    ctors.Add(delegateType, ctor);
                }
            }

            if (ctor != null)
            {
                return ctor(binder);
            }

            // slow path
            return (CallSite)method.Invoke(null, new object[] { binder });
        }
 public static CallSite Create(Type delegateType, CallSiteBinder binder)
 {
     Func<CallSiteBinder, CallSite> func;
     ContractUtils.RequiresNotNull(delegateType, "delegateType");
     ContractUtils.RequiresNotNull(binder, "binder");
     if (!delegateType.IsSubclassOf(typeof(Delegate)))
     {
         throw Error.TypeMustBeDerivedFromSystemDelegate();
     }
     if (_SiteCtors == null)
     {
         _SiteCtors = new CacheDict<Type, Func<CallSiteBinder, CallSite>>(100);
     }
     MethodInfo method = null;
     CacheDict<Type, Func<CallSiteBinder, CallSite>> dict = _SiteCtors;
     lock (dict)
     {
         if (!dict.TryGetValue(delegateType, out func))
         {
             method = typeof(CallSite<>).MakeGenericType(new Type[] { delegateType }).GetMethod("Create");
             if (delegateType.CanCache())
             {
                 func = (Func<CallSiteBinder, CallSite>) Delegate.CreateDelegate(typeof(Func<CallSiteBinder, CallSite>), method);
                 dict.Add(delegateType, func);
             }
         }
     }
     if (func != null)
     {
         return func(binder);
     }
     return (CallSite) method.Invoke(null, new object[] { binder });
 }
        /// <summary>
        /// Reduces the dynamic expression to a binder and a set of arguments to apply the operation to.
        /// </summary>
        /// <param name="binder">The binder used to perform the dynamic operation.</param>
        /// <param name="arguments">The arguments to apply the dynamic operation to.</param>
        /// <param name="argumentTypes">The types of the arguments to use for the dynamic call site. Return null to infer types.</param>
        protected override void ReduceDynamic(out CallSiteBinder binder, out IEnumerable<Expression> arguments, out Type[] argumentTypes)
        {
            var nodeType = OperationNodeType;

            switch (nodeType)
            {
                case ExpressionType.AddChecked:
                    nodeType = ExpressionType.Add;
                    break;
                case ExpressionType.MultiplyChecked:
                    nodeType = ExpressionType.Multiply;
                    break;
                case ExpressionType.SubtractChecked:
                    nodeType = ExpressionType.Subtract;
                    break;
                case ExpressionType.AndAlso:
                    nodeType = ExpressionType.And;
                    break;
                case ExpressionType.OrElse:
                    nodeType = ExpressionType.Or;
                    break;
            }

            binder = Binder.BinaryOperation(Flags, nodeType, Context, new[] { Left.ArgumentInfo, Right.ArgumentInfo });
            arguments = new[] { Left.Expression, Right.Expression };
            argumentTypes = null;
        }
Beispiel #4
0
 internal static DynamicExpression Make(Type returnType, Type delegateType, CallSiteBinder binder, ReadOnlyCollection<Expression> arguments) {
     if (returnType == typeof(object)) {
         return new DynamicExpressionN(delegateType, binder, arguments);
     } else {
         return new TypedDynamicExpressionN(returnType, delegateType, binder, arguments);
     }
 }
Beispiel #5
0
 internal static DynamicExpression Make(Type returnType, Type delegateType, CallSiteBinder binder, Expression arg0, Expression arg1, Expression arg2, Expression arg3) {
     if (returnType == typeof(object)) {
         return new DynamicExpression4(delegateType, binder, arg0, arg1, arg2, arg3);
     } else {
         return new TypedDynamicExpression4(returnType, delegateType, binder, arg0, arg1, arg2, arg3);
     }
 }
 internal DynamicExpression4(Type delegateType, CallSiteBinder binder, Expression arg0, Expression arg1, Expression arg2, Expression arg3) : base(delegateType, binder)
 {
     this._arg0 = arg0;
     this._arg1 = arg1;
     this._arg2 = arg2;
     this._arg3 = arg3;
 }
 internal static DynamicExpression Make(System.Type returnType, System.Type delegateType, CallSiteBinder binder, Expression arg0, Expression arg1, Expression arg2)
 {
     if (returnType == typeof(object))
     {
         return new DynamicExpression3(delegateType, binder, arg0, arg1, arg2);
     }
     return new TypedDynamicExpression3(returnType, delegateType, binder, arg0, arg1, arg2);
 }
        /// <summary>
        /// Creates a <see cref="DynamicExpression" /> that represents a dynamic operation bound by the provided <see cref="CallSiteBinder" />.
        /// </summary>
        /// <param name="binder">The runtime binder for the dynamic operation.</param>
        /// <param name="returnType">The result type of the dynamic expression.</param>
        /// <param name="arguments">The arguments to the dynamic operation.</param>
        /// <returns>
        /// A <see cref="DynamicExpression" /> that has <see cref="NodeType" /> equal to
        /// <see cref="ExpressionType.Dynamic">Dynamic</see> and has the
        /// <see cref="DynamicExpression.Binder">Binder</see> and
        /// <see cref="DynamicExpression.Arguments">Arguments</see> set to the specified values.
        /// </returns>
        /// <remarks>
        /// The <see cref="DynamicExpression.DelegateType">DelegateType</see> property of the
        /// result will be inferred from the types of the arguments and the specified return type.
        /// </remarks>
        public static DynamicExpression Dynamic(CallSiteBinder binder, Type returnType, IEnumerable<Expression> arguments)
        {
            ContractUtils.RequiresNotNull(arguments, nameof(arguments));
            ContractUtils.RequiresNotNull(returnType, nameof(returnType));

            var args = arguments.ToReadOnly();
            ContractUtils.RequiresNotEmpty(args, nameof(args));
            return MakeDynamic(binder, returnType, args);
        }
        internal static DynamicMetaObject RewriteStrongBoxAsRef(CallSiteBinder action, DynamicMetaObject target, DynamicMetaObject[] args, bool hasRhs) {
            Debug.Assert(action != null && target != null && args != null);

            var restrictions = target.Restrictions.Merge(BindingRestrictions.Combine(args));

            Expression[] argExpressions = new Expression[args.Length + 1];
            Type[] signatureTypes = new Type[args.Length + 3]; // args + CallSite, target, returnType

            signatureTypes[0] = typeof(CallSite);

            //we are not restricting on target type here.
            argExpressions[0] = target.Expression;
            signatureTypes[1] = target.Expression.Type;

            int argsToProcess = args.Length;

            if (hasRhs) {
                DynamicMetaObject rhsArgument = args[args.Length - 1];
                argExpressions[args.Length] = rhsArgument.Expression;
                signatureTypes[args.Length + 1] = rhsArgument.Expression.Type;
                argsToProcess--;
            }

            for (int i = 0; i < argsToProcess; i++) {
                DynamicMetaObject currArgument = args[i];
                if (IsStrongBoxArg(currArgument)) {
                    restrictions = restrictions.Merge(BindingRestrictions.GetTypeRestriction(currArgument.Expression, currArgument.LimitType));

                    // we have restricted this argument to LimitType so we can convert and conversion will be trivial cast.
                    Expression boxedValueAccessor = Expression.Field(
                        Helpers.Convert(
                            currArgument.Expression,
                            currArgument.LimitType
                        ),
                        currArgument.LimitType.GetField("Value")
                    );

                    argExpressions[i + 1] = boxedValueAccessor;
                    signatureTypes[i + 2] = boxedValueAccessor.Type.MakeByRefType();
                } else {
                    argExpressions[i + 1] = currArgument.Expression;
                    signatureTypes[i + 2] = currArgument.Expression.Type;
                }
            }
            
            // Last signatureType is the return value
            signatureTypes[signatureTypes.Length - 1] = typeof(object);

            return new DynamicMetaObject(
                Expression.MakeDynamic(
                    Expression.GetDelegateType(signatureTypes),
                    action,
                    argExpressions
                ),
                restrictions
            );
        }
Beispiel #10
0
        internal static Instruction CreateUntypedInstruction(CallSiteBinder binder, int argCount)
        {
            switch (argCount)
            {
                case 0:
                    return DynamicInstruction<object>.Factory(binder);

                case 1:
                    return DynamicInstruction<object, object>.Factory(binder);

                case 2:
                    return DynamicInstruction<object, object, object>.Factory(binder);

                case 3:
                    return DynamicInstruction<object, object, object, object>.Factory(binder);

                case 4:
                    return DynamicInstruction<object, object, object, object, object>.Factory(binder);

                case 5:
                    return DynamicInstruction<object, object, object, object, object, object>.Factory(binder);

                case 6:
                    return DynamicInstruction<object, object, object, object, object, object, object>.Factory(binder);

                case 7:
                    return DynamicInstruction<object, object, object, object, object, object, object, object>.Factory(binder);

                case 8:
                    return DynamicInstruction<object, object, object, object, object, object, object, object, object>.Factory(binder);

                case 9:
                    return DynamicInstruction<object, object, object, object, object, object, object, object, object, object>.Factory(binder);

                case 10:
                    return DynamicInstruction<object, object, object, object, object, object, object, object, object, object, object>.Factory(binder);

                case 11:
                    return DynamicInstruction<object, object, object, object, object, object, object, object, object, object, object, object>.Factory(binder);

                case 12:
                    return DynamicInstruction<object, object, object, object, object, object, object, object, object, object, object, object, object>.Factory(binder);

                case 13:
                    return DynamicInstruction<object, object, object, object, object, object, object, object, object, object, object, object, object, object>.Factory(binder);

                case 14:
                    return DynamicInstruction<object, object, object, object, object, object, object, object, object, object, object, object, object, object, object>.Factory(binder);

                case 15:
                    return DynamicInstruction<object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object>.Factory(binder);
            }
            return null;
        }
 public static Expression MakeDynamic(Type type, CallSiteBinder binder, IEnumerable<Expression> arguments, Type[] argumentTypes)
 {
     if (argumentTypes == null)
     {
         return Expression.Dynamic(binder, type, arguments);
     }
     else
     {
         // NB: This is a trick to leverage MakeCallSiteDelegate; we should refactor it to take in an array of types.
         var args = argumentTypes.Map(a => (Expression)Expression.Default(a)).ToReadOnly();
         var delegateType = DelegateHelpers.MakeCallSiteDelegate(args, type);
         return Expression.MakeDynamic(delegateType, binder, arguments);
     }
 }
        public static Instruction MakeInstruction(Type delegateType, CallSiteBinder binder) {
            Func<CallSiteBinder, Instruction> factory;
            if (!_factories.TryGetValue(delegateType, out factory)) {
                Type instructionType = GetDynamicInstructionType(delegateType);
                if (instructionType == null) {
                    return new DynamicInstructionN(delegateType, CallSite.Create(delegateType, binder));
                }

                factory = (Func<CallSiteBinder, Instruction>)Delegate.CreateDelegate(typeof(Func<CallSiteBinder, Instruction>),
                    instructionType.GetMethod("Factory"));
                _factories[delegateType] = factory;
            }
            return factory(binder);
        }
Beispiel #13
0
        internal static MetaObject RewriteStrongBoxAsRef(CallSiteBinder action, MetaObject target, MetaObject[] args) {
            Debug.Assert(action != null && target != null && args != null);

            var restrictions = target.Restrictions.Merge(Restrictions.Combine(args));

            Expression[] argExpressions = new Expression[args.Length + 1];
            Type[] signatureTypes = new Type[args.Length + 3]; // args + CallSite, target, returnType

            signatureTypes[0] = typeof(CallSite);

            //TODO: we are not restricting on target type here, but in theory we could. 
            //It is a tradeoff between rule reuse and higher polymorphism of the site. 
            argExpressions[0] = target.Expression;
            signatureTypes[1] = target.Expression.Type;

            for (int i = 0; i < args.Length; i++) {
                MetaObject currArgument = args[i];
                if (IsStrongBoxArg(currArgument)) {
                    restrictions = restrictions.Merge(Restrictions.GetTypeRestriction(currArgument.Expression, currArgument.LimitType));

                    // we have restricted this argument to LimitType so we can convert and conversion will be trivial cast.
                    Expression boxedValueAccessor = Expression.Field(
                        Helpers.Convert(
                            currArgument.Expression,
                            currArgument.LimitType
                        ),
                        currArgument.LimitType.GetField("Value")
                    );

                    argExpressions[i + 1] = boxedValueAccessor;
                    signatureTypes[i + 2] = boxedValueAccessor.Type.MakeByRefType();
                } else {
                    argExpressions[i + 1] = currArgument.Expression;
                    signatureTypes[i + 2] = currArgument.Expression.Type;
                }
            }

            // Last signatureType is the return value
            signatureTypes[signatureTypes.Length - 1] = typeof(object);

            return new MetaObject(
                Expression.MakeDynamic(
                    Expression.GetDelegateType(signatureTypes),
                    action,
                    argExpressions
                ),
                restrictions
            );
        }
        /// <summary>
        /// Reduces the dynamic expression to a binder and a set of arguments to apply the operation to.
        /// </summary>
        /// <param name="binder">The binder used to perform the dynamic operation.</param>
        /// <param name="arguments">The arguments to apply the dynamic operation to.</param>
        /// <param name="argumentTypes">The types of the arguments to use for the dynamic call site. Return null to infer types.</param>
        protected override void ReduceDynamic(out CallSiteBinder binder, out IEnumerable<Expression> arguments, out Type[] argumentTypes)
        {
            var nodeType = OperationNodeType;

            switch (nodeType)
            {
                case ExpressionType.NegateChecked:
                    nodeType = ExpressionType.Negate;
                    break;
            }

            binder = Binder.UnaryOperation(Flags, nodeType, Context, new[] { Operand.ArgumentInfo });
            arguments = new[] { Operand.Expression };
            argumentTypes = null;
        }
        private DynamicMetaObject BindGetOrInvoke(CallSiteBinder binder, DynamicMetaObject[] args, IList<ArgumentInfo> argInfos) {
            if (args.Any(arg => ComBinderHelpers.IsStrongBoxArg(arg))) {
                return ComBinderHelpers.RewriteStrongBoxAsRef(binder, this, args, false);
            }

            ComMethodDesc method;
            var target = _callable.DispatchComObject;
            var name = _callable.MemberName;
            
            if (target.TryGetMemberMethod(name, out method) ||
                target.TryGetMemberMethodExplicit(name, out method)) {

                return BindComInvoke(method, args, argInfos);
            }
            return null;
        }
        /// <summary>
        /// Reduces the dynamic expression to a binder and a set of arguments to apply the operation to.
        /// </summary>
        /// <param name="binder">The binder used to perform the dynamic operation.</param>
        /// <param name="arguments">The arguments to apply the dynamic operation to.</param>
        /// <param name="argumentTypes">The types of the arguments to use for the dynamic call site. Return null to infer types.</param>
        protected override void ReduceDynamic(out CallSiteBinder binder, out IEnumerable<Expression> arguments, out Type[] argumentTypes)
        {
            var n = Arguments.Count;

            var argumentInfos = new CSharpArgumentInfo[n + 1];
            var expressions = new Expression[n + 1];

            expressions[0] = Expression;
            argumentInfos[0] = CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null);

            argumentTypes = null;
            CopyArguments(Arguments, argumentInfos, expressions, ref argumentTypes);

            binder = Binder.Invoke(Flags, Context, argumentInfos);
            arguments = expressions;
        }
        /// <summary>
        /// Reduces the dynamic expression to a binder and a set of arguments to apply the operation to.
        /// </summary>
        /// <param name="binder">The binder used to perform the dynamic operation.</param>
        /// <param name="arguments">The arguments to apply the dynamic operation to.</param>
        /// <param name="argumentTypes">The types of the arguments to use for the dynamic call site. Return null to infer types.</param>
        protected override void ReduceDynamic(out CallSiteBinder binder, out IEnumerable<Expression> arguments, out Type[] argumentTypes)
        {
            var n = Arguments.Count;

            var argumentInfos = new CSharpArgumentInfo[n + 1];
            var expressions = new Expression[n + 1];

            expressions[0] = Expression.Constant(Type, typeof(Type));
            argumentInfos[0] = CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.IsStaticType, null);

            argumentTypes = null;
            CopyArguments(Arguments, argumentInfos, expressions, ref argumentTypes);

            binder = Binder.InvokeConstructor(Flags, Context, argumentInfos);
            arguments = expressions;
        }
        /// <summary>
        /// Creates a <see cref="DynamicExpression" /> that represents a dynamic operation bound by the provided <see cref="CallSiteBinder" />.
        /// </summary>
        /// <param name="binder">The runtime binder for the dynamic operation.</param>
        /// <param name="returnType">The result type of the dynamic expression.</param>
        /// <param name="arg0">The first argument to the dynamic operation.</param>
        /// <returns>
        /// A <see cref="DynamicExpression" /> that has <see cref="NodeType" /> equal to
        /// <see cref="ExpressionType.Dynamic">Dynamic</see> and has the
        /// <see cref="DynamicExpression.Binder">Binder</see> and
        /// <see cref="DynamicExpression.Arguments">Arguments</see> set to the specified values.
        /// </returns>
        /// <remarks>
        /// The <see cref="DynamicExpression.DelegateType">DelegateType</see> property of the
        /// result will be inferred from the types of the arguments and the specified return type.
        /// </remarks>
        public static DynamicExpression Dynamic(CallSiteBinder binder, Type returnType, Expression arg0)
        {
            ContractUtils.RequiresNotNull(binder, nameof(binder));
            ValidateDynamicArgument(arg0, nameof(arg0));

            DelegateHelpers.TypeInfo info = DelegateHelpers.GetNextTypeInfo(
                returnType,
                DelegateHelpers.GetNextTypeInfo(
                    arg0.Type,
                    DelegateHelpers.NextTypeInfo(typeof(CallSite))
                )
            );

            Type delegateType = info.DelegateType ?? info.MakeDelegateType(returnType, arg0);

            return DynamicExpression.Make(returnType, delegateType, binder, arg0);
        }
        /// <summary>
        /// Reduces the dynamic expression to a binder and a set of arguments to apply the operation to.
        /// </summary>
        /// <param name="binder">The binder used to perform the dynamic operation.</param>
        /// <param name="arguments">The arguments to apply the dynamic operation to.</param>
        /// <param name="argumentTypes">The types of the arguments to use for the dynamic call site. Return null to infer types.</param>
        protected override void ReduceDynamic(out CallSiteBinder binder, out IEnumerable<Expression> arguments, out Type[] argumentTypes)
        {
            var n = Arguments.Count;

            var argumentInfos = new CSharpArgumentInfo[n + 1];
            var expressions = new Expression[n + 1];

            // NB: By-ref passing for the receiver seems to be omitted in Roslyn here; see https://github.com/dotnet/roslyn/issues/6818.
            //     We're choosing to be consistent with that behavior until further notice.
            expressions[0] = Object;
            argumentInfos[0] = CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null);

            argumentTypes = null;
            CopyArguments(Arguments, argumentInfos, expressions, ref argumentTypes);

            binder = Binder.GetIndex(Flags, Context, argumentInfos);
            arguments = expressions;
        }
Beispiel #20
0
        /// <summary>
        /// Creates a CallSite with the given delegate type and binder.
        /// </summary>
        /// <param name="delegateType">The CallSite delegate type.</param>
        /// <param name="binder">The CallSite binder.</param>
        /// <returns>The new CallSite.</returns>
        public static CallSite Create(Type delegateType, CallSiteBinder binder) {
            ContractUtils.RequiresNotNull(delegateType, "delegateType");
            ContractUtils.RequiresNotNull(binder, "binder");
            ContractUtils.Requires(delegateType.IsSubclassOf(typeof(Delegate)), "delegateType", Strings.TypeMustBeDerivedFromSystemDelegate);

            if (_SiteCtors == null) {
                // It's okay to just set this, worst case we're just throwing away some data
                _SiteCtors = new CacheDict<Type, Func<CallSiteBinder, CallSite>>(100);
            }
            Func<CallSiteBinder, CallSite> ctor;
            lock (_SiteCtors) {
                if (!_SiteCtors.TryGetValue(delegateType, out ctor)) {
                    MethodInfo method = typeof(CallSite<>).MakeGenericType(delegateType).GetMethod("Create");
                    ctor = (Func<CallSiteBinder, CallSite>)Delegate.CreateDelegate(typeof(Func<CallSiteBinder, CallSite>), method);
                    _SiteCtors.Add(delegateType, ctor);
                }
            }
            return ctor(binder);
        }
        public static Instruction MakeInstruction(Type delegateType, CallSiteBinder binder) {
            Func<CallSiteBinder, Instruction> factory;
            lock (_factories) {
                if (!_factories.TryGetValue(delegateType, out factory)) {
                    if (delegateType.GetMethod("Invoke").ReturnType == typeof(void)) {
                        // TODO: We should generally support void returning binders but the only
                        // ones that exist are delete index/member who's perf isn't that critical.
                        return new DynamicInstructionN(delegateType, CallSite.Create(delegateType, binder), true);
                    }

                    Type instructionType = GetDynamicInstructionType(delegateType);
                    if (instructionType == null) {
                        return new DynamicInstructionN(delegateType, CallSite.Create(delegateType, binder));
                    }

                    factory = (Func<CallSiteBinder, Instruction>)Delegate.CreateDelegate(typeof(Func<CallSiteBinder, Instruction>),
                        instructionType.GetMethod("Factory"));
                    _factories[delegateType] = factory;
                }
            }
            return factory(binder);
        }
 public static System.Linq.Expressions.DynamicExpression Dynamic(System.Runtime.CompilerServices.CallSiteBinder binder, System.Type returnType, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1, System.Linq.Expressions.Expression arg2)
 {
     throw null;
 }
 // Dev10 Bug 914027 - Changed the callsite's target parameter from dynamic to object, see comment at top for details
 public static CallSite<Func<CallSite, object, object>> GetMemberAccessCallSite(CallSiteBinder binder)
 {
     return CallSite<Func<CallSite, object, object>>.Create(binder);
 }
Beispiel #24
0
 // only CallSite<T> derives from this
 internal CallSite(CallSiteBinder binder) {
     _binder = binder;
 }
Beispiel #25
0
        private static DynamicExpression MakeDynamic(CallSiteBinder binder, Type returnType, ReadOnlyCollection<Expression> args) {
            ContractUtils.RequiresNotNull(binder, "binder");

            for (int i = 0; i < args.Count; i++) {
                Expression arg = args[i];

                ValidateDynamicArgument(arg);
            }

            Type delegateType = DelegateHelpers.MakeCallSiteDelegate(args, returnType);

            // Since we made a delegate with argument types that exactly match,
            // we can skip delegate and argument validation

            switch (args.Count) {
                case 1: return DynamicExpression.Make(returnType, delegateType, binder, args[0]);
                case 2: return DynamicExpression.Make(returnType, delegateType, binder, args[0], args[1]);
                case 3: return DynamicExpression.Make(returnType, delegateType, binder, args[0], args[1], args[2]);
                case 4: return DynamicExpression.Make(returnType, delegateType, binder, args[0], args[1], args[2], args[3]);
                default: return DynamicExpression.Make(returnType, delegateType, binder, args);
            }
        }
Beispiel #26
0
 public static CallSite Create(Type delegateType, CallSiteBinder binder)
 {
     return(null);
 }
Beispiel #27
0
        /// <summary>
        /// Creates a <see cref="DynamicExpression" /> that represents a dynamic operation bound by the provided <see cref="CallSiteBinder" />.
        /// </summary>
        /// <param name="binder">The runtime binder for the dynamic operation.</param>
        /// <param name="returnType">The result type of the dynamic expression.</param>
        /// <param name="arg0">The first argument to the dynamic operation.</param>
        /// <param name="arg1">The second argument to the dynamic operation.</param>
        /// <param name="arg2">The third argument to the dynamic operation.</param>
        /// <param name="arg3">The fourth argument to the dynamic operation.</param>
        /// <returns>
        /// A <see cref="DynamicExpression" /> that has <see cref="NodeType" /> equal to
        /// <see cref="ExpressionType.Dynamic">Dynamic</see> and has the
        /// <see cref="DynamicExpression.Binder">Binder</see> and
        /// <see cref="DynamicExpression.Arguments">Arguments</see> set to the specified values.
        /// </returns>
        /// <remarks>
        /// The <see cref="DynamicExpression.DelegateType">DelegateType</see> property of the
        /// result will be inferred from the types of the arguments and the specified return type.
        /// </remarks>
        public static DynamicExpression Dynamic(CallSiteBinder binder, Type returnType, Expression arg0, Expression arg1, Expression arg2, Expression arg3) {
            ContractUtils.RequiresNotNull(binder, "binder");
            ValidateDynamicArgument(arg0);
            ValidateDynamicArgument(arg1);
            ValidateDynamicArgument(arg2);
            ValidateDynamicArgument(arg3);

            DelegateHelpers.TypeInfo info = DelegateHelpers.GetNextTypeInfo(
                returnType,
                DelegateHelpers.GetNextTypeInfo(
                    arg3.Type,
                    DelegateHelpers.GetNextTypeInfo(
                        arg2.Type,
                        DelegateHelpers.GetNextTypeInfo(
                            arg1.Type,
                            DelegateHelpers.GetNextTypeInfo(
                                arg0.Type,
                                DelegateHelpers.NextTypeInfo(typeof(CallSite))
                            )
                        )
                    )
                )
            );

            Type delegateType = info.DelegateType;
            if (delegateType == null) {
                delegateType = info.MakeDelegateType(returnType, arg0, arg1, arg2, arg3);
            }

            return DynamicExpression.Make(returnType, delegateType, binder, arg0, arg1, arg2, arg3);
        }
Beispiel #28
0
 /// <summary>
 /// Creates a <see cref="DynamicExpression" /> that represents a dynamic operation bound by the provided <see cref="CallSiteBinder" />.
 /// </summary>
 /// <param name="binder">The runtime binder for the dynamic operation.</param>
 /// <param name="returnType">The result type of the dynamic expression.</param>
 /// <param name="arguments">The arguments to the dynamic operation.</param>
 /// <returns>
 /// A <see cref="DynamicExpression" /> that has <see cref="NodeType" /> equal to
 /// <see cref="ExpressionType.Dynamic">Dynamic</see> and has the
 /// <see cref="DynamicExpression.Binder">Binder</see> and
 /// <see cref="DynamicExpression.Arguments">Arguments</see> set to the specified values.
 /// </returns>
 /// <remarks>
 /// The <see cref="DynamicExpression.DelegateType">DelegateType</see> property of the
 /// result will be inferred from the types of the arguments and the specified return type.
 /// </remarks>
 public static DynamicExpression Dynamic(CallSiteBinder binder, Type returnType, params Expression[] arguments) {
     return Dynamic(binder, returnType, (IEnumerable<Expression>)arguments);
 }
Beispiel #29
0
        /// <summary>
        /// Creates a <see cref="DynamicExpression" /> that represents a dynamic operation bound by the provided <see cref="CallSiteBinder" /> and four arguments.
        /// </summary>
        /// <param name="delegateType">The type of the delegate used by the <see cref="CallSite" />.</param>
        /// <param name="binder">The runtime binder for the dynamic operation.</param>
        /// <param name="arg0">The first argument to the dynamic operation.</param>
        /// <param name="arg1">The second argument to the dynamic operation.</param>
        /// <param name="arg2">The third argument to the dynamic operation.</param>
        /// <param name="arg3">The fourth argument to the dynamic operation.</param>
        /// <returns>
        /// A <see cref="DynamicExpression" /> that has <see cref="NodeType" /> equal to
        /// <see cref="ExpressionType.Dynamic">Dynamic</see> and has the
        /// <see cref="DynamicExpression.DelegateType">DelegateType</see>,
        /// <see cref="DynamicExpression.Binder">Binder</see>, and
        /// <see cref="DynamicExpression.Arguments">Arguments</see> set to the specified values.
        /// </returns>
        public static DynamicExpression MakeDynamic(Type delegateType, CallSiteBinder binder, Expression arg0, Expression arg1, Expression arg2, Expression arg3) {
            ContractUtils.RequiresNotNull(delegateType, "delegateType");
            ContractUtils.RequiresNotNull(binder, "binder");
            if (!delegateType.IsSubclassOf(typeof(MulticastDelegate))) throw Error.TypeMustBeDerivedFromSystemDelegate();

            var method = GetValidMethodForDynamic(delegateType);
            var parameters = method.GetParametersCached();

            ValidateArgumentCount(method, ExpressionType.Dynamic, 5, parameters);
            ValidateDynamicArgument(arg0);
            ValidateOneArgument(method, ExpressionType.Dynamic, arg0, parameters[1]);
            ValidateDynamicArgument(arg1);
            ValidateOneArgument(method, ExpressionType.Dynamic, arg1, parameters[2]);
            ValidateDynamicArgument(arg2);
            ValidateOneArgument(method, ExpressionType.Dynamic, arg2, parameters[3]);
            ValidateDynamicArgument(arg3);
            ValidateOneArgument(method, ExpressionType.Dynamic, arg3, parameters[4]);

            return DynamicExpression.Make(method.GetReturnType(), delegateType, binder, arg0, arg1, arg2, arg3);
        }
Beispiel #30
0
 // only CallSite<T> derives from this
 internal CallSite(CallSiteBinder binder)
 {
     Binder = binder;
 }
Beispiel #31
0
        /// <summary>
        /// Creates a <see cref="DynamicExpression" /> that represents a dynamic operation bound by the provided <see cref="CallSiteBinder" />.
        /// </summary>
        /// <param name="delegateType">The type of the delegate used by the <see cref="CallSite" />.</param>
        /// <param name="binder">The runtime binder for the dynamic operation.</param>
        /// <param name="arguments">The arguments to the dynamic operation.</param>
        /// <returns>
        /// A <see cref="DynamicExpression" /> that has <see cref="NodeType" /> equal to
        /// <see cref="ExpressionType.Dynamic">Dynamic</see> and has the
        /// <see cref="DynamicExpression.DelegateType">DelegateType</see>,
        /// <see cref="DynamicExpression.Binder">Binder</see>, and
        /// <see cref="DynamicExpression.Arguments">Arguments</see> set to the specified values.
        /// </returns>
        public static DynamicExpression MakeDynamic(Type delegateType, CallSiteBinder binder, IEnumerable<Expression> arguments) {
            ContractUtils.RequiresNotNull(delegateType, "delegateType");
            ContractUtils.RequiresNotNull(binder, "binder");
            if (!delegateType.IsSubclassOf(typeof(MulticastDelegate))) throw Error.TypeMustBeDerivedFromSystemDelegate();

            var method = GetValidMethodForDynamic(delegateType);

            var args = arguments.ToReadOnly();
            ValidateArgumentTypes(method, ExpressionType.Dynamic, ref args);

            return DynamicExpression.Make(method.GetReturnType(), delegateType, binder, args);
        }
Beispiel #32
0
 internal DynamicExpression(Type delegateType, CallSiteBinder binder) {
     Debug.Assert(delegateType.GetMethod("Invoke").GetReturnType() == typeof(object) || GetType() != typeof(DynamicExpression));
     _delegateType = delegateType;
     _binder = binder;
 }
 public static System.Linq.Expressions.DynamicExpression MakeDynamic(System.Type delegateType, System.Runtime.CompilerServices.CallSiteBinder binder, System.Collections.Generic.IEnumerable <System.Linq.Expressions.Expression> arguments)
 {
     throw null;
 }
 public static System.Linq.Expressions.DynamicExpression MakeDynamic(System.Type delegateType, System.Runtime.CompilerServices.CallSiteBinder binder, params System.Linq.Expressions.Expression[] arguments)
 {
     throw null;
 }
Beispiel #35
0
 public static T Bind <T>(CallSiteBinder binder, CallSite <T> site, object[] args) where T : class
 {
     return(binder.BindCore(site, args));
 }
 public static System.Linq.Expressions.DynamicExpression MakeDynamic(System.Type delegateType, System.Runtime.CompilerServices.CallSiteBinder binder, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1, System.Linq.Expressions.Expression arg2, System.Linq.Expressions.Expression arg3)
 {
     throw null;
 }
Beispiel #37
0
 /// <summary>
 /// Creates a <see cref="DynamicExpression" /> that represents a dynamic operation bound by the provided <see cref="CallSiteBinder" />.
 /// </summary>
 /// <param name="delegateType">The type of the delegate used by the <see cref="CallSite" />.</param>
 /// <param name="binder">The runtime binder for the dynamic operation.</param>
 /// <param name="arguments">The arguments to the dynamic operation.</param>
 /// <returns>
 /// A <see cref="DynamicExpression" /> that has <see cref="NodeType" /> equal to
 /// <see cref="ExpressionType.Dynamic">Dynamic</see> and has the
 /// <see cref="DynamicExpression.DelegateType">DelegateType</see>,
 /// <see cref="DynamicExpression.Binder">Binder</see>, and
 /// <see cref="DynamicExpression.Arguments">Arguments</see> set to the specified values.
 /// </returns>
 public static DynamicExpression MakeDynamic(Type delegateType, CallSiteBinder binder, params Expression[] arguments) {
     return MakeDynamic(delegateType, binder, (IEnumerable<Expression>)arguments);
 }
 public static System.Runtime.CompilerServices.CallSite Create(System.Type delegateType, System.Runtime.CompilerServices.CallSiteBinder binder)
 {
     throw null;
 }
Beispiel #39
0
 public static extern CallSite Create(Type delegateType, CallSiteBinder binder);