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

C# Expressions.Expression类代码示例

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

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



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

示例1: CompileBulkImporter

        public override Expression CompileBulkImporter(EnumStorage enumStorage, Expression writer, ParameterExpression document, ParameterExpression alias, ParameterExpression serializer)
        {
            var method = writeMethod.MakeGenericMethod(typeof(string));
            var dbType = Expression.Constant(DbType);

            return Expression.Call(writer, method, alias, dbType);
        }
开发者ID:danielmarbach,项目名称:marten,代码行数:7,代码来源:DocTypeArgument.cs


示例2: Visit

        protected override Expression Visit(Expression exp)
        {
            if(exp != null)
                return base.Visit(exp);

            return exp;
        }
开发者ID:kccarter,项目名称:SubSonic-3.0,代码行数:7,代码来源:QueryVisitor.cs


示例3: CanBeEvaluatedLocally

        // private static methods
        private static Boolean CanBeEvaluatedLocally(Expression expression, IQueryProvider queryProvider)
        {
            // any operation on a query can't be done locally
            var constantExpression = expression as ConstantExpression;
            if (constantExpression != null)
            {
                var query = constantExpression.Value as IQueryable;
                if (query != null && (queryProvider == null || query.Provider == queryProvider))
                {
                    return false;
                }
            }

            var methodCallExpression = expression as MethodCallExpression;
            if (methodCallExpression != null)
            {
                Type declaringType = methodCallExpression.Method.DeclaringType;
                if (declaringType == typeof (Enumerable) || declaringType == typeof (Queryable))
                {
                    return false;
                }
            }

            if (expression.NodeType == ExpressionType.Convert && expression.Type == typeof (Object))
            {
                return true;
            }

            if (expression.NodeType == ExpressionType.Parameter || expression.NodeType == ExpressionType.Lambda)
            {
                return false;
            }

            return true;
        }
开发者ID:sprucemedia,项目名称:oinq,代码行数:36,代码来源:PartialEvaluator.cs


示例4: Binding

 internal Binding(Expression linqExpression, DbExpression cqtExpression)
 {
     //Contract.Requires(linqExpression != null);
     //Contract.Requires(cqtExpression != null);
     LinqExpression = linqExpression;
     CqtExpression = cqtExpression;
 }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:7,代码来源:Binding.cs


示例5: ExpressionToString

        public static string ExpressionToString(Expression expr)
        {
            if (propertyDebugView == null)
                propertyDebugView = typeof(Expression).GetTypeInfo().FindDeclaredProperty("DebugView", ReflectionFlag.NoException | ReflectionFlag.NonPublic | ReflectionFlag.Instance);

            return (string)propertyDebugView.GetValue(expr, null);
        }
开发者ID:strogo,项目名称:neolua,代码行数:7,代码来源:Parser.cs


示例6: GetDocumentType

        // private static methods
        private static Type GetDocumentType(Expression expression)
        {
            // look for the innermost nested constant of type MongoQueryable<T> and return typeof(T)
            var constantExpression = expression as ConstantExpression;
            if (constantExpression != null)
            {
                var constantType = constantExpression.Type;
                if (constantType.IsGenericType)
                {
                    var genericTypeDefinition = constantType.GetGenericTypeDefinition();
                    if (genericTypeDefinition == typeof(MongoQueryable<>))
                    {
                        return constantType.GetGenericArguments()[0];
                    }
                }
            }

            var methodCallExpression = expression as MethodCallExpression;
            if (methodCallExpression != null && methodCallExpression.Arguments.Count != 0)
            {
                return GetDocumentType(methodCallExpression.Arguments[0]);
            }

            var message = string.Format("Unable to find document type of expression: {0}.", ExpressionFormatter.ToString(expression));
            throw new ArgumentOutOfRangeException(message);
        }
开发者ID:newlee,项目名称:mongo-csharp-driver,代码行数:27,代码来源:MongoQueryTranslator.cs


示例7: Gather

 private void Gather(Expression expression)
 {
     BinaryExpression b = expression as BinaryExpression;
     if (b != null)
     {
         switch (b.NodeType)
         {
             case ExpressionType.Equal:
             case ExpressionType.NotEqual:
                 if (IsExternalColumn(b.Left) && GetColumn(b.Right) != null)
                 {
                     this.columns.Add(GetColumn(b.Right));
                 }
                 else if (IsExternalColumn(b.Right) && GetColumn(b.Left) != null)
                 {
                     this.columns.Add(GetColumn(b.Left));
                 }
                 break;
             case ExpressionType.And:
             case ExpressionType.AndAlso:
                 if (b.Type == typeof(bool) || b.Type == typeof(bool?))
                 {
                     this.Gather(b.Left);
                     this.Gather(b.Right);
                 }
                 break;
         }
     }
 }
开发者ID:CMONO,项目名称:elinq,代码行数:29,代码来源:JoinColumnGatherer.cs


示例8: Get

 public IEnumerable<ErrorLog> Get(
    Expression<Func<ErrorLog, bool>> filter = null,
    Func<IQueryable<ErrorLog>, IOrderedQueryable<ErrorLog>> orderBy = null,
    string includeProperties = "")
 {
     return _unitOfWork.ErrorLogRepository.Get(filter, orderBy, includeProperties);
 }
开发者ID:edgecomputing,项目名称:cats,代码行数:7,代码来源:ErrorLogService.cs


示例9: CreateSetFieldExpression

        internal static Expression CreateSetFieldExpression(Expression clone, Expression value, FieldInfo fieldInfo) {
            // workaround for readonly fields: use reflection, this is a lot slower but the only way except using il directly
            if (fieldInfo.IsInitOnly)
                return Expression.Call(Expression.Constant(fieldInfo), _fieldInfoSetValueMethod, clone, Expression.Convert(value, TypeHelper.ObjectType));

            return Expression.Assign(Expression.Field(clone, fieldInfo), value);
        }
开发者ID:geffzhang,项目名称:Foundatio,代码行数:7,代码来源:CloneExpressionHelper.cs


示例10: VisitExpression

		public override Expression VisitExpression(Expression expression)
		{
			if (expression == null)
			{
				return null;
			}

			switch ((NhExpressionType)expression.NodeType)
			{
				case NhExpressionType.Average:
				case NhExpressionType.Min:
				case NhExpressionType.Max:
				case NhExpressionType.Sum:
				case NhExpressionType.Count:
				case NhExpressionType.Distinct:
					return VisitNhAggregate((NhAggregatedExpression)expression);
				case NhExpressionType.New:
					return VisitNhNew((NhNewExpression)expression);
				case NhExpressionType.Star:
					return VisitNhStar((NhStarExpression)expression);
			}

			// Keep this variable for easy examination during debug.
			var expr = base.VisitExpression(expression);
			return expr;
		}
开发者ID:jlevitt,项目名称:nhibernate-core,代码行数:26,代码来源:NhExpressionTreeVisitor.cs


示例11: UnaryExpression

 internal UnaryExpression(ExpressionType nodeType, Expression expression, Type type, MethodInfo method)
 {
     _operand = expression;
     _method = method;
     _nodeType = nodeType;
     _type = type;
 }
开发者ID:mesheets,项目名称:Theraot-CF,代码行数:7,代码来源:UnaryExpression.net30.cs


示例12: PrettyPrint

 // public methods
 /// <summary>
 /// Pretty prints an Expression.
 /// </summary>
 /// <param name="node">The Expression to pretty print.</param>
 /// <returns>A string containing the pretty printed Expression.</returns>
 public string PrettyPrint(Expression node)
 {
     _sb = new StringBuilder();
     _indentation = "";
     Visit(node);
     return _sb.ToString();
 }
开发者ID:mpobrien,项目名称:mongo-csharp-driver,代码行数:13,代码来源:ExpressionPrettyPrinter.cs


示例13: CreatePropertyAccessExpression

        private Expression CreatePropertyAccessExpression(Expression instance, string propertyName)
        {
            CallSiteBinder binder = Binder.GetMember(CSharpBinderFlags.None, propertyName,
                typeof(DynamicPropertyAccessExpressionBuilder), new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) });

            return Expression.Dynamic(binder, typeof(object), new[] { instance });
        }
开发者ID:akhuang,项目名称:Asp.net-MVC-3,代码行数:7,代码来源:DynamicPropertyAccessExpressionBuilder.cs


示例14: EvaluateUnsupported

		EvaluationResult EvaluateUnsupported(Expression expression) {
			try {
				return EvaluationResult.Success(expression.Type, Expression.Lambda<Func<object>>(expression.Box()).Compile()());
			} catch(Exception e) {
				return EvaluationResult.Failure(expression, e);
			}
		}
开发者ID:drunkcod,项目名称:Cone,代码行数:7,代码来源:ExpressionEvaluator.cs


示例15: BuildExpression

			public override Expression BuildExpression(Expression expression, int level)
			{
				var expr = Sequence.BuildExpression(expression, level);

				if (expression == null)
				{
					var q =
						from col in SqlQuery.Select.Columns
						where !col.CanBeNull()
						select SqlQuery.Select.Columns.IndexOf(col);

					var idx = q.DefaultIfEmpty(-1).First();

					if (idx == -1)
						idx = SqlQuery.Select.Add(new SqlValue((int?) 1));

					var n = ConvertToParentIndex(idx, this);

					var e = Expression.Call(
						ExpressionBuilder.DataReaderParam,
						ReflectionHelper.DataReader.IsDBNull,
						Expression.Constant(n)) as Expression;

					var defaultValue = _defaultValue ?? Expression.Constant(null, expr.Type);

					expr = Expression.Condition(e, defaultValue, expr);
				}

				return expr;
			}
开发者ID:x64,项目名称:bltoolkit,代码行数:30,代码来源:DefaultIfEmptyBuilder.cs


示例16: CreateCopyComplexArrayTypeFieldExpression

 /// <summary>
 /// Creates an expression that copies a coplex array value from the source to the target. The value will be cloned as well using the dictionary to reuse already cloned objects.
 /// </summary>
 /// <param name="sourceField"></param>
 /// <param name="targetField"></param>
 /// <param name="type"></param>
 /// <param name="objectDictionary"></param>
 /// <returns></returns>
 internal static Expression CreateCopyComplexArrayTypeFieldExpression(Expression sourceField, Expression targetField, Type type, ParameterExpression objectDictionary) {
     return Expression.IfThenElse(
         Expression.Call(objectDictionary, _dictionaryContainsKey, sourceField),
         Expression.Assign(targetField, Expression.Convert(Expression.Call(objectDictionary, _dictionaryGetItem, sourceField), type)),
         Expression.Assign(targetField, Expression.Convert(Expression.Call(Expression.Call(_getTypeClonerMethodInfo, Expression.Call(sourceField, _getTypeMethodInfo)), _invokeMethodInfo, sourceField, objectDictionary), type))
         );
 }
开发者ID:geffzhang,项目名称:Foundatio,代码行数:15,代码来源:CloneExpressionHelper.cs


示例17: Parse

        public static void Parse(SortedSet<string> list, Expression expr)
        {
            if (expr == null)
                return;

            BinaryExpression eb = expr as BinaryExpression;
            MemberExpression em = expr as MemberExpression;
            UnaryExpression eu = expr as UnaryExpression;
            MethodCallExpression ec = expr as MethodCallExpression;


            if (em != null) // member expression
            {
                list.Add(em.Member.Name);
            }
            else if (eb != null) // binary expression
            {
                Parse(list, eb.Left);
                Parse(list, eb.Right);
            }
            else if (eu != null) // unary expression
            {
                Parse(list, eu.Operand);
            }
            else if (ec != null) // call expression
            {
                foreach (var a in ec.Arguments)
                    Parse(list, a);
            }


            return;
        }
开发者ID:accord-net,项目名称:framework,代码行数:33,代码来源:ExpressionParser.cs


示例18: PropertyToElementInit

 static ElementInit PropertyToElementInit(PropertyInfo propertyInfo, Expression instance)
 {
     return Expression.ElementInit(DictionaryAddMethod,
                                   Expression.Constant(propertyInfo.Name),
                                   Expression.Call(ToStringOrNullMethod,
                                                   Expression.Convert(Expression.Property(instance, propertyInfo), typeof(object))));
 }
开发者ID:muratbeyaztas,项目名称:Simple.Web,代码行数:7,代码来源:ObjectEx.cs


示例19: Output

        void Output(Expression<Func<ContentItem, bool>> expr)
        {
            Debug.WriteLine("expr: " + expr);
            Debug.WriteLine(expr.Body);
            Debug.WriteLine(expr.Parameters[0]);

            var mce = expr.Body as MethodCallExpression;
            Debug.WriteLine("mce: " + mce);
            Debug.WriteLine(mce.Arguments.Count);
            Debug.WriteLine(mce.Arguments[0]);
            Debug.WriteLine(mce.Method);
            Debug.WriteLine(mce.Object);

            var mce2 = mce.Arguments[0] as MethodCallExpression;
            Debug.WriteLine("mce2: " + mce2);
            Debug.WriteLine(mce2.Arguments.Count);
            Debug.WriteLine(mce2.Arguments[0]);
            Debug.WriteLine(mce2.Method);
            Debug.WriteLine(mce2.Object);

            var me = mce2.Arguments[0] as MemberExpression;
            Debug.WriteLine("me: " + me);
            Debug.WriteLine(me.Expression);
            Debug.WriteLine(me.Member);

            var me2 = me.Expression as MemberExpression;
            Debug.WriteLine("me2: " + me2);
            Debug.WriteLine(me2.Expression);
            Debug.WriteLine(me2.Member);

            var pe = me2.Expression as ParameterExpression;
            Debug.WriteLine("pe: " + pe);
            Debug.WriteLine(pe.Name);
            Debug.WriteLine(pe.Type);
        }
开发者ID:Biswo,项目名称:n2cms,代码行数:35,代码来源:ExpressionBuildingUtils.cs


示例20: ForCSharpStatement

 internal ForCSharpStatement(ReadOnlyCollection<ParameterExpression> variables, ReadOnlyCollection<Expression> initializers, Expression test, ReadOnlyCollection<Expression> iterators, Expression body, LabelTarget breakLabel, LabelTarget continueLabel)
     : base(test, body, breakLabel, continueLabel)
 {
     Variables = variables;
     Initializers = initializers;
     Iterators = iterators;
 }
开发者ID:taolin123,项目名称:ExpressionFutures,代码行数:7,代码来源:ForCSharpStatement.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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