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

C# Expressions.BinaryExpression类代码示例

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

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



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

示例1: CheckShortCircuitAnd

        private static bool CheckShortCircuitAnd(BinaryExpression expression, StringBuilder queryBuilder, Action<Expression> visitExpression)
        {
            if (expression.NodeType == ExpressionType.And || expression.NodeType == ExpressionType.AndAlso)
            {
                var ceLeft = expression.Left as ConstantExpression;
                var ceRight = expression.Right as ConstantExpression;

                if (ceLeft != null && ceLeft.Type == typeof(bool))
                {
                    if ((bool)ceLeft.Value)
                        visitExpression(expression.Right);
                    else
                        queryBuilder.Append("false ");
                    return true;
                }
                else if (ceRight != null && ceRight.Type == typeof(bool))
                {
                    if ((bool)ceRight.Value)
                        visitExpression(expression.Left);
                    else
                        queryBuilder.Append("false ");
                    return true;
                }
            }
            return false;
        }
开发者ID:nutrija,项目名称:revenj,代码行数:26,代码来源:ExpressionShortCircuiting.cs


示例2: CheckShortCircuitOr

        private static bool CheckShortCircuitOr(BinaryExpression expression, StringBuilder queryBuilder, Action<Expression> visitExpression)
        {
            if (expression.NodeType == ExpressionType.Or || expression.NodeType == ExpressionType.OrElse)
            {
                var ceLeft = expression.Left as ConstantExpression;
                var ceRight = expression.Right as ConstantExpression;

                if (ceLeft != null && (ceLeft.Type == typeof(bool) || ceLeft.Type == typeof(bool?)))
                {
                    if (true.Equals(ceLeft.Value))
                        queryBuilder.Append("true ");
                    else
                        visitExpression(expression.Right);
                    return true;
                }
                else if (ceRight != null && (ceRight.Type == typeof(bool) || ceRight.Type == typeof(bool?)))
                {
                    if (true.Equals(ceRight.Value))
                        queryBuilder.Append("true ");
                    else
                        visitExpression(expression.Left);
                    return true;
                }
            }
            return false;
        }
开发者ID:AnaMarjanica,项目名称:revenj,代码行数:26,代码来源:ExpressionShortCircuiting.cs


示例3: VisitBinary

		protected override Expression VisitBinary(BinaryExpression binaryExpr)
		{
			ResourceProperty resourceProperty = null;
			object obj = null;
			if (!ExpressionHelper.ContainsComparisonOperator(binaryExpr))
			{
				if (!ExpressionHelper.ContainsLogicalOperator(binaryExpr))
				{
					this.IsCompleteExpressionParsed = false;
				}
			}
			else
			{
				if (!ExpressionHelper.GetPropertyNameAndValue(binaryExpr, out resourceProperty, out obj))
				{
					TraceHelper.Current.DebugMessage("Expression is too complex to execute");
					this.IsCompleteExpressionParsed = false;
				}
				else
				{
					this.FilterProperties.Add(new KeyValuePair<ResourceProperty, object>(resourceProperty, obj));
				}
			}
			return base.VisitBinary(binaryExpr);
		}
开发者ID:nickchal,项目名称:pash,代码行数:25,代码来源:FilterPropertyFinder.cs


示例4: VisitBinary

        protected List<Microsoft.Z3.BoolExpr> VisitBinary(BinaryExpression b)
        {
            // Use recursion to generate Z3 constraints for each operand of the binary expression
            // left side -> create a Z3 expression representing the left side
            Expression left = Visit(b.Left);

            // right side -> creat a Z3 expression representing the right side
            Expression right = Visit(b.Right);

            // Put those into a Z3 format
            ExpressionType op = b.NodeType;

            using (Context ctx = new Context())
            {
                if (op == ExpressionType.LessThan)
                {
                    // ctx.MkLt(left, right);
                }

            }

            Console.WriteLine(b.ToString());

            // TODO - return a Z3 expression
            return null;
        }
开发者ID:izmaxx,项目名称:VBADataGenerator,代码行数:26,代码来源:Z3ExprVisitor.cs


示例5: GetValueFromEqualsExpression

        internal static string GetValueFromEqualsExpression(BinaryExpression be, Type memberDeclaringType, string memberName)
        {
            if (be.NodeType != ExpressionType.Equal)
                throw new Exception("There is a bug in this program.");

            if (be.Left.NodeType == ExpressionType.MemberAccess)
            {
                MemberExpression me = (MemberExpression)be.Left;

                if (IsSameTypeOrSubType(me.Member.DeclaringType, memberDeclaringType) && me.Member.Name == memberName)
                {
                    return GetValueFromExpression(be.Right);
                }
            }
            else if (be.Right.NodeType == ExpressionType.MemberAccess)
            {
                MemberExpression me = (MemberExpression)be.Right;

                if (IsSameTypeOrSubType(me.Member.DeclaringType, memberDeclaringType) && me.Member.Name == memberName)
                {
                    return GetValueFromExpression(be.Left);
                }
            }

            // We should have returned by now.
            throw new Exception("There is a bug in this program.");
        }
开发者ID:rupertbates,项目名称:GuardianOpenPlatform,代码行数:27,代码来源:ExpressionTreeHelpers.cs


示例6: ValidateConjunctiveExpression

        /// <summary>
        /// Validates whether the binary expression is valid AND / OR expression.
        /// </summary>
        /// <param name="binaryExpression">Binary conjuctive expression.</param>
        public static void ValidateConjunctiveExpression(BinaryExpression binaryExpression)
        {
            Utils.ThrowIfNull(binaryExpression, "binaryExpression");

            ExpressionHelper.ValidateConjuctiveNode(binaryExpression.Left);
            ExpressionHelper.ValidateConjuctiveNode(binaryExpression.Right);
        }
开发者ID:shai-guy,项目名称:azuread-graphapi-library-for-dotnet,代码行数:11,代码来源:ExpressionHelper.cs


示例7: SimpleProduct

        static Expression SimpleProduct(Expression left, Expression right, BinaryExpression product)
        {
            // ensure "left" is no quotient
            if(left.NodeType == ExpressionType.Divide)
            {
                BinaryExpression leftQuotient = (BinaryExpression)left;
                Expression nominator = SimpleProduct(right, leftQuotient.Left, null);
                return SimpleQuotient(nominator, leftQuotient.Right, null);
            }

            // ensure "right" is no quotient
            if(right.NodeType == ExpressionType.Divide)
            {
                BinaryExpression rightQuotient = (BinaryExpression)right;
                Expression nominator = SimpleProduct(left, rightQuotient.Left, null);
                return SimpleQuotient(nominator, rightQuotient.Right, null);
            }

            // ensure "right" is no product
            while(right.NodeType == ExpressionType.Multiply)
            {
                BinaryExpression rightProduct = (BinaryExpression)right;
                left = Expression.Multiply(left, rightProduct.Right);
                right = rightProduct.Left;
            }

            if((product == null) || (left != product.Left) || (right != product.Right))
            {
                return Expression.Multiply(left, right);
            }

            return product;
        }
开发者ID:JackWangCUMT,项目名称:mathnet-linqalgebra,代码行数:33,代码来源:AutoSimplify.cs


示例8: VisitBinary

 protected override Expression VisitBinary(BinaryExpression node)
 {
     switch(node.NodeType) {
     case ExpressionType.Equal:
     case ExpressionType.NotEqual:
       if(_model.IsEntity(node.Left.Type) || _model.IsEntity(node.Right.Type)) {
     //visit children and replace with EntitiesEqual
     var newLeft = Visit(node.Left);
     var newRight = Visit(node.Right);
     var method = node.NodeType == ExpressionType.Equal ? EntityCacheHelper.EntitiesEqualMethod : EntityCacheHelper.EntitiesNotEqualMethod;
     return Expression.Call(null, method, newLeft, newRight);
       }//if
       // compare both args, to cover expr like 'p.Name == null'
       if (node.Left.Type == typeof(string) && node.Right.Type == typeof(string) && _caseMode == StringCaseMode.CaseInsensitive) {
     var baseLeft = base.Visit(node.Left);
     var baseRight = base.Visit(node.Right);
     Expression result = Expression.Call(EntityCacheHelper.StringStaticEquals3Method,
                                          baseLeft, baseRight, EntityCacheHelper.ConstInvariantCultureIgnoreCase);
     if (node.NodeType == ExpressionType.NotEqual)
       result = Expression.Not(result);
     return result;
       }
       break;
       }//switch
       return base.VisitBinary(node);
 }
开发者ID:yuanfei05,项目名称:vita,代码行数:26,代码来源:CacheQueryRewriter.cs


示例9: VisitBinary

        protected override Expression VisitBinary(BinaryExpression node)
        {
            string operatorName;
            if (node.Method == null)
            {
                operatorName = string.Format(" {0} ", node.NodeType.GetName());
            }
            else
            {
                // VisitBinary should be called only for operators but its possible
                // that we don't know this special C# operators name

                var name = TypeNameConverter.GetCSharpOperatorName(node.Method);
                if (name != null)
                    operatorName = string.Format(" {0} ", name);
                else
                    operatorName = node.Method.Name;
            }
            // BinaryExpression consists of 3 parts: left operator right
            _rep = string.Format("{0}{1}{2}",
                Print(node.Left),
                operatorName,
                Print(node.Right));

            if (!_isHighLevel)
                _rep = string.Format("({0})", _rep);

            return node;
        }
开发者ID:SergeyTeplyakov,项目名称:VerificationFakes,代码行数:29,代码来源:ExpressionPrinterVisitor.cs


示例10: VisitBinary

 protected override Expression VisitBinary(BinaryExpression node)
 {
     var relation = string.Empty;
     switch (node.NodeType)
     {
         case ExpressionType.Equal:
             relation = " = ";
             break;
         case ExpressionType.NotEqual:
             relation = " <> ";
             break;
         case ExpressionType.GreaterThan:
             relation = " > ";
             break;
         case ExpressionType.GreaterThanOrEqual:
             relation = " >= ";
             break;
         case ExpressionType.LessThan:
             relation = " < ";
             break;
         case ExpressionType.LessThanOrEqual:
             relation = " <= ";
             break;
         case ExpressionType.Add:
             relation = " + ";
             break;
         case ExpressionType.Subtract:
             relation = " - ";
             break;
         default:
             break;
     }
     this.Condition = GetRelationCondition(relation, node);
     return node;
 }
开发者ID:BeanHsiang,项目名称:Greedy,代码行数:35,代码来源:BinaryExpressionVisitor.cs


示例11: PrintNode

 private static void PrintNode(BinaryExpression expression,
   int indent)
 {
     PrintNode(expression.Left, indent + 1);
     PrintSingle(expression, indent);
     PrintNode(expression.Right, indent + 1);
 }
开发者ID:troubleminds,项目名称:TIP,代码行数:7,代码来源:Listing12.25.ExamingingAnExpressTree.cs


示例12: VisitBinary

        protected override Expression VisitBinary(BinaryExpression b)
        {
            b = base.VisitBinary(b) as BinaryExpression;

            switch (b.NodeType)
            {
                case ExpressionType.Add:
                case ExpressionType.AddChecked:
                    if (b.Left.Type.Equals(typeof(String)))
                        return Expression.Call(MethodRepository.Concat, Expression.NewArrayInit(Types.String, b.Left, Expressor.ToString(b.Right)));
                    if (b.Right.Type.Equals(typeof(String)))
                        return Expression.Call(MethodRepository.Concat, Expression.NewArrayInit(Types.String, Expressor.ToString(b.Left), b.Right));
                    return b;
                case ExpressionType.ArrayIndex:
                    if (b.Type == Types.Byte)
                    {

                    }
                    return b;
                case ExpressionType.Equal:
                case ExpressionType.NotEqual:
                default:
                    return b;
            }
        }
开发者ID:jaykizhou,项目名称:elinq,代码行数:25,代码来源:FunctionBinder.cs


示例13: VisitBinary

		protected override Expression VisitBinary(BinaryExpression binaryExpression)
		{
			var nodeType = binaryExpression.NodeType;

			if (nodeType == ExpressionType.Equal || nodeType == ExpressionType.NotEqual)
			{
				var left = this.Visit(binaryExpression.Left).StripAndGetConstant();
				var right = this.Visit(binaryExpression.Right).StripAndGetConstant();

				if (left != null && right != null)
				{
					if (left.Value == null && right.Value == null)
					{
						return Expression.Constant(true);
					}

					if (left.Value == null || right.Value == null)
					{
						return Expression.Constant(false);
					}
				}

				if (left != null && left.Value == null)
				{
					return new SqlFunctionCallExpression(binaryExpression.Type, nodeType == ExpressionType.Equal ? SqlFunction.IsNull : SqlFunction.IsNotNull, binaryExpression.Right);
				}
				else if (right != null && right.Value == null)
				{
					return new SqlFunctionCallExpression(binaryExpression.Type, nodeType == ExpressionType.Equal ? SqlFunction.IsNull : SqlFunction.IsNotNull, binaryExpression.Left);
				}
			}

			return base.VisitBinary(binaryExpression);
		}
开发者ID:tumtumtum,项目名称:Shaolinq,代码行数:34,代码来源:SqlNullComparisonCoalescer.cs


示例14: VisitBinary

        protected override Expression VisitBinary(BinaryExpression binaryExpression)
        {
            var left = this.Visit(binaryExpression.Left);
            var right = this.Visit(binaryExpression.Right);

            if (left.Type.GetUnwrappedNullableType().IsEnum)
            {
                if (!right.Type.GetUnwrappedNullableType().IsEnum)
                {
                    right = Expression.Convert(Expression.Call(null, MethodInfoFastRef.EnumToObjectMethod, Expression.Constant(left.Type.GetUnwrappedNullableType()), Expression.Convert(right, typeof(int))), left.Type);
                }
            }
            else if (right.Type.GetUnwrappedNullableType().IsEnum)
            {
                if (!left.Type.GetUnwrappedNullableType().IsEnum)
                {
                    left = Expression.Convert(Expression.Call(null, MethodInfoFastRef.EnumToObjectMethod, Expression.Constant(right.Type.GetUnwrappedNullableType()), Expression.Convert(left, typeof(int))), right.Type);
                }
            }

            if (left != binaryExpression.Left || right != binaryExpression.Right)
            {
                return Expression.MakeBinary(binaryExpression.NodeType, left, right);
            }

            return binaryExpression;
        }
开发者ID:ciker,项目名称:Shaolinq,代码行数:27,代码来源:SqlEnumTypeNormalizer.cs


示例15: VisitBinary

        protected override Expression VisitBinary(BinaryExpression binaryExpression)
        {
            if (binaryExpression.NodeType == ExpressionType.Or
                || binaryExpression.NodeType == ExpressionType.And
                || binaryExpression.NodeType == ExpressionType.OrElse
                || binaryExpression.NodeType == ExpressionType.AndAlso
                && binaryExpression.Type.GetUnwrappedNullableType() == typeof(bool))
            {
                var left = this.Visit(binaryExpression.Left);
                var right = this.Visit(binaryExpression.Right);

                if (left.Type.GetUnwrappedNullableType() == typeof(bool) && (left is BitBooleanExpression))
                {
                    left = Expression.Equal(left, Expression.Constant(true));
                }

                if (right.Type.GetUnwrappedNullableType() == typeof(bool) && (right is BitBooleanExpression))
                {
                    right = Expression.Equal(right, Expression.Constant(false));
                }

                if (left != binaryExpression.Left || right != binaryExpression.Right)
                {
                    return Expression.MakeBinary(binaryExpression.NodeType, left, right);
                }
            }

            return base.VisitBinary(binaryExpression);
        }
开发者ID:smadep,项目名称:Shaolinq,代码行数:29,代码来源:SqlServerBooleanNormalizer.cs


示例16: VisitBinary

            protected override Expression VisitBinary(BinaryExpression binary)
            {
                if (_operators.ContainsKey(binary.NodeType))
                {
                    var fragment = _parent.buildSimpleWhereClause(_mapping, binary);
                    _register.Peek()(fragment);

                    return null;
                }

                if ((binary.NodeType == ExpressionType.AndAlso) || (binary.NodeType == ExpressionType.OrElse))
                {
                    var separator = binary.NodeType == ExpressionType.AndAlso
                        ? "and"
                        : "or";

                    var compound = new CompoundWhereFragment(separator);
                    _register.Peek()(compound);
                    _register.Push(child => compound.Add(child));

                    Visit(binary.Left);
                    Visit(binary.Right);

                    _register.Pop();

                    return null;
                }


                throw new NotSupportedException($"Marten does not support the BinaryExpression {binary} (yet).");
            }
开发者ID:JasperFx,项目名称:marten,代码行数:31,代码来源:WhereClauseVisitor.cs


示例17: ContainmentWhereFragment

        public ContainmentWhereFragment(ISerializer serializer, BinaryExpression binary)
        {
            _serializer = serializer;

            var visitor = new FindMembers();
            visitor.Visit(binary.Left);

            var members = visitor.Members;

            if (members.Count > 1)
            {
                var dict = new Dictionary<string, object>();
                var member = members.Last();
                var value = MartenExpressionParser.Value(binary.Right);
                dict.Add(member.Name, value);

                members.Reverse().Skip(1).Each(m =>
                {
                    dict = new Dictionary<string, object> { { m.Name, dict}};
                });

                _dictionary = dict;
            }
            else
            {
                _dictionary = new Dictionary<string, object>();

                var member = members.Single();
                var value = MartenExpressionParser.Value(binary.Right);
                _dictionary.Add(member.Name, value);

            }
        }
开发者ID:bojanv91,项目名称:Marten,代码行数:33,代码来源:ContainmentWhereFragment.cs


示例18: VisitBinary

 protected override Expression VisitBinary(BinaryExpression node)
 {
     // rewrite not equal
     if (node.NodeType == ExpressionType.NotEqual)
     {
         return
             Visit(Expression.MakeUnary(ExpressionType.Not,
                 Expression.MakeBinary(ExpressionType.Equal, node.Left, node.Right), node.Type));
     }
     // handle
     _query.Append("(");
     Visit(node.Left);
     switch (node.NodeType)
     {
         case ExpressionType.AndAlso:
             _query.Append(" AND ");
             break;
         case ExpressionType.OrElse:
             _query.Append(" OR ");
             break;
         case ExpressionType.Equal:
             _query.Append(":");
             break;
     }
     Visit(node.Right);
     _query.Append(")");
     // done
     return node;
 }
开发者ID:Qobra,项目名称:Solr.Net,代码行数:29,代码来源:SolrLuceneExpressionVisitor.cs


示例19: VisitBinary

        protected override Expression VisitBinary(BinaryExpression node)
        {
            // Go and visit the left hand side of this expression
            this.Visit(node.Left);

            // Add the operator in the middle
            switch (node.NodeType)
            {
                case ExpressionType.Equal:
                    this.sql.Append("=");
                break;

                case ExpressionType.And:
                case ExpressionType.AndAlso:
                case ExpressionType.Or:
                case ExpressionType.OrElse:
                    this.sql.Append(",");
                break;

                default:
                    throw new Exception
                    (
                        "Operator Not Known => " + node.NodeType
                    );
            }

            // Operator needs a space after it.
            this.sql.Append(" ");

            // Now visit the right hand side of this expression.
            this.Visit(node.Right);

            return node;
        }
开发者ID:brad-jones,项目名称:dotneteloquent,代码行数:34,代码来源:AssignmentsConverter.cs


示例20: VisitBinary

        protected override Expression VisitBinary(BinaryExpression b)
        {
            this.Visit(b.Left);
            switch (b.NodeType) {
                case ExpressionType.And | ExpressionType.AndAlso:
                    sb.Append(" and ");
                    break;
                case ExpressionType.Or:
                    sb.Append(" OR");
                    break;
                case ExpressionType.Equal:
                    sb.Append(" = ");
                    break;
                case ExpressionType.NotEqual:
                    sb.Append(" != ");
                    break;
                case ExpressionType.LessThan:
                    sb.Append(" < ");
                    break;
                case ExpressionType.LessThanOrEqual:
                    sb.Append(" <= ");
                    break;
                case ExpressionType.GreaterThan:
                    sb.Append(" > ");
                    break;
                case ExpressionType.GreaterThanOrEqual:
                    sb.Append(" >= ");
                    break;
                default:
                    throw new NotSupportedException(string.Format("The binary operator '{0}' is not supported by SimpleDB.", b.NodeType));
            }

            this.Visit(b.Right);
            return b;
        }
开发者ID:sipsorcery,项目名称:sipsorcery,代码行数:35,代码来源:SimpleDBExpressionVisitor.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Expressions.ConditionalExpression类代码示例发布时间:2022-05-26
下一篇:
C# Linq.CompositeDisposable类代码示例发布时间: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