当前位置: 首页>>代码示例>>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;未经允许,请勿转载。