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


C# Expression.As方法代碼示例

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


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

示例1: ParseWhereFragment

        public IWhereFragment ParseWhereFragment(DocumentMapping mapping, Expression expression)
        {
            if (expression is BinaryExpression)
            {
                return GetWhereFragment(mapping, expression.As<BinaryExpression>());
            }

            if (expression.NodeType == ExpressionType.Call)
            {
                return GetMethodCall(mapping, expression.As<MethodCallExpression>());
            }

            if (expression is MemberExpression && expression.Type == typeof (bool))
            {
                var locator = JsonLocator(mapping, expression.As<MemberExpression>());
                return new WhereFragment("{0} = True".ToFormat(locator), true);
            }

            if (expression.NodeType == ExpressionType.Not)
            {
                return GetNotWhereFragment(mapping, expression.As<UnaryExpression>().Operand);
            }

            if (expression is SubQueryExpression)
            {
                return GetWhereFragment(mapping, expression.As<SubQueryExpression>());
            }

            throw new NotSupportedException();
        }
開發者ID:kiliman,項目名稱:marten,代碼行數:30,代碼來源:MartenExpressionParser.cs

示例2: ParseWhereFragment

        public static IWhereFragment ParseWhereFragment(Expression expression)
        {
            if (expression is BinaryExpression)
            {
                return GetWhereFragment(expression.As<BinaryExpression>());
            }

            if (expression.NodeType == ExpressionType.Call)
            {
                return GetMethodCall(expression.As<MethodCallExpression>());
            }

            throw new NotSupportedException();
        }
開發者ID:ahmedshuhel,項目名稱:Marten,代碼行數:14,代碼來源:MartenExpressionParser.cs

示例3: JsonLocator

        public static string JsonLocator(Type rootType, Expression expression)
        {
            if (expression is MemberExpression)
            {
                var memberExpression = expression.As<MemberExpression>();
                return JsonLocator(rootType, memberExpression);
            }

            if (expression is UnaryExpression)
            {
                return JsonLocator(rootType, expression.As<UnaryExpression>());
            }

            throw new NotSupportedException();
        }
開發者ID:alexandernyquist,項目名稱:Marten,代碼行數:15,代碼來源:MartenExpressionParser.cs

示例4: IsDynamicComponentDictionaryGetter

		public static bool IsDynamicComponentDictionaryGetter(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, ISessionFactory sessionFactory, out string memberName)
		{
			memberName = null;

			// A dynamic component must be an IDictionary with a string key.

			if (method.Name != "get_Item" || !typeof(IDictionary).IsAssignableFrom(targetObject.Type))
				return false;

			var key = arguments.First().As<ConstantExpression>();
			if (key == null || key.Type != typeof(string))
				return false;

			// The potential member name
			memberName = (string)key.Value;

			// Need the owning member (the dictionary).
			var member = targetObject.As<MemberExpression>();
			if (member == null)
				return false;

			var metaData = sessionFactory.GetClassMetadata(member.Expression.Type);
			if (metaData == null)
				return false;

			// IDictionary can be mapped as collection or component - is it mapped as a component?
			var propertyType = metaData.GetPropertyType(member.Member.Name);
			return (propertyType != null && propertyType.IsComponentType);
		}
開發者ID:rancomarcus,項目名稱:nhibernate-core,代碼行數:29,代碼來源:VisitorUtil.cs

示例5: Value

        public static object Value(Expression expression)
        {
            if (expression is ConstantExpression)
            {
                // TODO -- handle nulls
                // TODO -- check out more types here.
                return expression.As<ConstantExpression>().Value;
            }

            throw new NotSupportedException();
        }
開發者ID:bojanv91,項目名稱:Marten,代碼行數:11,代碼來源:MartenExpressionParser.cs

示例6: JsonLocator

        public static string JsonLocator(Expression expression)
        {
            if (expression is MemberExpression)
            {
                var member = expression.As<MemberExpression>().Member;

                var locator = "data ->> '{0}'".ToFormat(member.Name);
                var memberType = member.GetMemberType();

                return memberType == typeof (string) ? locator : locator.ApplyCastToLocator(memberType);
            }

            throw new NotSupportedException();
        }
開發者ID:ahmedshuhel,項目名稱:Marten,代碼行數:14,代碼來源:MartenExpressionParser.cs

示例7: ParseWhereFragment

        public IWhereFragment ParseWhereFragment(IQueryableDocument mapping, Expression expression)
        {
            if (expression is LambdaExpression)
            {
                expression = expression.As<LambdaExpression>().Body;
            }

            var visitor = new WhereClauseVisitor(this, mapping);
            visitor.Visit(expression);
            var whereFragment = visitor.ToWhereFragment();

            if (whereFragment == null)
            {
                throw new NotSupportedException("Marten does not (yet) support this Linq query type");
            }

            return whereFragment;
        }
開發者ID:JasperFx,項目名稱:marten,代碼行數:18,代碼來源:MartenExpressionParser.cs

示例8: GetNotWhereFragment

        private static IWhereFragment GetNotWhereFragment(Type rootType, Expression expression)
        {
            if (expression is MemberExpression && expression.Type == typeof(bool))
            {
                var locator = JsonLocator(rootType, expression.As<MemberExpression>());
                return new WhereFragment("({0})::Boolean = False".ToFormat(locator));
            }

            throw new NotSupportedException();
        }
開發者ID:alexandernyquist,項目名稱:Marten,代碼行數:10,代碼來源:MartenExpressionParser.cs

示例9: ParseWhereFragment

        public static IWhereFragment ParseWhereFragment(Type rootType, Expression expression)
        {
            if (expression is BinaryExpression)
            {
                return GetWhereFragment(rootType, expression.As<BinaryExpression>());
            }

            if (expression.NodeType == ExpressionType.Call)
            {
                return GetMethodCall(rootType, expression.As<MethodCallExpression>());
            }

            if (expression is MemberExpression && expression.Type == typeof(bool))
            {
                var locator = JsonLocator(rootType, expression.As<MemberExpression>());
                return new WhereFragment("({0})::Boolean = True".ToFormat(locator), true);
            }

            if (expression.NodeType == ExpressionType.Not)
            {
                return GetNotWhereFragment(rootType, expression.As<UnaryExpression>().Operand);
            }

            throw new NotSupportedException();
        }
開發者ID:alexandernyquist,項目名稱:Marten,代碼行數:25,代碼來源:MartenExpressionParser.cs

示例10: GetNotWhereFragment

        private IWhereFragment GetNotWhereFragment(DocumentMapping mapping, Expression expression)
        {
            if (expression is MemberExpression && expression.Type == typeof (bool))
            {
                var locator = JsonLocator(mapping, expression.As<MemberExpression>());
                return new WhereFragment("({0})::Boolean = False".ToFormat(locator));
            }

            if (expression.Type == typeof (bool) && expression.NodeType == ExpressionType.NotEqual &&
                expression is BinaryExpression)
            {
                var binaryExpression = expression.As<BinaryExpression>();
                var locator = JsonLocator(mapping, binaryExpression.Left);
                if (binaryExpression.Right.NodeType == ExpressionType.Constant &&
                    binaryExpression.Right.As<ConstantExpression>().Value == null)
                {
                    return new WhereFragment($"({locator})::Boolean IS NULL");
                }
            }

            throw new NotSupportedException();
        }
開發者ID:bojanv91,項目名稱:Marten,代碼行數:22,代碼來源:MartenExpressionParser.cs

示例11: TransformToJsonNode

 public TransformToJsonNode(MethodCallExpressionParseInfo parseInfo, Expression transform, Expression optionalSelector) : base(parseInfo, transform as LambdaExpression, optionalSelector as LambdaExpression)
 {
     var name = transform.As<ConstantExpression>().Value.As<string>();
     _operator = new TransformToJsonResultOperator(name);
 }
開發者ID:danielmarbach,項目名稱:marten,代碼行數:5,代碼來源:TransformToJsonNode.cs

示例12: Value

        public static object Value(Expression expression)
        {
            if (expression is PartialEvaluationExceptionExpression)
            {
                var partialEvaluationExceptionExpression = expression.As<PartialEvaluationExceptionExpression>();
                var inner = partialEvaluationExceptionExpression.Exception;

                throw new BadLinqExpressionException($"Error in value expression inside of the query for '{partialEvaluationExceptionExpression.EvaluatedExpression}'. See the inner exception:", inner);
            }

            if (expression is ConstantExpression)
            {
                // TODO -- handle nulls
                // TODO -- check out more types here.
                return expression.As<ConstantExpression>().Value;
            }

            throw new NotSupportedException();
        }
開發者ID:brianstanforth,項目名稱:marten,代碼行數:19,代碼來源:MartenExpressionParser.cs


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