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


C# Expression.ElementType方法代码示例

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


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

示例1: SelectResourceByKey

 private static Expression SelectResourceByKey(Expression queryExpression, ResourceType resourceType, KeyInstance key)
 {
     for (int i = 0; i < resourceType.KeyProperties.Count; i++)
     {
         Expression expression2;
         ResourceProperty property = resourceType.KeyProperties[i];
         object obj2 = key.AreValuesNamed ? key.NamedValues[property.Name] : key.PositionalValues[i];
         ParameterExpression expression = Expression.Parameter(queryExpression.ElementType(), "element");
         if (property.CanReflectOnInstanceTypeProperty)
         {
             expression2 = Expression.Property(expression, property.Name);
         }
         else
         {
             expression2 = Expression.Convert(Expression.Call(null, DataServiceProviderMethods.GetValueMethodInfo, expression, Expression.Constant(property)), property.Type);
         }
         LambdaExpression predicate = Expression.Lambda(Expression.Equal(expression2, Expression.Constant(obj2)), new ParameterExpression[] { expression });
         queryExpression = queryExpression.QueryableWhere(predicate);
     }
     return queryExpression;
 }
开发者ID:nickchal,项目名称:pash,代码行数:21,代码来源:RequestUriProcessor.cs

示例2: SelectMultiple

 private static Expression SelectMultiple(Expression queryExpression, ResourceProperty property)
 {
     Type iEnumerableElement = BaseServiceProvider.GetIEnumerableElement(property.Type);
     ParameterExpression expression = Expression.Parameter(queryExpression.ElementType(), "element");
     LambdaExpression selector = Expression.Lambda(Expression.ConvertChecked(Expression.Property(expression, property.Name), typeof(IEnumerable<>).MakeGenericType(new Type[] { iEnumerableElement })), new ParameterExpression[] { expression });
     return queryExpression.QueryableSelectMany(selector);
 }
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:RequestUriProcessor.cs

示例3: SelectOpenProperty

 private static Expression SelectOpenProperty(Expression queryExpression, string propertyName)
 {
     ParameterExpression expression = Expression.Parameter(queryExpression.ElementType(), "element");
     LambdaExpression selector = Expression.Lambda(Expression.Call(null, OpenTypeMethods.GetValueOpenPropertyMethodInfo, expression, Expression.Constant(propertyName)), new ParameterExpression[] { expression });
     return queryExpression.QueryableSelect(selector);
 }
开发者ID:nickchal,项目名称:pash,代码行数:6,代码来源:RequestUriProcessor.cs

示例4: SelectLateBoundProperty

 private static Expression SelectLateBoundProperty(Expression queryExpression, ResourceProperty property)
 {
     ParameterExpression expression = Expression.Parameter(queryExpression.ElementType(), "element");
     LambdaExpression selector = Expression.Lambda(Expression.Convert(Expression.Call(null, DataServiceProviderMethods.GetValueMethodInfo, expression, Expression.Constant(property)), property.Type), new ParameterExpression[] { expression });
     return queryExpression.QueryableSelect(selector);
 }
开发者ID:nickchal,项目名称:pash,代码行数:6,代码来源:RequestUriProcessor.cs

示例5: SelectLateBoundPropertyMultiple

 private static Expression SelectLateBoundPropertyMultiple(Expression queryExpression, ResourceProperty property)
 {
     Type iEnumerableElement = BaseServiceProvider.GetIEnumerableElement(property.Type);
     ParameterExpression expression = Expression.Parameter(queryExpression.ElementType(), "element");
     MethodInfo method = DataServiceProviderMethods.GetSequenceValueMethodInfo.MakeGenericMethod(new Type[] { iEnumerableElement });
     LambdaExpression selector = Expression.Lambda(Expression.Call(null, method, expression, Expression.Constant(property)), new ParameterExpression[] { expression });
     return queryExpression.QueryableSelectMany(selector);
 }
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:RequestUriProcessor.cs

示例6: SelectDerivedResourceType

 private static Expression SelectDerivedResourceType(Expression queryExpression, ResourceType resourceType)
 {
     if (resourceType.CanReflectOnInstanceType)
     {
         return queryExpression.QueryableOfType(resourceType.InstanceType);
     }
     Type type = queryExpression.ElementType();
     ConstantExpression expression = Expression.Constant(resourceType, typeof(ResourceType));
     return Expression.Call(null, DataServiceExecutionProviderMethods.OfTypeMethodInfo.MakeGenericMethod(new Type[] { type, resourceType.InstanceType }), queryExpression, expression);
 }
开发者ID:nickchal,项目名称:pash,代码行数:10,代码来源:RequestUriProcessor.cs

示例7: SelectElement

 private static Expression SelectElement(Expression queryExpression, ResourceProperty property)
 {
     ParameterExpression expression = Expression.Parameter(queryExpression.ElementType(), "element");
     Expression expression2 = Expression.Property(expression, property.Name);
     if ((property.TypeKind == ResourceTypeKind.Collection) && (expression2.Type != property.Type))
     {
         expression2 = Expression.Convert(expression2, property.Type);
     }
     LambdaExpression selector = Expression.Lambda(expression2, new ParameterExpression[] { expression });
     return queryExpression.QueryableSelect(selector);
 }
开发者ID:nickchal,项目名称:pash,代码行数:11,代码来源:RequestUriProcessor.cs

示例8: SelectResourceByKey

        /// <summary>Selects a single resource by key values.</summary>
        /// <param name="queryExpression">Base query for resources</param>
        /// <param name="resourceType">resource type whose keys are specified</param>
        /// <param name="key">Key values for the given resource type.</param>
        /// <returns>A new query that selects the single resource that matches the specified key values.</returns>
        private static Expression SelectResourceByKey(Expression queryExpression, ResourceType resourceType, KeySegment key)
        {
            Debug.Assert(queryExpression != null, "queryExpression != null");
            Debug.Assert(key != null, "key != null");
            
            List<KeyValuePair<string, object>> keyValues = key.Keys.ToList();
            Debug.Assert(keyValues.Count != 0, "keyValues.Count != 0");
            Debug.Assert(resourceType.KeyProperties.Count == keyValues.Count, "resourceType.KeyProperties.Count == keyValues.Count");

            for (int i = 0; i < resourceType.KeyProperties.Count; i++)
            {
                ResourceProperty keyProperty = resourceType.KeyProperties[i];
                Debug.Assert(keyProperty.IsOfKind(ResourcePropertyKind.Key), "keyProperty.IsOfKind(ResourcePropertyKind.Key)");

                object keyValue;
                if (keyValues.Count == 0)
                {
                    keyValue = keyValues[0].Value;
                }
                else
                {
                    keyValue = keyValues.Single(v => v.Key == keyProperty.Name).Value;    
                }
                
                var binaryValue = keyValue as byte[];
                if (binaryValue != null && keyProperty.Type == typeof(System.Data.Linq.Binary))
                {
                    keyValue = new System.Data.Linq.Binary(binaryValue);
                }

                var stringValue = keyValue as string;
                if (stringValue != null && keyProperty.Type == typeof(XElement))
                {
                    keyValue = XElement.Parse(stringValue);
                }

                if (keyProperty.Type == typeof(DateTime))
                {
                    Debug.Assert(keyValue != null && keyValue is DateTimeOffset, "For DateTime properties, the value must be read as DateTimeOffset");
                    keyValue = WebUtil.ConvertDateTimeOffsetToDateTime((DateTimeOffset)keyValue);
                }

                ParameterExpression parameter = Expression.Parameter(queryExpression.ElementType(), "element");
                Expression e;
                if (keyProperty.CanReflectOnInstanceTypeProperty)
                {
                    e = Expression.Property(parameter, keyProperty.Name);
                }
                else
                {
                    e = Expression.Call(null /*instance*/, DataServiceProviderMethods.GetValueMethodInfo, parameter, Expression.Constant(keyProperty));
                    e = Expression.Convert(e, keyProperty.Type);
                }

                BinaryExpression body = Expression.Equal(e, Expression.Constant(keyValue));
                LambdaExpression predicate = Expression.Lambda(body, parameter);
                queryExpression = queryExpression.QueryableWhere(predicate);
            }

            return queryExpression;
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:66,代码来源:RequestUriProcessor.cs

示例9: Where

        /// <summary>Filters a query like a SQL WHERE clause does.</summary>
        /// <param name="service">Service with data and configuration.</param>
        /// <param name="requestDescription">RequestDescription instance containing information about the current request being parsed.</param>
        /// <param name="source">Original source for query expression.</param>
        /// <returns>The composed query expression.</returns>
        internal static Expression Where(IDataService service, RequestDescription requestDescription, Expression source)
        {
            Debug.Assert(service != null, "service != null");
            Debug.Assert(source != null, "source != null");
            Debug.Assert(requestDescription != null, "requestDescription != null");

            FilterClause filterClause = new RequestExpressionParser(service, requestDescription).ParseFilter();

            if (filterClause == null)
            {
                return source;
            }

            bool filterQueryApplicable = requestDescription.TargetKind == RequestTargetKind.Resource
                                         || requestDescription.TargetKind == RequestTargetKind.OpenProperty
                                         || requestDescription.TargetKind == RequestTargetKind.ComplexObject
                                         || requestDescription.CountOption == RequestQueryCountOption.CountSegment;

            if (!filterQueryApplicable)
            {
                throw DataServiceException.CreateBadRequestError(Strings.RequestQueryProcessor_QueryFilterOptionNotApplicable);
            }

            Type queryElementType = source.ElementType();
            Debug.Assert(queryElementType != null, "queryElementType != null");

            ParameterExpression parameterForIt = Expression.Parameter(queryElementType, "it");
            Debug.Assert(
                (requestDescription.TargetResourceSet == null && (requestDescription.TargetResourceType == null || requestDescription.TargetResourceType.ResourceTypeKind != ResourceTypeKind.EntityType)) ||
                (requestDescription.TargetResourceType != null && requestDescription.TargetResourceType.ResourceTypeKind == ResourceTypeKind.EntityType),
                "setForIt cannot be null if typeForIt is an entity type.");
            Debug.Assert(
                requestDescription.TargetResourceType == null && parameterForIt.Type == typeof(object) ||
                requestDescription.TargetResourceType != null && requestDescription.TargetResourceType.InstanceType == parameterForIt.Type,
                "non-open type expressions should have a typeForIt");

            var translator = NodeToExpressionTranslator.Create(service, requestDescription, parameterForIt);
            LambdaExpression lambda = translator.TranslateFilterClause(filterClause);
            return source.QueryableWhere(lambda);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:45,代码来源:RequestQueryParser.cs

示例10: SelectLateBoundPropertyMultiple

        private static Expression SelectLateBoundPropertyMultiple(Expression queryExpression, ResourceProperty property)
        {
            Debug.Assert(queryExpression != null, "queryExpression != null");
            Debug.Assert(property != null && property.Kind == ResourcePropertyKind.ResourceSetReference && !property.CanReflectOnInstanceTypeProperty, "property != null && property.Kind == ResourcePropertyKind.ResourceSetReference && !property.CanReflectOnInstanceTypeProperty");

            Type enumerableElement = BaseServiceProvider.GetIEnumerableElement(property.Type);
            ParameterExpression parameter = Expression.Parameter(queryExpression.ElementType(), "element");
            MethodInfo getter = DataServiceProviderMethods.GetSequenceValueMethodInfo.MakeGenericMethod(enumerableElement);
            Expression body = Expression.Call(null /*instance*/, getter, parameter, Expression.Constant(property));
            LambdaExpression selector = Expression.Lambda(body, parameter);
            return queryExpression.QueryableSelectMany(selector);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:12,代码来源:RequestUriProcessor.cs

示例11: SelectLateBoundProperty

        private static Expression SelectLateBoundProperty(Expression queryExpression, ResourceProperty property)
        {
            Debug.Assert(queryExpression != null, "queryExpression != null");
            Debug.Assert(property != null && !property.CanReflectOnInstanceTypeProperty, "property != null && !property.CanReflectOnInstanceTypeProperty");

            ParameterExpression parameter = Expression.Parameter(queryExpression.ElementType(), "element");
            Expression body = Expression.Call(null /*instance*/, DataServiceProviderMethods.GetValueMethodInfo, parameter, Expression.Constant(property));
            body = Expression.Convert(body, property.Type);
            LambdaExpression selector = Expression.Lambda(body, parameter);
            return queryExpression.QueryableSelect(selector);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:11,代码来源:RequestUriProcessor.cs

示例12: SelectOpenProperty

        private static Expression SelectOpenProperty(Expression queryExpression, string propertyName)
        {
            Debug.Assert(queryExpression != null, "queryExpression != null");
            Debug.Assert(propertyName != null, "propertyName != null");

            ParameterExpression parameter = Expression.Parameter(queryExpression.ElementType(), "element");
            Expression body = Expression.Call(null /* instance */, OpenTypeMethods.GetValueOpenPropertyMethodInfo, parameter, Expression.Constant(propertyName));
            LambdaExpression selector = Expression.Lambda(body, parameter);
            return queryExpression.QueryableSelect(selector);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:10,代码来源:RequestUriProcessor.cs

示例13: SelectMultiple

        private static Expression SelectMultiple(Expression queryExpression, ResourceProperty property)
        {
            Debug.Assert(queryExpression != null, "queryExpression != null");
            Debug.Assert(property.Kind == ResourcePropertyKind.ResourceSetReference, "property == ResourcePropertyKind.ResourceSetReference");

            Type enumerableElement = BaseServiceProvider.GetIEnumerableElement(property.Type);
            Debug.Assert(enumerableElement != null, "Providers should never expose a property as a resource-set if it doesn't implement IEnumerable`1.");

            ParameterExpression parameter = Expression.Parameter(queryExpression.ElementType(), "element");
            UnaryExpression body =
                Expression.ConvertChecked(
                    Expression.Property(parameter, property.Name),
                    typeof(IEnumerable<>).MakeGenericType(enumerableElement));
            LambdaExpression selector = Expression.Lambda(body, parameter);
            return queryExpression.QueryableSelectMany(selector);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:16,代码来源:RequestUriProcessor.cs

示例14: SelectElement

        private static Expression SelectElement(Expression queryExpression, ResourceProperty property)
        {
            Debug.Assert(queryExpression != null, "queryExpression != null");
            Debug.Assert(property.Kind != ResourcePropertyKind.ResourceSetReference, "property != ResourcePropertyKind.ResourceSetReference");

            ParameterExpression parameter = Expression.Parameter(queryExpression.ElementType(), "element");
            Expression body = Expression.Property(parameter, property.Name);

            // If the property is a collection its instance type is always IEnumerable<T>, but the actual type of the property
            //   might be type a type implementing the IEnumerable<T> (Like List<T>). We need to add an explicit cast here
            //   so that our expression types match and we will be able to call the lambda later.
            if (property.TypeKind == ResourceTypeKind.Collection && body.Type != property.Type)
            {
                body = Expression.Convert(body, property.Type);
            }

            LambdaExpression selector = Expression.Lambda(body, parameter);
            return queryExpression.QueryableSelect(selector);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:19,代码来源:RequestUriProcessor.cs


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