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


C# Expression.MaybeAs方法代碼示例

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


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

示例1: Evaluate

		public static Maybe<object> Evaluate(Expression argument)
		{
			var value = argument.MaybeAs<ConstantExpression>().Select(x => x.Value)
				.OrElse(() =>
				        from memberExpression in argument.MaybeAs<MemberExpression>()
				        from @object in memberExpression.Expression.MaybeAs<ConstantExpression>(nullMeansNothing: false)
				        from computedValue in
					        memberExpression.Member.MaybeAs<PropertyInfo>().Select(x => x.GetValue(@object.Value, null))
					        .OrElse(() => memberExpression.Member.MaybeAs<FieldInfo>().Select(x => x.GetValue(@object.Value)))
				        select computedValue
				);
			return value;
		}
開發者ID:lakshithagit,項目名稱:Target-Process-Plugins,代碼行數:13,代碼來源:Evaluator.cs

示例2: SimpleEval

		public static Maybe<object> SimpleEval(Expression lambdaContainer)
		{
			Maybe<object> lambda = from methodCallExpression in lambdaContainer.MaybeAs<MethodCallExpression>()
			                       from @object in methodCallExpression.Object.MaybeAs<ConstantExpression>(nullMeansNothing: false)
			                       from parameters in GetParameters(methodCallExpression)
			                       from lambdaExpression in Maybe.Just(methodCallExpression.Method.Invoke(@object == null ? null : @object.Value, parameters.ToArray()))
			                       select lambdaExpression;

			Maybe<object> maybe = lambda.OrElse(() => Evaluate(lambdaContainer));
			return maybe;
		}
開發者ID:lakshithagit,項目名稱:Target-Process-Plugins,代碼行數:11,代碼來源:Evaluator.cs

示例3: GetMethodName

		private static Maybe<string> GetMethodName(Expression expr)
		{
			return expr.MaybeAs<MethodCallExpression>().Bind(
				call =>
				{
					if (call.Arguments.Count == 0 || (call.Method.IsExtensionMethod() && call.Arguments.Count == 1))
					{
						return Maybe.Just(call.Method.Name);
					}
					return Maybe.Nothing;
				}
				);
		}
開發者ID:TargetProcess,項目名稱:Target-Process-Plugins,代碼行數:13,代碼來源:ExpressionParser.cs

示例4: GetConditionName

		// special case for protected nullable properties
		// for x==null?null:(Nullable<T>)Expr(x) returns name of Expr(x)
		private Maybe<string> GetConditionName(Expression expr, int exprPos)
		{
			return expr.MaybeAs<ConditionalExpression>()
				.Bind(conditional => ExtensionsProvider.GetValue<Expression>(conditional)
					.Bind(x => GetPropertyName(x, exprPos)));
		}
開發者ID:TargetProcess,項目名稱:Target-Process-Plugins,代碼行數:8,代碼來源:ExpressionParser.cs

示例5: GetEnumerableRootName

		// find the root of Enumerable chains and get it name
		// userstories.Where(x).select(y)=>'userstories'
		private Maybe<string> GetEnumerableRootName(Expression expr, int exprPos)
		{
			return expr.MaybeAs<MethodCallExpression>()
				.Where(x => x.Method.DeclaringType == typeof(Enumerable))
				.Where(x => !AggregationMethodNames.Contains(x.Method.Name))
				.Select(x => x.Arguments.First())
				.Bind(x => GetPropertyName(x, exprPos));
		}
開發者ID:TargetProcess,項目名稱:Target-Process-Plugins,代碼行數:10,代碼來源:ExpressionParser.cs

示例6: GetPropertyName

		private Maybe<string> GetPropertyName(Expression expr, int exprPos)
		{
			var maybePropName = expr
				.MaybeAs<MemberExpression>().Select(x => x.Member.Name)
				.OrElse(() => DynamicDictionary.GetAlias(expr, exprPos))
				.OrElse(() => GetConditionName(expr, exprPos))
				.OrElse(() => GetEnumerableRootName(expr, exprPos))
				.OrElse(() => GetMethodName(expr));

			return maybePropName;
		}
開發者ID:TargetProcess,項目名稱:Target-Process-Plugins,代碼行數:11,代碼來源:ExpressionParser.cs


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