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


C# Expression.Invoke方法代码示例

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


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

示例1: GetResults

        public static IEnumerable<Book> GetResults(Expression<Func<Book, bool>> criteria)
        {
            IQueryable<Book> db = new[] {
                                            new Book { Title = "War and Peace", Author = "Leo Tolstoy"},
                                            new Book { Title = "Hunger", Author = "Knut Hamsun" },
                                            new Book { Title = "Embers", Author = "Sandor Marai" }
                                        }.AsQueryable();

            var query = from book in db.AsExpandable()
                        where criteria.Invoke(book)
                        select book;

            return query;
        }
开发者ID:prompt,项目名称:preprompt-csharp,代码行数:14,代码来源:Test.cs

示例2: CalcEff

        /// <summary>
        /// Do the cut
        /// </summary>
        /// <param name="effResults"></param>
        /// <param name="queryable1"></param>
        /// <param name="queryable2"></param>
        private static IFutureValue<double> CalcEff(FutureTDirectory effResults, Expression<Func<TrainingData,double>> selection, double threshold, IQueryable<TrainingData> background, IQueryable<TrainingData> signal)
        {
            background
                .Select(t => selection.Invoke(t))
                .FuturePlot("b_weight", "Background weight", 50, -1.1, 1.1)
                .Save(effResults);
            signal
                .Select(t => selection.Invoke(t))
                .FuturePlot("s_weight", "Signal weight", 50, -1.1, 1.1)
                .Save(effResults);

            var total_b = background.FutureCount();
            var total_s = signal.FutureCount();

            var selected_b = background.Where(t => selection.Invoke(t) > threshold).FutureCount();
            var selected_s = signal.Where(t => selection.Invoke(t) > threshold).FutureCount();

            var eff_b = from tb in total_b from ns in selected_b select (double) ns / (double) tb;
            var eff_s = from tb in total_s from ns in selected_s select (double) ns / (double) tb;

            //FutureWrite(from eb in eff_b from es in eff_s select $"Signal eff: {es}; Background eff: {eb}");

            return eff_s;
        }
开发者ID:gordonwatts,项目名称:JetCutStudies,代码行数:30,代码来源:Program.cs

示例3: QueryCustomersManualJoin2

		/// <summary>
		/// Another way to formulate the preceding query.
		/// </summary>
		static void QueryCustomersManualJoin2 (Expression<Func<Purchase, bool>> purchasePredicate)
		{
			var data = new DemoData ();

			// Here we're including the purchasePredicate in the filteredPurchases expression. 
			// We can combine lambda expressions by calling Invoke() on the variable
			// expresssion.  The AsExpandable() wrapper then strips out the call to Invoke
			// and emits one clean expression:

			var query =
				from c in data.Customers.AsExpandable ()
				let filteredPurchases = data.Purchases.Where (
					p => p.CustomerID == c.ID && purchasePredicate.Invoke (p))
				where filteredPurchases.Any ()
				select new
				{
					c.Name,
					FilteredPurchases =
						from p in filteredPurchases
						select p.Price
				};

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

示例4: ClassSetUp

 public void ClassSetUp() {
     calc = (i => i * 10);
     expr = LinqTool.Expr<int, int>(i => calc.Invoke(i) + 4);
     func = LinqTool.Func<int, int>(i => calc.Invoke(i) + 2);
 }
开发者ID:debop,项目名称:NFramework,代码行数:5,代码来源:ExpressionFixture.cs

示例5: PlotMVAResult

        /// <summary>
        /// Generate plots for the signal
        /// </summary>
        /// <param name="queryable"></param>
        /// <param name="sampleD"></param>
        /// <param name="mvaValue"></param>
        private static void PlotMVAResult(IQueryable<JetStream> source, FutureTDirectory dir, Expression<Func<TrainingTree, double>> mvaValue)
        {
            // Plot the weights. This can be used to plot signal vs background, ROC curves, etc.
            var weights = source
                .Select(j => TrainingUtils.TrainingTreeConverter.Invoke(j))
                .Select(j => Tuple.Create(mvaValue.Invoke(j), j.Weight))
                .FuturePlot(TrainingEventWeightFine.NameFormat, TrainingEventWeightFine.TitleFormat, TrainingEventWeightFine, "All")
                .Save(dir);

            // Next, let plot lots of kinematic plots so we can see what they look like.
            var plotsFromJS = new IPlotSpec<JetStream>[]
            {
                JetPtPlotJetStream,
                JetETPlotJetStream,
                JetEtaPlotJetStream,
                JetLxyPlotJetStream,
                JetCalRPlotJetStream,
                JetStreamSumPt,
                JetStreamMaxPt,
                JetCalRPlotFineJetStream,
            };

            var plots = plotsFromJS
                .Select(myp => myp.FromType<JetStream, Tuple<JetStream, double>>(jinfo => jinfo.Item1, weight: jinfo => jinfo.Item2 * jinfo.Item1.Weight));

            // We want weighted and unweighted plots here. We first have to normalize the weighting to be from 0 to 1.
            // If there is only a single weight in the sample (which is just weird) then correctly make sure we are set to deal
            // with things.
            var firstNonZeroBinValue = weights.Value.FindNonZeroBinValue();
            var lastNonZeroBinValue = weights.Value.FindNonZeroBinValue(HistogramUtils.BinSearchOrder.HighestBin);

            if (firstNonZeroBinValue == lastNonZeroBinValue)
            {
                Console.WriteLine($"  Sample has events with all one weight ({firstNonZeroBinValue}).");
            }

            var scaleing = lastNonZeroBinValue == firstNonZeroBinValue
                ? 1.0 
                : 1.0 / (lastNonZeroBinValue - firstNonZeroBinValue);

            firstNonZeroBinValue = lastNonZeroBinValue == firstNonZeroBinValue
                ? firstNonZeroBinValue - 1.0
                : firstNonZeroBinValue;

            var mvaWeithedJetStream = source
                .Select(j => Tuple.Create(j, j.Weight * (mvaValue.Invoke(TrainingUtils.TrainingTreeConverter.Invoke(j)) - firstNonZeroBinValue)*scaleing));
            var weithedJetStream = source
                .Select(j => Tuple.Create(j, j.Weight));

            // And run through each plot
            foreach (var p in plots)
            {
                mvaWeithedJetStream
                    .FuturePlot(p, "MVA")
                    .Save(dir);
                weithedJetStream
                    .FuturePlot(p, "")
                    .Save(dir);
            }
        }
开发者ID:gordonwatts,项目名称:JetCutStudies,代码行数:66,代码来源:Program.cs


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