当前位置: 首页>>代码示例>>C#>>正文


C# DynamicMetaObject.Select方法代码示例

本文整理汇总了C#中System.Dynamic.DynamicMetaObject.Select方法的典型用法代码示例。如果您正苦于以下问题:C# DynamicMetaObject.Select方法的具体用法?C# DynamicMetaObject.Select怎么用?C# DynamicMetaObject.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Dynamic.DynamicMetaObject的用法示例。


在下文中一共展示了DynamicMetaObject.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BindInvokeMember

            public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
            {
                Type[] argTypes = args.Select(a => a.RuntimeType).ToArray();
                MethodInfo method = type.GetMethod(binder.Name, BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Public, null, argTypes, null);

                if (method == null)
                    return base.BindInvokeMember(binder, args);

                var parameters = new Expression[] { Expression.Constant(null), Expression.NewArrayInit(typeof(object), args.Select(a => Expression.Convert(a.Expression, typeof(object)))) };

                return new DynamicMetaObject(
                    Expression.Call(
                        Expression.Constant(method),
                        typeof(MethodInfo).GetMethod("Invoke", new Type[] { typeof(object), typeof(object[]) }),
                        parameters),
                    BindingRestrictions.GetTypeRestriction(Expression, LimitType));
            }
开发者ID:distantcam,项目名称:zeromvvm,代码行数:17,代码来源:StaticMembersDynamicWrapper.cs

示例2: BindInvoke

 public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
 {
     return new DynamicMetaObject(
         Expression.Call(
             Expression.Constant(Function),
             typeof(BonsaiFunction).GetMethod("Call"),
             Expression.NewArrayInit(typeof(object), args.Select(a => Expression.Convert(a.Expression, typeof(object))))),
         BindingRestrictions.GetInstanceRestriction(this.Expression, Function));
 }
开发者ID:eugen,项目名称:Bonsai,代码行数:9,代码来源:BonsaiFunction.cs

示例3: Call

        public static Expr Call(Expr context, DynamicMetaObject target, DynamicMetaObject[] args)
        {
            var expression = Expr.Invoke(
                Expr.Constant((Func<CodeContext, object, object[], object>)LuaOps.CallMetamethod),
                context,
                Expr.Convert(target.Expression, typeof(object)),
                Expr.NewArrayInit(
                    typeof(object),
                    args.Select(arg => Expr.Convert(arg.Expression, typeof(object)))));

            return expression;
        }
开发者ID:SPARTAN563,项目名称:IronLua,代码行数:12,代码来源:MetamethodFallbacks.cs

示例4: FallbackInvoke

        public override DynamicMetaObject FallbackInvoke(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
        {
            var combinedArgs = new Expr[args.Length + 1];
            combinedArgs[0] = target.Expression;
            Array.Copy(args.Select(a => a.Expression).ToArray(), 0, combinedArgs, 1, args.Length);

            var restrictions = target.Restrictions.Merge(BindingRestrictions.Combine(args));
            var expression =
                Expr.Dynamic(
                    context.CreateInvokeBinder(new CallInfo(args.Length)),
                    typeof(object),
                    combinedArgs);

            return new DynamicMetaObject(expression, restrictions);
        }
开发者ID:fgretief,项目名称:IronLua,代码行数:15,代码来源:LuaInvokeMemberBinder.cs

示例5: BindGetIndex

        public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes)
        {
            var limitedSelf = Expression;
            if (limitedSelf.Type != LimitType)
            {
                limitedSelf = Expression.Convert(limitedSelf, LimitType);
            }

            var indexer = LimitType.GetProperty("Item");
            Expression expression = Expression.Call(limitedSelf, indexer.GetGetMethod(), indexes.Select(i => i.Expression));
            if (binder.ReturnType != expression.Type)
            {
                expression = Expression.Convert(expression, binder.ReturnType);
            }

            return new DynamicMetaObject(expression, BindingRestrictions.GetTypeRestriction(Expression, LimitType));
        }
开发者ID:realm,项目名称:realm-dotnet,代码行数:17,代码来源:MetaRealmList.cs

示例6: FallbackInvoke

        public override DynamicMetaObject FallbackInvoke(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
        {
            var combinedArgs = new Expr[args.Length + 1];
            combinedArgs[0] = target.Expression;
            Array.Copy(args.Select(a => a.Expression).ToArray(), 0, combinedArgs, 1, args.Length);

            var restrictions = target.Restrictions.Merge(BindingRestrictions.Combine(args));
            Expr expression =
                Expr.Dynamic(
                    context.CreateInvokeBinder(new CallInfo(args.Length)),
                    typeof(object),
                    combinedArgs);

            expression = MetamethodFallbacks.WrapStackTrace(expression, context,
                    new FunctionStack(context,null, null, context.CurrentVariableIdentifier + "." + Name));

            return new DynamicMetaObject(expression, restrictions);
        }
开发者ID:SPARTAN563,项目名称:IronLua,代码行数:18,代码来源:LuaInvokeMemberBinder.cs

示例7: GetIndexingExpression

        // Return the expression for getting target[indexes]
        //
        // Note, callers must ensure consistent restrictions are added for
        // the conversions on args and target.
        //
        public static Expression GetIndexingExpression(
            DynamicMetaObject target,
            DynamicMetaObject[] indexes)
        {
            Debug.Assert(target.HasValue && target.LimitType != typeof(Array));

            var indexExpressions = indexes.Select(
                i => Expression.Convert(i.Expression, i.LimitType))
                .ToArray();

            //// CONS
            //if (target.LimitType == typeof(Cons))
            //{
            //    // Call RuntimeHelper.GetConsElt
            //    var args = new List<Expression>();
            //    // The first argument is the list
            //    args.Add(
            //        Expression.Convert(
            //            target.Expression,
            //            target.LimitType)
            //    );
            //    args.AddRange(indexExpressions);
            //    return Expression.Call(
            //        typeof(RuntimeHelpers),
            //        "GetConsElt",
            //        null,
            //        args.ToArray());
            //    // ARRAY
            //}
            //else
            if (target.LimitType.IsArray)
            {
                return Expression.ArrayAccess(
                    Expression.Convert(target.Expression,
                        target.LimitType),
                    indexExpressions
                    );
                // INDEXER
            }
            else
            {
                var props = target.LimitType.GetProperties();
                var indexers = props.Where(p => p.GetIndexParameters().Length > 0).ToArray();
                indexers = indexers.Where(idx => idx.GetIndexParameters().Length == indexes.Length).ToArray();

                var res = new List<PropertyInfo>();
                foreach (var idxer in indexers)
                {
                    if (RuntimeHelpers.ParametersMatchArguments(
                        idxer.GetIndexParameters(), indexes))
                    {
                        // all parameter types match
                        res.Add(idxer);
                    }
                }
                if (res.Count == 0)
                {
                    return Expression.Throw(
                        Expression.New(
                            typeof(MissingMemberException)
                                .GetConstructor(new Type[] { typeof(string) }),
                            Expression.Constant(
                                "Can't bind because there is no matching indexer.")
                            )
                        );
                }
                return Expression.MakeIndex(
                    Expression.Convert(target.Expression, target.LimitType),
                    res[0], indexExpressions);
            }
        }
开发者ID:dlurton,项目名称:Happy,代码行数:76,代码来源:RuntimeHelpers.cs

示例8: BindInvokeMember

		public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
		{
			var wrapper = this.Value as ExpressionContainer;
			var valueExpr = wrapper.Expression;

			var typeArgs = MockingUtil.TryGetTypeArgumentsFromBinder(binder);

			var candidateMethods = valueExpr.Type.GetAllMethods()
				.Where(m => MockingUtil.StringEqual(m.Name, binder.Name, binder.IgnoreCase) && m.IsStatic == wrapper.IsStatic)
				.Where(m => m.GetParameters().Length >= args.Length)
				.Select(m =>
				{
					if (typeArgs == null)
					{
						return MockingUtil.TrySpecializeGenericMethod(m, args.Select(a => a.RuntimeType).ToArray()) ?? m;
					}
					else
					{
						return MockingUtil.TryApplyTypeArguments(m, typeArgs);
					}
				})
				.Where(m => m != null)
				.Where(m =>
				{
					var methodParams = m.GetParameters();
					for (int i = 0; i < args.Length; ++i)
					{
						var matcher = UnwrapMatcher(args[i]);
						if (matcher != null)
						{
							var argType = matcher.ReturnType;
							if (!methodParams[i].ParameterType.IsAssignableFrom(argType))
								return false;
						}
					}
					return true;
				})
				.ToArray();

			if (candidateMethods.Length == 0 && args.Length == 0)
			{
				return DoBindGetMember(binder.ReturnType, binder.Name, binder.IgnoreCase);
			}

			var methodArgs = args.Select(a =>
			{
				var matcher = UnwrapMatcher(a);
				return matcher != null ? matcher.ReturnType.GetDefaultValue() : a.Value;
			}).ToArray();

			object state;
			var method = (MethodInfo)MockingUtil.BindToMethod(MockingUtil.Default, candidateMethods, ref methodArgs, null, null, null, out state);

			var memberExpr = Expression.Call(!wrapper.IsStatic ? valueExpr : null, method, args.Select(FromArg).ToArray());

			return CreateRecorder(memberExpr, binder.ReturnType);
		}
开发者ID:ArthurYiL,项目名称:JustMockLite,代码行数:57,代码来源:ExpressionRecorder.cs

示例9: BindSetIndex

		public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
		{
			var wrapper = this.Value as ExpressionContainer;
			var valueExpr = wrapper.Expression;
			var property = PrivateAccessor.ResolveProperty(valueExpr.Type, "Item", false,
				indexes.Select(i => i.Value).ToArray(), !wrapper.IsStatic, value.Value, getter: false);
			if (property == null)
				ThrowMissingMemberException(valueExpr.Type, "Item");

			var memberExpr = Expression.Assign(
				Expression.MakeIndex(!wrapper.IsStatic ? valueExpr : null, property, indexes.Select(FromArg)),
				FromArg(value));
			return CreateRecorder(memberExpr, binder.ReturnType);
		}
开发者ID:ArthurYiL,项目名称:JustMockLite,代码行数:14,代码来源:ExpressionRecorder.cs

示例10: BindSetIndex

			public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
			{
				return BindSetMember(binder.ReturnType, "Item", value.Expression, indexes.Select(i => i.Expression));
			}
开发者ID:ArthurYiL,项目名称:JustMockLite,代码行数:4,代码来源:PrivateAccessor.cs

示例11: BindGetIndex

			public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes)
			{
				var getProp = typeof(PrivateAccessor).GetMethod("GetProperty");

				var call = Expression.Call(Expression.Convert(this.Expression, typeof(PrivateAccessor)), getProp,
					Expression.Constant("Item"),
					Expression.NewArrayInit(typeof(object), indexes.Select(a => Expression.Convert(a.Expression, typeof(object)))));
				return CreateMetaObject(call);
			}
开发者ID:ArthurYiL,项目名称:JustMockLite,代码行数:9,代码来源:PrivateAccessor.cs

示例12: BindInvokeMember

			public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
			{
				var callResult = Expression.Variable(typeof(object));
				var argsVar = Expression.Variable(typeof(object[]));

				MethodInfo invoke = typeof(PrivateAccessor).GetMethod("CallMethod", new[] { typeof(string), typeof(object[]) });
				var invokeArgs = new List<Expression>
				{
					Expression.Constant(binder.Name),
					argsVar
				};

				var typeArgs = MockingUtil.TryGetTypeArgumentsFromBinder(binder);
				if (typeArgs != null)
				{
					invoke = typeof(PrivateAccessor).GetMethod("CallMethodWithTypeArguments");
					invokeArgs.Insert(1, Expression.Constant(typeArgs));
				}

				var executionList = new List<Expression>
				{
					Expression.Assign(argsVar, Expression.NewArrayInit(typeof(object), args.Select(a => Expression.Convert(a.Expression, typeof(object))))),
					Expression.Assign(callResult, Expression.Call(
						Expression.Convert(this.Expression, typeof(PrivateAccessor)), invoke, invokeArgs.ToArray())),
				};

				executionList.AddRange(args
					.Select((a, i) => new { expr = a.Expression, i })
					.Where(p => p.expr is ParameterExpression)
					.Select(p => Expression.Assign(p.expr, Expression.Convert(Expression.ArrayIndex(argsVar, Expression.Constant(p.i)), p.expr.Type))));
				executionList.Add(callResult);

				return CreateMetaObject(Expression.Block(new[] { argsVar, callResult }, executionList));
			}
开发者ID:ArthurYiL,项目名称:JustMockLite,代码行数:34,代码来源:PrivateAccessor.cs

示例13: MapArguments

        IEnumerable<Expr> MapArguments(DynamicMetaObject[] args, MethodInfo methodInfo, ref BindingRestrictions restrictions, out List<Expr> sideEffects, out Expr failExpr)
        {
            var parameters = methodInfo.GetParameters();
            var isFromLua = methodInfo.Name.StartsWith(Constant.FUNCTION_PREFIX);
            var arguments = args.Select(arg => new Argument(arg.Expression, arg.LimitType)).ToList();

            // Remove closure
            if (parameters.Length > 0 && parameters[0].ParameterType == typeof(Closure))
            {
                var tempParameters = new ParameterInfo[parameters.Length - 1];
                Array.Copy(parameters, 1, tempParameters, 0, tempParameters.Length);
                parameters = tempParameters;
            }

            ExpandLastArg(arguments, args, ref restrictions);
            DefaultParamValues(arguments, parameters);
            OverflowIntoParams(arguments, parameters);
            TrimArguments(arguments, parameters, out sideEffects);
            if (isFromLua)
                DefaultParamTypeValues(arguments, parameters);
            ConvertArgumentToParamType(arguments, parameters, out failExpr);
            if (failExpr == null && !isFromLua)
                CheckNumberOfArguments(arguments, parameters, out failExpr);

            return arguments.Select(arg => arg.Expression);
        }
开发者ID:ericmj,项目名称:IronLua,代码行数:26,代码来源:LuaInvokeBinder.cs

示例14: BindInvokeMember

            public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
            {
                MethodInfo method = _proxy._instanceType.GetMethod(binder.Name, args.Select(d => d.RuntimeType ?? d.LimitType.MakeByRefType()).ToArray());
                if (method == null)
                    return null;

                return new DynamicMetaObject(new DynamicMethod(method, _proxy._instance).GetMethodExpression(args.Select(arg => arg.Expression)), BindingRestrictions.GetTypeRestriction(Expression, LimitType));
            }
开发者ID:swolter,项目名称:DynamicProxy,代码行数:8,代码来源:DynamicProxy.cs

示例15: BindInvoke

 public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
 {
     var args2 = args.Select(x => x.Expression).ToArray();
     var code = MakeExpression(false, Lambda.Members, args2);
     var restrictions = BindingRestrictions.GetInstanceRestriction(Expression, Value);
     return new DynamicMetaObject(code, restrictions);
 }
开发者ID:jantolenaar,项目名称:kiezellisp,代码行数:7,代码来源:builtin.cs


注:本文中的System.Dynamic.DynamicMetaObject.Select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。