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


C# Expression.Select方法代码示例

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


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

示例1: CallFunction

        static Expression CallFunction(string name, Expression[] parameters)
        {
            var methodInfo = typeof (Math).GetMethod(name, parameters.Select(e => e.Type).ToArray());
            if (methodInfo == null)
                throw new ParseException(string.Format("Function '{0}({1})' does not exist.", name,
                                                       string.Join(",", parameters.Select(e => e.Type.Name))));

            return Expression.Call(methodInfo, parameters);
        }
开发者ID:sprache,项目名称:Sprache,代码行数:9,代码来源:ExpressionParser.cs

示例2: createCallSiteInvokeTarget

        /// <summary>
        /// Creates a call site.
        /// </summary>
        /// <param name="createBinderMethodName">
        /// The name of the method 
        /// </param>
        /// <param name="instance"></param>
        /// <param name="targetArgExprs"></param>
        /// <remarks>
        ///		<ul>
        ///			<li>
        ///				Determines if a delegate has been created in _assemblyGenerator yet that matches the 
        ///				operation and signature of the call site to be created.  
        ///			</li>
        ///			<li>
        ///				Uses existing delegate or defines a new delegate if one was not identified.
        ///			</li>
        ///			<li>
        ///				Creates a field in the dynamic type for storing the call site
        ///			</li>
        ///			<li>
        ///				Emits code to check if the field has been initialized with a binder yet, and if not initializes it 
        ///				using the HappyLanguageContext method identified by createBinderMethodName, passing the arguments
        ///				identified by createBinderMethodArgExprs.
        ///			</li>
        ///			<li>
        ///				Emits code to invoke the callsite's target.  
        ///			</li>
        ///		</ul>
        /// </remarks>
        /// <returns></returns>
        Expression createCallSiteInvokeTarget(string createBinderMethodName, Expression[] createBinderMethodArgExprs, Expression[] targetArgExprs)
        {
            var argTypes = new List<Type> { typeof(CallSite) };
            argTypes.AddRange(targetArgExprs.Select(a => a.Type));
            Type delegateType = getDelegateType(createBinderMethodName, typeof(object), argTypes.ToArray());

            Expression callSiteExpr = makeCallSiteField(delegateType);
            MethodInfo createBinderMethodInfo = typeof(HappyLanguageContext).GetMethod(createBinderMethodName, BindingFlags.Public | BindingFlags.Instance);
            DebugAssert.IsNotNull(createBinderMethodInfo, "'{0}' is not a valid member of HappyLanguageContext");
            var expectedArgumentTypes = createBinderMethodInfo.GetParameters().Select(a => a.ParameterType).ToArray();
            #if DEBUG
            DebugAssert.AreEqual(expectedArgumentTypes.Length, createBinderMethodArgExprs.Length,
                                 "Incorrect number of expressions supplied as create binder method arugments for HappyLanguageContext.{0} " +
                                 "Expected {1} got {2}", createBinderMethodName, expectedArgumentTypes.Length, createBinderMethodArgExprs.Length);

            for(int i = 0; i < expectedArgumentTypes.Length; ++i)
            {
                if (!createBinderMethodArgExprs[i].Type.IsAssignableFrom(expectedArgumentTypes[i]))
                    DebugAssert.Fail("Argument {0} ( of type {1}) in call to HappyLanguageContext.{2} was not asssignable from {3}",
                                     i + 1, createBinderMethodArgExprs[i].Type.FullName, createBinderMethodName, expectedArgumentTypes[i].FullName);
            }
            #endif
            Expression initCallSiteExpr = getInitCallSiteExpr(callSiteExpr, createBinderMethodInfo, createBinderMethodArgExprs);

            List<Expression> finalArgs = new List<Expression> { callSiteExpr};
            finalArgs.AddRange(targetArgExprs);

            Expression callTargetExpr = Expression.Invoke(Expression.Field(callSiteExpr, "Target"), finalArgs);

            return Expression.Block(initCallSiteExpr, callTargetExpr);
        }
开发者ID:dlurton,项目名称:Happy,代码行数:62,代码来源:AstAnalyzer.DynamicExpressions.cs

示例3: MergeTest

        public void MergeTest()
        {
            var expressions = new Expression<Func<Test, Test>>[]
            {
                t => new Test {A = t.A},
                t => new Test {B = t.B},
                t => new Test {C = t.C},
                t => new Test {D = t.D},
            };
            var oneParamExpressions = expressions.Select(x => Expression.Lambda<Func<Test, Test>>(x.Body, expressions[0].Parameters[0])).ToList();
            ParameterExpression pe;
            _parameterRebinder.Setup(x => x.ReplaceParametersByFirst(expressions)).Returns(oneParamExpressions.Select(x => x.Body)).Verifiable();

            var result = Create().Merge<Test>(expressions, out pe);

            Assert.AreEqual(ExpressionType.MemberInit, result.NodeType);
            var mie = result as MemberInitExpression;
            var ci = mie.NewExpression.Constructor;
            Assert.AreEqual(ci, typeof (Test).GetConstructors()[0]);
            Assert.AreEqual(4, mie.Bindings.Count);
            Assert.AreEqual(1, mie.Bindings.Count(b => b.Member == typeof (Test).GetProperty("A")));
            Assert.AreEqual(1, mie.Bindings.Count(b => b.Member == typeof (Test).GetProperty("B")));
            Assert.AreEqual(1, mie.Bindings.Count(b => b.Member == typeof (Test).GetProperty("C")));
            Assert.AreEqual(1, mie.Bindings.Count(b => b.Member == typeof (Test).GetProperty("D")));
        }
开发者ID:riberk,项目名称:Rib.Common,代码行数:25,代码来源:MemberInitMergerTests.cs

示例4: MergeUndefinedExpressionTest

        public void MergeUndefinedExpressionTest()
        {
            ParameterExpression pe;
            var expressions = new Expression<Func<Test, int>>[]
            {
                t => 1
            };
            _parameterRebinder.Setup(x => x.ReplaceParametersByFirst(expressions)).Returns(expressions.Select(x => x.Body)).Verifiable();

            Create().Merge<Test>(expressions, out pe);
        }
开发者ID:riberk,项目名称:Rib.Common,代码行数:11,代码来源:MemberInitMergerTests.cs

示例5: MethodCall

        static Expression MethodCall(string name, Expression[] parameters)
        {
            var methodInfo = (parameters != null) ? typeof(Order).GetMethod(name, parameters.Select(e => e.Type).ToArray())
                                                  : typeof(Order).GetMethod(name);

            if (methodInfo == null)
            {
                throw new ParseException(string.Format("Function '{0}({1})' does not exist.",
                                         name,
                                         string.Join(", ", parameters.Select(e => e.Type.Name))));
            }

            return Expression.Call(Expression.Parameter(typeof(Order), "order"), methodInfo, parameters);
        }
开发者ID:markashleybell,项目名称:SpracheDSLSpike,代码行数:14,代码来源:Parser.cs

示例6: Gather

        public static ReferencedRelatedObjectPropertyGathererResults Gather(DataAccessModel model, Expression[] expressions, ParameterExpression sourceParameterExpression, bool forProjection)
        {
            var gatherer = new ReferencedRelatedObjectPropertyGatherer(model, sourceParameterExpression, forProjection);

            var reducedExpressions = expressions.Select(gatherer.Visit).ToArray();

            return new ReferencedRelatedObjectPropertyGathererResults
            {
                ReducedExpressions = reducedExpressions,
                ReferencedRelatedObjectByPath = gatherer.results,
                RootExpressionsByPath = gatherer.rootExpressionsByPath,
                IncludedPropertyInfoByExpression = gatherer
                    .includedPropertyInfos
                    .GroupBy(c => c.RootExpression)
                    .ToDictionary(c => c.Key, c => c.ToList())
            };
        }
开发者ID:ciker,项目名称:Shaolinq,代码行数:17,代码来源:ReferencedRelatedObjectPropertyGatherer.cs

示例7: CreateBodyExpression

        private static Expression CreateBodyExpression(
            MethodInfo delegateMethod, DelegateCallInterceptedEventRaiser eventRaiser, Expression[] parameterExpressions)
        {
            var parameterExpressionsCastToObject =
                parameterExpressions.Select(x => Expression.Convert(x, typeof(object))).Cast<Expression>().ToArray();

            Expression body = Expression.Call(
                Expression.Constant(eventRaiser),
                DelegateCallInterceptedEventRaiser.RaiseMethod,
                new Expression[] { Expression.NewArrayInit(typeof(object), parameterExpressionsCastToObject) });

            if (!delegateMethod.ReturnType.Equals(typeof(void)))
            {
                body = Expression.Convert(body, delegateMethod.ReturnType);
            }

            return body;
        }
开发者ID:jszumigaj,项目名称:FakeItEasy,代码行数:18,代码来源:DelegateProxyGenerator.cs

示例8: AllPublicMethodsCheckIfPageHasBeenInitialized

        public void AllPublicMethodsCheckIfPageHasBeenInitialized()
        {
            var publicMethodCallExpressions = new Expression<Action<BasePage>>[]
                {
                    x => x.ExecuteScript("return 1;"),
                    x => x.ExecuteAsyncScript("return 2;"),
                    x => x.FindElement(By.Id("start")),
                    x => x.FindElements(By.ClassName("end"))
                };
            var page = new SimplePageForTest();
            var methods = typeof(BasePage).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
                .Where(x => !x.IsSpecialName);
            var coveredMethods = publicMethodCallExpressions.Select(x => x.Body).Cast<MethodCallExpression>().Select(x => x.Method.Name);
            var uncoveredMethods = methods.Where(x => !coveredMethods.Contains(x.Name)).Select(x => x.Name).ToArray();

            Assert.IsEmpty(uncoveredMethods, "'{0}' methods does not covered. Please add expressions to test them.", string.Join(", ", uncoveredMethods));
            foreach (var publicMethodCallExpression in publicMethodCallExpressions)
            {
                Assert.Throws<PageInitializationException>(() => publicMethodCallExpression.Compile()(page));
            }
        }
开发者ID:pbakshy,项目名称:Selenol,代码行数:21,代码来源:TestPageInitialization.cs

示例9: SeekFunction

        internal static Function SeekFunction(string name, Expression[] arguments, bool seekInsideObservable = false)
        {
            var qualifiedName = string.Format("{0}({1})", name, arguments.Count());

            // TODO: Handle missing function events
            var function = ExpressionsHelper.functions.Where(f => f.FunctionName.Equals(qualifiedName)
                        && arguments.Select(a =>
                        {
                            var type = a.Type.GetFirstObservableGenericType();

                            if (type == null || seekInsideObservable == false)
                            {
                                return a.Type;
                            }

                            return type;

                        })
                                    .SequenceEqual(f.Parameters
                                                        .Select(p => p.Type))).FirstOrDefault();

            return function;
        }
开发者ID:fahadash,项目名称:CalcRx,代码行数:23,代码来源:FunctionHelper.cs

示例10: CreateTupleSelector

        private static Expression CreateTupleSelector(
            Expression body, 
            Expression[] memberSelectors)
        {
            Type[] memberTypes = memberSelectors.Select(e => e.Type).ToArray();

            Type tupleType = TupleTypeHelper.CreateTupleType(memberTypes);

            var helper = new TupleKeyInfoHelper(tupleType);
            body = helper.CreateKeyFactoryExpression(memberSelectors);
            return body;
        }
开发者ID:nozerowu,项目名称:ABP,代码行数:12,代码来源:KeyInfoHelper.cs

示例11: GetArgTypesString

 private static string GetArgTypesString(Expression[] arguments) {
     StringBuilder argTypesStr = new StringBuilder();
     var isFirst = true;
     argTypesStr.Append("(");
     foreach (var t in arguments.Select(arg => arg.Type)) {
         if (!isFirst) {
             argTypesStr.Append(", ");
         }
         argTypesStr.Append(t.Name);
         isFirst = false;
     }
     argTypesStr.Append(")");
     return argTypesStr.ToString();
 }
开发者ID:jcteague,项目名称:ironruby,代码行数:14,代码来源:IndexExpression.cs

示例12: VisitExpressions

        private Variable[] VisitExpressions(Expression[] expressions)
        {
            return expressions.Select(Visit).ToArray();

            //this.Out(open);
            //if (expressions != null)
            //{
            //    bool flag = true;
            //    foreach (T local in expressions)
            //    {
            //        if (flag)
            //        {
            //            flag = false;
            //        }
            //        else
            //        {
            //            this.Out(", ");
            //        }
            //        this.Visit(local);
            //    }
            //}
            //this.Out(close);
        }
开发者ID:xornand,项目名称:rDSN,代码行数:23,代码来源:BasicBlockBuilder.cs


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