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


C# ExpressionContext.Evaluate方法代码示例

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


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

示例1: filter

        /// <summary>
        ///     Used to filter the PlayerStatsRow results based on any user-specified metric stats criteria.
        /// </summary>
        /// <param name="o">The o.</param>
        /// <returns></returns>
        private bool filter(object o)
        {
            var psr = (PlayerStatsRow) o;
            var ps = new PlayerStats(psr);
            bool keep = true;
            var context = new ExpressionContext();
            IGenericExpression<bool> ige;
            if (!String.IsNullOrWhiteSpace(txtYearsProVal.Text))
            {
                ige = context.CompileGeneric<bool>(psr.YearsPro.ToString() + cmbYearsProOp.SelectedItem + txtYearsProVal.Text);
                if (ige.Evaluate() == false)
                {
                    return false;
                }
            }
            if (!String.IsNullOrWhiteSpace(txtYOBVal.Text))
            {
                context = new ExpressionContext();
                ige = context.CompileGeneric<bool>(psr.YearOfBirth.ToString() + cmbYOBOp.SelectedItem + txtYOBVal.Text);
                if (ige.Evaluate() == false)
                {
                    return false;
                }
            }
            if (!String.IsNullOrWhiteSpace(txtHeightVal.Text))
            {
                double metricHeight = MainWindow.IsImperial
                                          ? PlayerStatsRow.ConvertImperialHeightToMetric(txtHeightVal.Text)
                                          : Convert.ToDouble(txtHeightVal.Text);
                context = new ExpressionContext();
                ige = context.CompileGeneric<bool>(psr.Height.ToString() + cmbHeightOp.SelectedItem + metricHeight.ToString());
                if (ige.Evaluate() == false)
                {
                    return false;
                }
            }
            if (!String.IsNullOrWhiteSpace(txtWeightVal.Text))
            {
                double imperialWeight = MainWindow.IsImperial
                                            ? Convert.ToDouble(txtWeightVal.Text)
                                            : PlayerStatsRow.ConvertMetricWeightToImperial(txtWeightVal.Text);
                context = new ExpressionContext();
                ige = context.CompileGeneric<bool>(psr.Weight.ToString() + cmbWeightOp.SelectedItem + imperialWeight.ToString());
                if (ige.Evaluate() == false)
                {
                    return false;
                }
            }
            if (!String.IsNullOrWhiteSpace(txtContractYLeftVal.Text))
            {
                context = new ExpressionContext();
                ige =
                    context.CompileGeneric<bool>((chkExcludeOption.IsChecked.GetValueOrDefault()
                                                      ? psr.ContractYearsMinusOption.ToString()
                                                      : psr.ContractYears.ToString()) + cmbContractYLeftOp.SelectedItem +
                                                 txtContractYLeftVal.Text);
                if (ige.Evaluate() == false)
                {
                    return false;
                }
            }

            foreach (string contractYear in lstContract.Items.Cast<string>())
            {
                string[] parts = contractYear.Split(' ');
                ige =
                    context.CompileGeneric<bool>(psr.GetType().GetProperty("ContractY" + parts[1]).GetValue(psr, null) + parts[2] +
                                                 parts[3]);
                keep = ige.Evaluate();
                if (!keep)
                {
                    return keep;
                }
            }

            IEnumerable<string> totalsFilters = lstTotals.Items.Cast<string>();
            Parallel.ForEach(totalsFilters, (item, loopState) =>
                {
                    string[] parts = item.Split(' ');
                    parts[0] = parts[0].Replace("3P", "TP");
                    parts[0] = parts[0].Replace("TO", "TOS");
                    context = new ExpressionContext();
                    ige = context.CompileGeneric<bool>(psr.GetType().GetProperty(parts[0]).GetValue(psr, null) + parts[1] + parts[2]);
                    keep = ige.Evaluate();
                    if (!keep)
                    {
                        loopState.Stop();
                    }
                });

            if (!keep)
            {
                return keep;
            }

//.........这里部分代码省略.........
开发者ID:rainierpunzalan,项目名称:nba-stats-tracker,代码行数:101,代码来源:PlayerSearchWindow.xaml.cs

示例2: filter

        /// <summary>Used to filter the PlayerStatsRow results based on any user-specified metric stats criteria.</summary>
        /// <param name="o">The o.</param>
        /// <returns></returns>
        private bool filter(object o)
        {
            var psr = (PlayerStatsRow) o;
            var ps = new PlayerStats(psr);
            var keep = true;
            var context = new ExpressionContext();
            IGenericExpression<bool> ige;

            if (!String.IsNullOrWhiteSpace(_yearsProVal))
            {
                ige = context.CompileGeneric<bool>(psr.YearsPro.ToString() + _yearsProOp + _yearsProVal);
                if (ige.Evaluate() == false)
                {
                    return false;
                }
            }
            if (!String.IsNullOrWhiteSpace(_yobVal))
            {
                context = new ExpressionContext();
                ige = context.CompileGeneric<bool>(psr.YearOfBirth.ToString() + _yobOp + _yobVal);
                if (ige.Evaluate() == false)
                {
                    return false;
                }
            }
            if (!String.IsNullOrWhiteSpace(_heightVal))
            {
                var metricHeight = MainWindow.IsImperial
                                       ? PlayerStatsRow.ConvertImperialHeightToMetric(_heightVal)
                                       : Convert.ToDouble(_heightVal);
                context = new ExpressionContext();
                ige = context.CompileGeneric<bool>(psr.Height.ToString() + _heightOp + metricHeight.ToString());
                if (ige.Evaluate() == false)
                {
                    return false;
                }
            }
            if (!String.IsNullOrWhiteSpace(_weightVal))
            {
                var imperialWeight = MainWindow.IsImperial
                                         ? Convert.ToDouble(_weightVal)
                                         : PlayerStatsRow.ConvertMetricWeightToImperial(_weightVal);
                context = new ExpressionContext();
                ige = context.CompileGeneric<bool>(psr.Weight.ToString() + _weightOp + imperialWeight.ToString());
                if (ige.Evaluate() == false)
                {
                    return false;
                }
            }
            if (!String.IsNullOrWhiteSpace(_contractYearsLeftVal))
            {
                context = new ExpressionContext();
                ige =
                    context.CompileGeneric<bool>(
                        (chkExcludeOption.IsChecked.GetValueOrDefault()
                             ? psr.ContractYearsMinusOption.ToString()
                             : psr.ContractYears.ToString()) + _contractYearsLeftOp + _contractYearsLeftVal);
                if (ige.Evaluate() == false)
                {
                    return false;
                }
            }

            foreach (var contractYear in _contractYears)
            {
                var parts = contractYear.Split(' ');
                ige =
                    context.CompileGeneric<bool>(
                        psr.GetType().GetProperty("ContractY" + parts[1]).GetValue(psr, null) + parts[2] + parts[3]);
                keep = ige.Evaluate();
                if (!keep)
                {
                    return false;
                }
            }

            var stopped = false;

            Parallel.ForEach(
                _totalsFilters,
                (item, loopState) =>
                    {
                        var parts = item.Split(' ');
                        parts[0] = parts[0].Replace("3P", "TP");
                        parts[0] = parts[0].Replace("TO", "TOS");
                        context = new ExpressionContext();
                        ige =
                            context.CompileGeneric<bool>(psr.GetType().GetProperty(parts[0]).GetValue(psr, null) + parts[1] + parts[2]);
                        keep = ige.Evaluate();
                        if (!keep)
                        {
                            stopped = true;
                            loopState.Stop();
                        }
                    });

            if (!keep || stopped)
//.........这里部分代码省略.........
开发者ID:jaosming,项目名称:nba-stats-tracker,代码行数:101,代码来源:PlayerSearchWindow.xaml.cs


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