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


C# Expression.Find方法代码示例

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


在下文中一共展示了Expression.Find方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanBeCompiled

		bool CanBeCompiled(Expression expr)
		{
			return null == expr.Find(ex =>
			{
				if (IsServerSideOnly(ex))
					return true;

				switch (ex.NodeType)
				{
					case ExpressionType.Parameter :
						return ex != ParametersParam;

					case ExpressionType.MemberAccess :
						{
							var attr = GetFunctionAttribute(((MemberExpression)ex).Member);
							return attr != null && attr.ServerSideOnly;
						}

					case ExpressionType.Call :
						{
							var attr = GetFunctionAttribute(((MethodCallExpression)ex).Method);
							return attr != null && attr.ServerSideOnly;
						}
				}

				return false;
			});
		}
开发者ID:Firebie,项目名称:ItemsUsage,代码行数:28,代码来源:ExpressionParser.Parsing.cs

示例2: CanBeConstant

		bool CanBeConstant(Expression expr)
		{
			return null == expr.Find(ex =>
			{
				if (ex is BinaryExpression || ex is UnaryExpression || ex.NodeType == ExpressionType.Convert)
					return false;

				switch (ex.NodeType)
				{
					case ExpressionType.Constant:
						{
							var c = (ConstantExpression)ex;

							if (c.Value == null || ExpressionHelper.IsConstant(ex.Type))
								return false;

							break;
						}

					case ExpressionType.MemberAccess:
						{
							var ma = (MemberExpression)ex;

							if (ExpressionHelper.IsConstant(ma.Member.DeclaringType) || TypeHelper.IsNullableValueMember(ma.Member))
								return false;

							break;
						}

					case ExpressionType.Call:
						{
							var mc = (MethodCallExpression)ex;

							if (ExpressionHelper.IsConstant(mc.Method.DeclaringType) || mc.Method.DeclaringType == typeof(object))
								return false;

							var attr = GetFunctionAttribute(mc.Method);

							if (attr != null && !attr.ServerSideOnly)
								return false;

							break;
						}
				}

				return true;
			});
		}
开发者ID:Firebie,项目名称:ItemsUsage,代码行数:48,代码来源:ExpressionParser.Parsing.cs

示例3: CanBeTranslatedToSql

		bool CanBeTranslatedToSql(IParseContext context, Expression expr, bool canBeCompiled)
		{
			return null == expr.Find(pi =>
			{
				switch (pi.NodeType)
				{
					case ExpressionType.MemberAccess:
						{
							var ma = (MemberExpression)pi;
							var l  = ConvertMember(ma.Member);

							if (l != null)
								return !CanBeTranslatedToSql(context, l.Body.Unwrap(), canBeCompiled);

							var attr = GetFunctionAttribute(ma.Member);

							if (attr == null && !TypeHelper.IsNullableValueMember(ma.Member))
								goto case ExpressionType.Parameter;

							break;
						}

					case ExpressionType.Parameter:
						{
							if (canBeCompiled && GetContext(context, pi) == null)
								return !CanBeCompiled(pi);
							break;
						}

					case ExpressionType.Call:
						{
							var e = pi as MethodCallExpression;

							if (e.Method.DeclaringType != typeof(Enumerable))
							{
								var cm = ConvertMethod(e);

								if (cm != null)
									return !CanBeTranslatedToSql(context, cm, canBeCompiled);

								var attr = GetFunctionAttribute(e.Method);

								if (attr == null && canBeCompiled)
									return !CanBeCompiled(pi);
							}

							break;
						}

					case ExpressionType.New: return true;
				}

				return false;
			});
		}
开发者ID:Firebie,项目名称:ItemsUsage,代码行数:55,代码来源:ExpressionParser.Parsing.cs

示例4: CheckSubQueryForWhere

		bool CheckSubQueryForWhere(IParseContext context, Expression expression, out bool makeHaving)
		{
			//var checkParameter = true; //context.IsExpression(expression, 0, RequestFor.ScalarExpression);
			var makeSubQuery   = false;
			var isHaving       = false;
			var isWhere        = false;

			expression.Find(expr =>
			{
				if (IsSubQuery(context, expr))
					return isWhere = true;

				var stopWalking = false;

				switch (expr.NodeType)
				{
					case ExpressionType.MemberAccess:
						{
							var ma = (MemberExpression)expr;

							if (TypeHelper.IsNullableValueMember(ma.Member))
								break;

							if (ConvertMember(ma.Member) == null)
							{
								var ctx = GetContext(context, expr);

								if (ctx != null)
								{
									if (ctx.IsExpression(expr, 0, RequestFor.Expression))
										makeSubQuery = true;
									stopWalking = true;
								}
							}

							isWhere = true;

							break;
						}

					case ExpressionType.Call:
						{
							var e = (MethodCallExpression)expr;

							if (e.Method.DeclaringType == typeof(Enumerable) && e.Method.Name != "Contains")
								return isHaving = true;

							isWhere = true;

							break;
						}

					case ExpressionType.Parameter:
						{
							var ctx = GetContext(context, expr);

							if (ctx != null)
							{
								if (ctx.IsExpression(expr, 0, RequestFor.Expression))
									makeSubQuery = true;
								stopWalking = true;
							}

							isWhere = true;

							break;
						}
				}

				return stopWalking;
			});

			makeHaving = isHaving && !isWhere;
			return makeSubQuery || isHaving && isWhere;
		}
开发者ID:Firebie,项目名称:ItemsUsage,代码行数:75,代码来源:ExpressionParser.Parsing.cs

示例5: FindExpression

		static Expression FindExpression(Expression expr)
		{
			var ret = expr.Find(pi =>
			{
				switch (pi.NodeType)
				{
					case ExpressionType.Convert      :
						{
							var e = (UnaryExpression)expr;

							return
								e.Operand.NodeType == ExpressionType.ArrayIndex &&
								((BinaryExpression)e.Operand).Left == ParametersParam;
						}

					case ExpressionType.MemberAccess :
					case ExpressionType.New          :
						return true;
				}

				return false;
			});

			if (ret == null)
				throw new NotImplementedException();

			return ret;
		}
开发者ID:Firebie,项目名称:ItemsUsage,代码行数:28,代码来源:ExpressionParser.Parsing.cs


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