本文整理汇总了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;
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
}