當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。