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


C# Expression.Compile方法代码示例

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


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

示例1: QueryCustomers

		/// <summary>
		/// This demonstrates how to plug a query expression into an EntitySet. It prints all customers and the
		/// value of their purchases, filtering the purchases according to a specified predicate.
		/// </summary>
		static void QueryCustomers (Expression<Func<Purchase, bool>> purchasePredicate)
		{
			var data = new DemoData ();

			// We do two special things to make this query work:
			//   (1) Call AsExpandable() on the Customer table
			//   (2) Call Compile() on the supplied predicate when it's used within an EntitySet.
			// AsExpandable() returns a wrapper that strips away the call to Compile when the query is run.

			var query =
				from c in data.Customers.AsExpandable ()
				where c.Purchases.Any (purchasePredicate.Compile ())
				select new
				{
					c.Name,
					FilteredPurchases =
						from p in c.Purchases.Where (purchasePredicate.Compile ())
						select p.Price
				};

			foreach (var customerResult in query)
			{
				Console.WriteLine (customerResult.Name);
				foreach (decimal price in customerResult.FilteredPurchases)
					Console.WriteLine ("   $" + price);
			}
		}
开发者ID:osjimenez,项目名称:LINQKit,代码行数:31,代码来源:Program.cs

示例2: GetTools

 public List<Tool> GetTools(Expression<Func<Tool, bool>> predicate)
 {
     if(predicate != null)
     {
       var preComp =  predicate.Compile();
       predicate = o => preComp(o) && o.Active == true;
       return ausv1Context.Tools.Where(predicate.Compile()).ToList();
     }            
     return ausv1Context.Tools.Where(o => o.Active == true).ToList();
 }
开发者ID:MTeuser,项目名称:WebTools,代码行数:10,代码来源:DataAccess.cs

示例3: Find

 public IEnumerable<User> Find(Expression<Func<User, bool>> where)
 {
     using (var db = new UserContext())
     {
         return db.Users.Where(where.Compile()).ToArray();
     }
 }
开发者ID:kv1z,项目名称:Panzar,代码行数:7,代码来源:UserRepository.cs

示例4: TestFilter

 private async Task TestFilter(Expression<Func<Order, bool>> predicate)
 {
     var table = Client.GetTable<Order>();
     var items = await table.Where(predicate).OrderBy(o => o.Id).ToListAsync();
     var expected = Orders.Where(predicate.Compile()).OrderBy(o => o.Id).ToArray();
     ComparisonHelper.CompareAssert(expected, items);
 }
开发者ID:aeee98,项目名称:blogsamples,代码行数:7,代码来源:FilterTests.cs

示例5: AssertJiraHttpLink

 private void AssertJiraHttpLink(Expression<Func<IHttpInterfaceConfiguration, string>> configPropertyAccessor)
 {
     IHttpInterfaceConfiguration httpConfig = JiraConfig.Instance.HttpInterfaceConfiguration;
     Assert.AreEqual(
             ExpectedUrlFrom(configPropertyAccessor),
             configPropertyAccessor.Compile().Invoke(httpConfig));
 }
开发者ID:adrianoc,项目名称:binboo,代码行数:7,代码来源:JiraConfigTestCase.Helper.cs

示例6: CheckExpression

 public static void CheckExpression(Expression<Func<Boolean>> expression)
 {
     if (!expression.Compile()())
     {
         throw new MalformedException(string.Concat("Bad file format, expecting ", expression.ToString().Replace("() => ", string.Empty)));
     }
 }
开发者ID:redrocktx,项目名称:shellify,代码行数:7,代码来源:FormatChecker.cs

示例7: EntryTokenizeFormats

        private void EntryTokenizeFormats(string token, Func<string[],string[]> tokenizer, Expression<Func<string[]>> expression)
        {
            var key = ExpressionHelper.GetExpressionText(expression);
            var formats = tokenizer(expression.Compile().Invoke().ToArray());

            TokenizeFormats[token + ":" + key] = formats;
        }
开发者ID:takepara,项目名称:MvcPhotos,代码行数:7,代码来源:UaRazorViewEngine.cs

示例8: GradientDescent

        public static Vector GradientDescent(
            Expression<Func<Vector, double>> function, 
            Expression<Func<Vector, Vector>> gradient, 
            Vector x0, 
            int iter, 
            double stepSize, 
            out Vector trajectory)
        {
            trajectory = Vector.Zeros(iter);
            var x = x0;
            var obj = double.MaxValue;
            var f = function.Compile();
            var g = gradient.Compile();
            for (int i = 0; i < iter; i++)
            {
                // calculate gradient
                var grad = g(x);
                // get step size (avoid overstepping)
                var eta = stepSize / System.Math.Sqrt(iter + 1);
                // take step
                x = x - eta * grad;
                // calculate objective
                trajectory[i] = f(x);
                // sanity check (don't want to take too many steps)
                if (System.Math.Abs(obj - trajectory[i]) < MIN_DIFF)
                    break;
                // start again
                obj = trajectory[i];
            }

            return x;
        }
开发者ID:al-main,项目名称:CloudyBank,代码行数:32,代码来源:OptimizeBy.cs

示例9: AddRequestProperty

        public static void AddRequestProperty(Expression<Func<HttpRequestBase, object>> expression)
        {
            var property = ReflectionHelper.GetProperty(expression);
            _systemProperties.Add(property);

            _requestProperties[property.Name] = expression.Compile();
        }
开发者ID:cothienlac86,项目名称:fubumvc,代码行数:7,代码来源:RequestPropertyValueSource.cs

示例10: GetFriendlyName

        protected internal virtual string GetFriendlyName(Type type, Expression<Func<Type, string>> nameFunctionExpression)
        {
            if(type == null)
                throw new ArgumentNullException("type");

            if(nameFunctionExpression == null)
                throw new ArgumentNullException("nameFunctionExpression");

            if(type.IsGenericParameter)
                return type.Name;

            var name = nameFunctionExpression.Compile().Invoke(type);

            if(!type.IsGenericType)
                return name;

            name = name.Substring(0, name.IndexOf("`", StringComparison.OrdinalIgnoreCase));

            var genericArgumentFriendlyName = string.Empty;

            foreach(var genericArgument in type.GetGenericArguments())
            {
                if(!string.IsNullOrEmpty(genericArgumentFriendlyName))
                    genericArgumentFriendlyName += ", ";

                genericArgumentFriendlyName += this.GetFriendlyName(genericArgument, nameFunctionExpression);
            }

            return string.Format(CultureInfo.InvariantCulture, "{0}<{1}>", name, genericArgumentFriendlyName);
        }
开发者ID:HansKindberg-Lab,项目名称:LINQ-Query-Provider,代码行数:30,代码来源:DefaultTypeExtension.cs

示例11: RouteTarget

        public RouteTarget(Expression<Func<IServiceLocator, object>> controllerExpr)
        {
            _controllerExpr = controllerExpr;
            _controllerFunc = _controllerExpr.Compile();

            ControllerType = ((_controllerExpr.Body as MethodCallExpression)?.Arguments?[0]
                as ConstantExpression)?.Value as Type;
        }
开发者ID:jammycakes,项目名称:dolstagis.web,代码行数:8,代码来源:RouteTarget.cs

示例12: AddHttpMethodFilter

 public void AddHttpMethodFilter(Expression<Func<ActionCall, bool>> filter, string method)
 {
     _httpMethodFilters.Add(new HttpMethodFilter{
         Filter = filter.Compile(),
         Description = filter.Body.ToString(),
         Method = method
     });
 }
开发者ID:NeilSorensen,项目名称:fubumvc,代码行数:8,代码来源:RouteConstraintPolicy.cs

示例13: NotNullOrEmpty

        public static void NotNullOrEmpty(Expression<Func<string>> expr)
        {
            if (!string.IsNullOrEmpty(expr.Compile()()))
                return;

            var param = (MemberExpression)expr.Body;
            throw new ArgumentNullException("The parameter '" + param.Member.Name + "' cannot be null or empty.");
        }
开发者ID:RussPAll,项目名称:FhemDotNet,代码行数:8,代码来源:Validation.cs

示例14: FindCalls

 public IEnumerable<Call> FindCalls(Expression<Func<CallInput, bool>> filter)
 {
     if (filter == null)
     {
         throw new ArgumentNullException("filter");
     }
     var predicate = filter.Compile();
     return from call in _calls where predicate.Invoke(call.Input) select call;
 }
开发者ID:ebjornset,项目名称:Crasop.Net,代码行数:9,代码来源:CallFileRepository.cs

示例15: CompileTree

 private Action<FunctionContext> CompileTree(Expression<Action<FunctionContext>> lambda)
 {
     if (this.CompileInterpretDecision == CompileInterpretChoice.AlwaysCompile)
     {
         return lambda.Compile();
     }
     int compilationThreshold = (this.CompileInterpretDecision == CompileInterpretChoice.NeverCompile) ? 0x7fffffff : -1;
     return (Action<FunctionContext>) new LightCompiler(compilationThreshold).CompileTop(lambda).CreateDelegate();
 }
开发者ID:nickchal,项目名称:pash,代码行数:9,代码来源:CompiledScriptBlockData.cs


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