當前位置: 首頁>>代碼示例>>C#>>正文


C# Expression.Nullify方法代碼示例

本文整理匯總了C#中System.Linq.Expressions.Expression.Nullify方法的典型用法代碼示例。如果您正苦於以下問題:C# Expression.Nullify方法的具體用法?C# Expression.Nullify怎麽用?C# Expression.Nullify使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Linq.Expressions.Expression的用法示例。


在下文中一共展示了Expression.Nullify方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: NotEqualNullable

        public static Expression NotEqualNullable(Expression e1, Expression e2)
        {
            if (e1.Type.IsNullable() == e2.Type.IsNullable())
                return Expression.NotEqual(e1, e2);

            return Expression.NotEqual(e1.Nullify(), e2.Nullify());
        }
開發者ID:rondoo,項目名稱:framework,代碼行數:7,代碼來源:SmartEqualizer.cs

示例2: EqualNullable

        public static Expression EqualNullable(Expression e1, Expression e2)
        {
            if (e1 == NewId || e2 == NewId)
                return False;

            if (e1.Type.IsNullable() == e2.Type.IsNullable())
                return Expression.Equal(e1, e2);

            return Expression.Equal(e1.Nullify(), e2.Nullify());
        }
開發者ID:rondoo,項目名稱:framework,代碼行數:10,代碼來源:SmartEqualizer.cs

示例3: ParameterFactory

        public override MemberInitExpression ParameterFactory(Expression parameterName, SqlDbType sqlType, string udtTypeName, bool nullable, Expression value)
        {
            Expression valueExpr = Expression.Convert(IsDate(sqlType) ? Expression.Call(miAsserDateTime, value.Nullify()) : value, typeof(object));

            if (nullable)
                valueExpr = Expression.Condition(Expression.Equal(value, Expression.Constant(null, value.Type)),
                            Expression.Constant(DBNull.Value, typeof(object)),
                            valueExpr);

            NewExpression newExpr = Expression.New(typeof(SqlParameter).GetConstructor(new[] { typeof(string), typeof(object) }), parameterName, valueExpr);


            List<MemberBinding> mb = new List<MemberBinding>()
            {
                Expression.Bind(typeof(SqlParameter).GetProperty("IsNullable"), Expression.Constant(nullable)),
                Expression.Bind(typeof(SqlParameter).GetProperty("SqlDbType"), Expression.Constant(sqlType)),
            };

            if (sqlType == SqlDbType.Udt)
                mb.Add(Expression.Bind(typeof(SqlParameter).GetProperty("UdtTypeName"), Expression.Constant(udtTypeName)));

            return Expression.MemberInit(newExpr, mb);
        }
開發者ID:signumsoftware,項目名稱:framework,代碼行數:23,代碼來源:SqlConnector.cs

示例4: GetCompareExpression

 public static Expression GetCompareExpression(FilterOperation operation, Expression left, Expression right, bool inMemory = false)
 {
     switch (operation)
     {
         case FilterOperation.EqualTo: return Expression.Equal(left, right);
         case FilterOperation.DistinctTo: 
             {
                 var t = left.Type.UnNullify();
                 var mi = t.IsValueType ? miDistinctNullable : miDistinct;
                 return Expression.Call(mi.MakeGenericMethod(t), left.Nullify(), right.Nullify());
             }
         case FilterOperation.GreaterThan: return Expression.GreaterThan(left, right);
         case FilterOperation.GreaterThanOrEqual: return Expression.GreaterThanOrEqual(left, right);
         case FilterOperation.LessThan: return Expression.LessThan(left, right);
         case FilterOperation.LessThanOrEqual: return Expression.LessThanOrEqual(left, right);
         case FilterOperation.Contains: return Expression.Call(Fix(left, inMemory), miContains, right);
         case FilterOperation.StartsWith: return Expression.Call(Fix(left, inMemory), miStartsWith, right);
         case FilterOperation.EndsWith: return Expression.Call(Fix(left, inMemory), miEndsWith, right);
         case FilterOperation.Like: return Expression.Call(miLike, Fix(left, inMemory), right);
         case FilterOperation.NotContains: return Expression.Not(Expression.Call(Fix(left, inMemory), miContains, right));
         case FilterOperation.NotStartsWith: return Expression.Not(Expression.Call(Fix(left, inMemory), miStartsWith, right));
         case FilterOperation.NotEndsWith: return Expression.Not(Expression.Call(Fix(left, inMemory), miEndsWith, right));
         case FilterOperation.NotLike: return Expression.Not(Expression.Call(miLike, Fix(left, inMemory), right));
         default:
             throw new InvalidOperationException("Unknown operation {0}".Formato(operation));
     }
 }
開發者ID:nuub666,項目名稱:framework,代碼行數:27,代碼來源:QueryUtils.cs

示例5: ParameterFactory

        public override MemberInitExpression ParameterFactory(Expression parameterName, SqlDbType sqlType, string udtTypeName, bool nullable, Expression value)
        {
            Expression valueExpr = Expression.Convert(IsDate(sqlType) ? Expression.Call(miAsserDateTime, value.Nullify()) : value, typeof(object));

            if (nullable)
                valueExpr = Expression.Condition(Expression.Equal(value, Expression.Constant(null, value.Type)),
                            Expression.Constant(DBNull.Value, typeof(object)),
                            valueExpr);

            NewExpression newExpr = Expression.New(typeof(SqlCeParameter).GetConstructor(new[] { typeof(string), typeof(object) }), parameterName, valueExpr);


            List<MemberBinding> mb = new List<MemberBinding>()
            {
                Expression.Bind(typeof(SqlCeParameter).GetProperty("IsNullable"), Expression.Constant(nullable)),
                Expression.Bind(typeof(SqlCeParameter).GetProperty("SqlDbType"), Expression.Constant(sqlType)),
            };

            if (sqlType == SqlDbType.Udt)
                throw new InvalidOperationException("User Defined Tyeps not supported on SQL Server Compact ({0})".FormatWith(udtTypeName));

            return Expression.MemberInit(newExpr, mb);
        }
開發者ID:rondoo,項目名稱:framework,代碼行數:23,代碼來源:SqlCeConnector.cs

示例6: EqualNullableGroupBy

 public static Expression EqualNullableGroupBy(Expression e1, Expression e2)
 {
     return Expression.Or(Expression.Equal(e1.Nullify(), e2.Nullify()),
         Expression.And(new IsNullExpression(e1), new IsNullExpression(e2)));
 }
開發者ID:rondoo,項目名稱:framework,代碼行數:5,代碼來源:SmartEqualizer.cs


注:本文中的System.Linq.Expressions.Expression.Nullify方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。