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


C# Expressions.ConditionalExpression类代码示例

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


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


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