• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Expressions.ConditionalExpression类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



ConditionalExpression类属于System.Linq.Expressions命名空间,在下文中一共展示了ConditionalExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SerializableConditionalExpression

 /// <summary>
 /// Constructor with an <see cref="ConditionalExpression"/> and an <see cref="ExpressionConverter"/>.
 /// </summary>
 /// <param name="expression">The original, not serializable <see cref="Expression"/>.</param>
 /// <param name="expConverter">The <see cref="ExpressionConverter"/> to convert contained <see cref="Expression">Expressions</see>.</param>
 public SerializableConditionalExpression(ConditionalExpression expression, ExpressionConverter expConverter)
     : base(expression, expConverter)
 {
     IfTrue = expression.IfTrue.MakeSerializable(expConverter);
     IfFalse = expression.IfFalse.MakeSerializable(expConverter);
     Test = expression.Test.MakeSerializable(expConverter);
 }
开发者ID:yallie,项目名称:zyan,代码行数:12,代码来源:SerializableConditionalExpression.cs


示例2: TryRemoveNullPropagation

        private bool TryRemoveNullPropagation(ConditionalExpression node, out Expression condition)
        {
            condition = null;
            if (!typeof(IEnumerable).IsAssignableFrom(node.Type)) {
                return false;
            }

            if (node.Test.NodeType != ExpressionType.Equal) {
                return false;
            }

            if (node.IfTrue.NodeType != ExpressionType.Call) {
                return false;
            }

            if (node.IfFalse.NodeType != ExpressionType.MemberAccess) {
                return false;
            }

            if (!node.Type.IsAssignableFrom(node.IfFalse.Type)) {
                return false;
            }

            _yankingNull = true;
            condition = node.IfFalse;
            _yankingNull = false;
            return true;
        }
开发者ID:scim,项目名称:ODataNullPropagationVisitor,代码行数:28,代码来源:EnumerableNullPropagationYanker.cs


示例3: UpdateConditional

 protected ConditionalExpression UpdateConditional(ConditionalExpression c, Expression test, Expression ifTrue, Expression ifFalse)
 {
     if (test != c.Test || ifTrue != c.IfTrue || ifFalse != c.IfFalse) {
         return Expression.Condition(test, ifTrue, ifFalse);
     }
     return c;
 }
开发者ID:kpfaulkner,项目名称:Linq-To-Search,代码行数:7,代码来源:ExpressionVisitor.cs


示例4: TryRemoveNullPropagation

        private bool TryRemoveNullPropagation(ConditionalExpression node, out Expression condition)
        {
            condition = null;
            if (node.IfTrue.NodeType != ExpressionType.Constant) {
                return false;
            }

            if (node.Test.NodeType != ExpressionType.Equal) {
                return false;
            }

            var test = (BinaryExpression)node.Test;
            var constantExpr = (ConstantExpression)node.IfTrue;

            if (node.IfFalse.NodeType != ExpressionType.Call) {
                return false;
            }

            var memberExpr = (MethodCallExpression)node.IfFalse;

            _yankingNull = true;
            condition = Visit(memberExpr);
            _yankingNull = false;
            return true;
        }
开发者ID:ray2k,项目名称:ODataNullPropagationVisitor,代码行数:25,代码来源:MethodCallNullPropagationYanker.cs


示例5: VisitConditional

 protected override Expression VisitConditional(ConditionalExpression node)
 {
     return Expression.Condition(
         Visit(node.Test),
         Visit(node.IfTrue),
         Visit(node.IfFalse));
 }
开发者ID:fedeneo77,项目名称:Handlebars.Net,代码行数:7,代码来源:PathBinder.cs


示例6: TryToCoalesceAsNullable

        private Expression TryToCoalesceAsNullable(ConditionalExpression c)
        {
            var hasValueTarget = (Expression)null;
            var getValueTarget = (Expression)null;

            var matched = Matcher
                .For(c.Test).AsPropertyOrField()
                    .Property(property => property.Name == "HasValue" && property.DeclaringType.IsGenericTypeDefinedAs(typeof(Nullable<>)))
                    .Do(p => hasValueTarget = p.Expression)

                .For(c.IfTrue).AsConvert()
                    .Type(typeof(Nullable<>))
                    .Operand().AsMethodCall()
                        .Method(method => method.Name == "GetValueOrDefault"
                                       && method.DeclaringType.IsGenericTypeDefinedAs(typeof(Nullable<>)))
                        .Do(call => getValueTarget = call.Object)

                .Matched;

            if (!matched)
                return null;

            if (hasValueTarget != getValueTarget)
                return null;

            return Expression.Coalesce(getValueTarget, c.IfFalse);
        }
开发者ID:ashmind,项目名称:expressive,代码行数:27,代码来源:CoalescingVisitor.cs


示例7: VisitConditional

 public override Expression VisitConditional(ConditionalExpression c)
 {
     _Builder.Append("(");
     var conditional = base.VisitConditional(c);
     _Builder.Append(")");
     return conditional;
 }
开发者ID:g0t4,项目名称:ExpectEx,代码行数:7,代码来源:AssertionExpressionVisitor.cs


示例8: VisitConditional

        protected override Expression VisitConditional(ConditionalExpression expression)
        {
            var test = this.Visit(expression.Test);
            var ifFalse = this.Visit(expression.IfFalse);
            var ifTrue = this.Visit(expression.IfTrue);

            if (test is BitBooleanExpression)
            {
                test = Expression.Equal(test, Expression.Constant(true));
            }

            if (ifFalse.Type.GetUnwrappedNullableType() == typeof(bool) && !(ifFalse is BitBooleanExpression))
            {
                ifFalse = BitBooleanExpression.Coerce(ifFalse);
            }

            if (ifTrue.Type.GetUnwrappedNullableType() == typeof(bool) && !(ifTrue is BitBooleanExpression))
            {
                ifTrue = BitBooleanExpression.Coerce(ifTrue);
            }

            if (test != expression.Test || ifFalse != expression.IfFalse || ifTrue != expression.IfTrue)
            {
                return new BitBooleanExpression(Expression.Condition(test, ifTrue, ifFalse));
            }
            else
            {
                return base.VisitConditional(expression);
            }
        }
开发者ID:ciker,项目名称:Shaolinq,代码行数:30,代码来源:SqlServerBooleanNormalizer.cs


示例9: VisitConditional

        protected override Expression VisitConditional(ConditionalExpression c)
        {
            c = (ConditionalExpression)base.VisitConditional(c);

            return TryToCoalesceAsObjects(c)
                ?? TryToCoalesceAsNullable(c)
                ?? c;
        }
开发者ID:ashmind,项目名称:expressive,代码行数:8,代码来源:CoalescingVisitor.cs


示例10: UpdateConditional

 protected static ConditionalExpression UpdateConditional(ConditionalExpression node, Expression test,
                                                          Expression ifTrue, Expression ifFalse)
 {
     if (node.Test != test || node.IfTrue != ifTrue || node.IfFalse != ifFalse)
     {
         return Expression.Condition(test, ifTrue, ifFalse);
     }
     return node;
 }
开发者ID:sprucemedia,项目名称:oinq,代码行数:9,代码来源:ExpressionVisitor.cs


示例11: HandleConditionalExpression

        /*********
        ** Protected methods
        *********/
        /// <summary>Handles the conditional expression (equivalent to <c>.If {} .Else {}</c> in the sample expression tree in the <see cref="FixStringMethodsVisitor"/> remarks).</summary>
        /// <param name="original">The original expression.</param>
        /// <param name="ifElse">The conditional expression.</param>
        /// <returns>A reduced if/else statement if it contains any of the matched methods. Otherwise, the original expression.</returns>
        private Expression HandleConditionalExpression(Expression original, ConditionalExpression ifElse)
        {
            var elseExpression = ifElse.IfFalse as UnaryExpression;
            if (elseExpression != null)
            {
                var methodCallExpression = elseExpression.Operand as MethodCallExpression;
                if (methodCallExpression != null)
                {
                    if (this.BooleanReturnStringMethods.Contains(methodCallExpression.Method))
                    {
                        var methodCallReplacement = Expression.Call(
                            methodCallExpression.Object,
                            methodCallExpression.Method,
                            methodCallExpression.Arguments);

                        // Convert the result to a nullable boolean so the Expression.Equal works.
                        var result = Expression.Convert(methodCallReplacement, typeof(bool?));
                        return result;
                    }

                    if (this.IntegerStringMethods.Contains(methodCallExpression.Method))
                    {
                        var methodCallReplacement = Expression.Call(
                            methodCallExpression.Object,
                            methodCallExpression.Method,
                            methodCallExpression.Arguments);

                        var result = Expression.Convert(methodCallReplacement, typeof(int?));
                        return result;
                    }
                }
            }

            var firstLevelMethodCallExpression = ifElse.IfFalse as MethodCallExpression;
            if (firstLevelMethodCallExpression != null)
            {
                // Using the method name and declaring type as strings because I don't want to add a dependency to the project for a simple check like that.
                if (firstLevelMethodCallExpression.Method.DeclaringType != null &&
                    firstLevelMethodCallExpression.Method.DeclaringType.FullName == "System.Web.Http.OData.Query.Expressions.ClrSafeFunctions" &&
                    (firstLevelMethodCallExpression.Method.Name == "SubstringStartAndLength"  || firstLevelMethodCallExpression.Method.Name == "SubstringStart"))
                {
                    var arguments = firstLevelMethodCallExpression.Arguments.Skip(1).ToArray();
                    return Expression.Call(
                        firstLevelMethodCallExpression.Arguments[0],
                        typeof(string).GetMethod("Substring", arguments.Select(x => typeof(int)).ToArray()),
                        arguments);
                }

                if (this.ConcatStringMethods.Contains(firstLevelMethodCallExpression.Method))
                {
                    return Expression.Add(firstLevelMethodCallExpression.Arguments.First(), firstLevelMethodCallExpression.Arguments.Last(), firstLevelMethodCallExpression.Method);
                }
            }

            return original;
        }
开发者ID:behaug,项目名称:webapi.nhibernate-odata,代码行数:63,代码来源:FixStringMethodsVisitor.cs


示例12: VisitConditional

        protected override Expression VisitConditional(ConditionalExpression node)
        {
            DefaultExpression defaultExpression = node.IfFalse as DefaultExpression;

            if (defaultExpression == null || defaultExpression.Type != typeof (void) || !_canReplace)
                return base.VisitConditional(node);

            _canReplace = false;    
            return Visit(Expression.IfThenElse(node.Test, node.IfTrue, Replacement));
        }
开发者ID:Pzixel,项目名称:ZLinq,代码行数:10,代码来源:ZComparerBuilderVisitor.cs


示例13: Conditional

 void Conditional(ConditionalExpression expression)
 {
     Write("Conditional:");
     Write("Test:");
     Expression(expression.Test);
     Write("IfTrue:");
     Expression(expression.IfTrue);
     Write("IfFalse:");
     Expression(expression.IfFalse);
 }
开发者ID:rogernorling,项目名称:csharp-utilities,代码行数:10,代码来源:LinqDom.cs


示例14: VisitConditional

 protected override Expression VisitConditional(ConditionalExpression node)
 {
     var cond = Visit(node.Test);
     AddParameter(cond);
     var lhs = Visit(node.IfTrue);
     AddParameter(lhs);
     var rhs = Visit(node.IfFalse);
     AddParameter(rhs);
     return null;
 }
开发者ID:hazama-yuinyan,项目名称:Expresso,代码行数:10,代码来源:ParameterCollector.cs


示例15: VisitConditional

        protected override Expression VisitConditional(ConditionalExpression expression)
        {
            var constantExpression = expression.Test as ConstantExpression;

            if (constantExpression != null)
            {
                return Convert.ToBoolean(constantExpression.Value) ? expression.IfTrue : expression.IfFalse;
            }

            return base.VisitConditional(expression);
        }
开发者ID:ciker,项目名称:Shaolinq,代码行数:11,代码来源:SqlConditionalEliminator.cs


示例16: Condition

 internal static Condition Condition(ConditionalExpression expression)
 {
     return new Condition()
     {
         Type = expression.Type != expression.IfTrue.Type
             ? TypeRef.Serialize(expression.Type)
             : null,
         Test = Serialize(expression.Test),
         IfTrue = Serialize(expression.IfTrue),
         IfFalse = Serialize(expression.IfFalse),
     }.If(n => n.Type == null, n => n.TypeHint = TypeRef.Serialize(expression.Type));
 }
开发者ID:takeshik,项目名称:yacq,代码行数:12,代码来源:Condition.cs


示例17: VisitConditionalExpression

		protected override Expression VisitConditionalExpression(ConditionalExpression expression)
		{
			var oldRequiresJoinForNonIdentifier = _requiresJoinForNonIdentifier;
			_requiresJoinForNonIdentifier = !_preventJoinsInConditionalTest && _requiresJoinForNonIdentifier;
			var newTest = VisitExpression(expression.Test);
			_requiresJoinForNonIdentifier = oldRequiresJoinForNonIdentifier;
			var newFalse = VisitExpression(expression.IfFalse);
			var newTrue = VisitExpression(expression.IfTrue);
			if ((newTest != expression.Test) || (newFalse != expression.IfFalse) || (newTrue != expression.IfTrue))
				return Expression.Condition(newTest, newTrue, newFalse);
			return expression;
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:12,代码来源:MemberExpressionJoinDetector.cs


示例18: VisitConditional

        protected override Expression VisitConditional(ConditionalExpression node)
        {
            if (node.IfFalse.NodeType != ExpressionType.Throw)
            {
                return base.VisitConditional(node);
            }

            Console.WriteLine(node.ToString());

            Expression<Func<Object>> dummyFalseResult = () => DUMMY_RESULT;
            var invokeDummyFalseResult = Expression.Invoke(dummyFalseResult, null);
            return Expression.Condition(node.Test, node.IfTrue, invokeDummyFalseResult);
        }
开发者ID:renestein,项目名称:DynamicCheckPropertyExistence,代码行数:13,代码来源:Program.cs


示例19: VisitConditional

        protected override Expression VisitConditional(ConditionalExpression node)
        {
            Expression expression;
            if (TryRemoveNullPropagation(node, out expression)) {
                return expression;
            }

            if (_yankingNull && IsNullCheck(node.Test)) {
                return Visit(node.IfFalse);
            }

            return base.VisitConditional(node);
        }
开发者ID:ray2k,项目名称:ODataNullPropagationVisitor,代码行数:13,代码来源:NullPropagationYanker.cs


示例20: VisitConditional

		protected override Expression VisitConditional(ConditionalExpression node)
		{
			var newExpr = base.VisitConditional(node);
			if (newExpr.NodeType == ExpressionType.Conditional)
			{
				var cond = (ConditionalExpression) newExpr;
				if (cond.Test.NodeType == ExpressionType.Constant)
				{
					var testResult = (bool) ((ConstantExpression) cond.Test).Value;
					return testResult ? cond.IfTrue : cond.IfFalse;
				}
			}
			return newExpr;
		}
开发者ID:TargetProcess,项目名称:Target-Process-Plugins,代码行数:14,代码来源:BooleanEvaluator.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Expressions.ConstantExpression类代码示例发布时间:2022-05-26
下一篇:
C# Expressions.BinaryExpression类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap