diff --git a/src/Microsoft.AspNet.OData.Shared/Builder/EdmModelHelperMethods.cs b/src/Microsoft.AspNet.OData.Shared/Builder/EdmModelHelperMethods.cs index 6c25711292..7177cc1546 100644 --- a/src/Microsoft.AspNet.OData.Shared/Builder/EdmModelHelperMethods.cs +++ b/src/Microsoft.AspNet.OData.Shared/Builder/EdmModelHelperMethods.cs @@ -185,12 +185,12 @@ private static string ConvertBindingPath(EdmTypeMap edmMap, NavigationPropertyBi } else if (propertyInfo != null) { - PropertyDescriptor propDescr = new PropertyDescriptor(propertyInfo); + MemberDescriptor propDescr = new MemberDescriptor(propertyInfo); bindings.Add(edmMap.EdmProperties[propDescr].Name); } else if (methodInfo != null) { - PropertyDescriptor propDescr = new PropertyDescriptor(methodInfo); + MemberDescriptor propDescr = new MemberDescriptor(methodInfo); bindings.Add(edmMap.EdmProperties[propDescr].Name); } } @@ -431,7 +431,7 @@ private static Dictionary AddTypes(this EdmModel model, EdmTypeM model.AddClrTypeAnnotations(edmTypes); // add annotation for properties - Dictionary edmProperties = edmTypeMap.EdmProperties; + Dictionary edmProperties = edmTypeMap.EdmProperties; model.AddClrPropertyInfoAnnotations(edmProperties); model.AddPropertyRestrictionsAnnotations(edmTypeMap.EdmPropertiesRestrictions); model.AddPropertiesQuerySettings(edmTypeMap.EdmPropertiesQuerySettings); @@ -495,12 +495,12 @@ private static void AddClrTypeAnnotations(this EdmModel model, Dictionary edmProperties) + private static void AddClrPropertyInfoAnnotations(this EdmModel model, Dictionary edmProperties) { - foreach (KeyValuePair edmPropertyMap in edmProperties) + foreach (KeyValuePair edmPropertyMap in edmProperties) { IEdmProperty edmProperty = edmPropertyMap.Value; - PropertyDescriptor clrProperty = edmPropertyMap.Key; + MemberDescriptor clrProperty = edmPropertyMap.Key; if (clrProperty.MethodInfo != null || edmProperty.Name != clrProperty.Name) { model.SetAnnotationValue(edmProperty, new ClrPropertyInfoAnnotation(clrProperty)); diff --git a/src/Microsoft.AspNet.OData.Shared/Builder/EdmTypeBuilder.cs b/src/Microsoft.AspNet.OData.Shared/Builder/EdmTypeBuilder.cs index 982d65a1ed..091b2d64aa 100644 --- a/src/Microsoft.AspNet.OData.Shared/Builder/EdmTypeBuilder.cs +++ b/src/Microsoft.AspNet.OData.Shared/Builder/EdmTypeBuilder.cs @@ -22,7 +22,7 @@ internal class EdmTypeBuilder { private readonly List _configurations; private readonly Dictionary _types = new Dictionary(); - private readonly Dictionary _properties = new Dictionary(); + private readonly Dictionary _properties = new Dictionary(); private readonly Dictionary _propertiesRestrictions = new Dictionary(); private readonly Dictionary _propertiesQuerySettings = new Dictionary(); private readonly Dictionary _structuredTypeQuerySettings = new Dictionary(); @@ -433,7 +433,7 @@ private IList GetDeclaringPropertyInfo(IEnumerable GetDeclaringPropertyInfo(IEnumerable edmTypes, - Dictionary edmProperties, + Dictionary edmProperties, Dictionary edmPropertiesRestrictions, Dictionary edmPropertiesQuerySettings, Dictionary edmStructuredTypeQuerySettings, @@ -31,7 +31,7 @@ public EdmTypeMap( public Dictionary EdmTypes { get; private set; } - public Dictionary EdmProperties { get; private set; } + public Dictionary EdmProperties { get; private set; } public Dictionary EdmPropertiesRestrictions { get; private set; } diff --git a/src/Microsoft.AspNet.OData.Shared/Builder/PropertyDescriptor.cs b/src/Microsoft.AspNet.OData.Shared/Builder/MemberDescriptor.cs similarity index 66% rename from src/Microsoft.AspNet.OData.Shared/Builder/PropertyDescriptor.cs rename to src/Microsoft.AspNet.OData.Shared/Builder/MemberDescriptor.cs index 2efa5a7016..904e87d127 100644 --- a/src/Microsoft.AspNet.OData.Shared/Builder/PropertyDescriptor.cs +++ b/src/Microsoft.AspNet.OData.Shared/Builder/MemberDescriptor.cs @@ -1,44 +1,45 @@ -using Microsoft.AspNet.OData.Common; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + using System; using System.Collections.Generic; using System.Reflection; -using System.Text; +using Microsoft.AspNet.OData.Common; namespace Microsoft.AspNet.OData.Builder { /// - /// Property descriptor + /// Member descriptor /// - public class PropertyDescriptor + public class MemberDescriptor { - private readonly PropertyInfo _propertyInfo; - private readonly MethodInfo _methodInfo; + private readonly MemberInfo _memberInfo; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Property information - public PropertyDescriptor(PropertyInfo propertyInfo) + public MemberDescriptor(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } - this._propertyInfo = propertyInfo; + this._memberInfo = propertyInfo; } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - /// Extension property information - public PropertyDescriptor(MethodInfo methodInfo) + /// Extension method information + public MemberDescriptor(MethodInfo methodInfo) { - if(methodInfo==null) + if(methodInfo == null) { throw Error.ArgumentNull("methodInfo"); } - this._methodInfo = methodInfo; + this._memberInfo = methodInfo; } /// @@ -48,9 +49,7 @@ public MemberInfo MemberInfo { get { - if (_propertyInfo != null) - return _propertyInfo; - return _methodInfo; + return _memberInfo; } } @@ -61,7 +60,7 @@ public PropertyInfo PropertyInfo { get { - return _propertyInfo; + return _memberInfo as PropertyInfo; } } @@ -72,7 +71,7 @@ public MethodInfo MethodInfo { get { - return _methodInfo; + return _memberInfo as MethodInfo; } } @@ -94,9 +93,9 @@ public Type PropertyType { get { - if (_propertyInfo != null) - return _propertyInfo.PropertyType; - return _methodInfo.ReturnType; + if (PropertyInfo != null) + return PropertyInfo.PropertyType; + return MethodInfo.ReturnType; } } @@ -107,9 +106,9 @@ public Type DeclaringType { get { - if (_propertyInfo != null) - return _propertyInfo.DeclaringType; - return _methodInfo.GetParameters()[0].ParameterType; + if (PropertyInfo != null) + return PropertyInfo.DeclaringType; + return MethodInfo.GetParameters()[0].ParameterType; } } @@ -120,14 +119,14 @@ public Type ReflectedType { get { - if (_propertyInfo != null) - return TypeHelper.GetReflectedType(_propertyInfo); - return _methodInfo.GetParameters()[0].ParameterType; + if (PropertyInfo != null) + return TypeHelper.GetReflectedType(PropertyInfo); + return MethodInfo.GetParameters()[0].ParameterType; } } /// - public static implicit operator MemberInfo(PropertyDescriptor propertyDescriptor) + public static implicit operator MemberInfo(MemberDescriptor propertyDescriptor) { return propertyDescriptor.MemberInfo; } @@ -161,7 +160,7 @@ public override int GetHashCode() /// public override bool Equals(object obj) { - PropertyDescriptor propDescr = obj as PropertyDescriptor; + MemberDescriptor propDescr = obj as MemberDescriptor; if (propDescr == null) return false; diff --git a/src/Microsoft.AspNet.OData.Shared/Builder/NavigationPropertyConfiguration.cs b/src/Microsoft.AspNet.OData.Shared/Builder/NavigationPropertyConfiguration.cs index 4bea1a8f9f..47e13645d8 100644 --- a/src/Microsoft.AspNet.OData.Shared/Builder/NavigationPropertyConfiguration.cs +++ b/src/Microsoft.AspNet.OData.Shared/Builder/NavigationPropertyConfiguration.cs @@ -40,7 +40,7 @@ public NavigationPropertyConfiguration(PropertyInfo property, EdmMultiplicity mu /// The backing CLR property. /// The . /// The declaring structural type. - public NavigationPropertyConfiguration(PropertyDescriptor propertyDecriptor, EdmMultiplicity multiplicity, StructuralTypeConfiguration declaringType) + public NavigationPropertyConfiguration(MemberDescriptor propertyDecriptor, EdmMultiplicity multiplicity, StructuralTypeConfiguration declaringType) : base(propertyDecriptor, declaringType) { if (propertyDecriptor == null) @@ -65,13 +65,13 @@ public NavigationPropertyConfiguration(PropertyDescriptor propertyDecriptor, Edm OnDeleteAction = EdmOnDeleteAction.None; } - private static PropertyDescriptor CreatePropertyDescriptor(PropertyInfo property) + private static MemberDescriptor CreatePropertyDescriptor(PropertyInfo property) { if(property == null) { throw Error.ArgumentNull("property"); } - return new PropertyDescriptor(property); + return new MemberDescriptor(property); } /// @@ -219,8 +219,8 @@ public NavigationPropertyConfiguration HasConstraint(PropertyInfo dependentPrope /// /// The dependent property info for the referential constraint. /// The principal property info for the referential constraint. - public NavigationPropertyConfiguration HasConstraint(PropertyDescriptor dependentPropertyInfo, - PropertyDescriptor principalPropertyInfo) + public NavigationPropertyConfiguration HasConstraint(MemberDescriptor dependentPropertyInfo, + MemberDescriptor principalPropertyInfo) { return HasConstraint(dependentPropertyInfo.PropertyInfo, principalPropertyInfo.PropertyInfo); } diff --git a/src/Microsoft.AspNet.OData.Shared/Builder/PropertyConfiguration.cs b/src/Microsoft.AspNet.OData.Shared/Builder/PropertyConfiguration.cs index f519e100ce..11cbc67ec6 100644 --- a/src/Microsoft.AspNet.OData.Shared/Builder/PropertyConfiguration.cs +++ b/src/Microsoft.AspNet.OData.Shared/Builder/PropertyConfiguration.cs @@ -20,7 +20,7 @@ public abstract class PropertyConfiguration /// /// The name of the property. /// The declaring EDM type of the property. - protected PropertyConfiguration(PropertyDescriptor property, StructuralTypeConfiguration declaringType) + protected PropertyConfiguration(MemberDescriptor property, StructuralTypeConfiguration declaringType) { if (property == null) { @@ -67,7 +67,7 @@ public string Name /// /// Gets the mapping CLR . /// - public PropertyDescriptor PropertyInfo { get; private set; } + public MemberDescriptor PropertyInfo { get; private set; } /// /// Gets the CLR of the property. diff --git a/src/Microsoft.AspNet.OData.Shared/Builder/StructuralPropertyConfiguration.cs b/src/Microsoft.AspNet.OData.Shared/Builder/StructuralPropertyConfiguration.cs index 1eaf468cfd..142a638023 100644 --- a/src/Microsoft.AspNet.OData.Shared/Builder/StructuralPropertyConfiguration.cs +++ b/src/Microsoft.AspNet.OData.Shared/Builder/StructuralPropertyConfiguration.cs @@ -17,7 +17,7 @@ public abstract class StructuralPropertyConfiguration : PropertyConfiguration /// The property of the configuration. /// The declaring type of the property. protected StructuralPropertyConfiguration(PropertyInfo property, StructuralTypeConfiguration declaringType) - : base(new PropertyDescriptor(property), declaringType) + : base(new MemberDescriptor(property), declaringType) { OptionalProperty = EdmLibHelpers.IsNullable(property.PropertyType); } diff --git a/src/Microsoft.AspNet.OData.Shared/Builder/StructuralTypeConfiguration.cs b/src/Microsoft.AspNet.OData.Shared/Builder/StructuralTypeConfiguration.cs index cf5efa236e..ac38d6a60e 100644 --- a/src/Microsoft.AspNet.OData.Shared/Builder/StructuralTypeConfiguration.cs +++ b/src/Microsoft.AspNet.OData.Shared/Builder/StructuralTypeConfiguration.cs @@ -31,7 +31,7 @@ public abstract class StructuralTypeConfiguration : IEdmTypeConfiguration /// The default constructor is intended for use by unit testing only. protected StructuralTypeConfiguration() { - ExplicitProperties = new Dictionary(); + ExplicitProperties = new Dictionary(); RemovedProperties = new List(); QueryConfiguration = new QueryConfiguration(); } @@ -213,7 +213,7 @@ public virtual IEnumerable NavigationProperties /// /// Gets the collection of explicitly added properties. /// - protected internal IDictionary ExplicitProperties { get; private set; } + protected internal IDictionary ExplicitProperties { get; private set; } /// /// Gets the base type of this structural type. @@ -361,7 +361,7 @@ public virtual EnumPropertyConfiguration AddEnumProperty(PropertyInfo propertyIn return propertyConfiguration; } - internal ComplexPropertyConfiguration AddComplexProperty(PropertyDescriptor propertyDescriptor) + internal ComplexPropertyConfiguration AddComplexProperty(MemberDescriptor propertyDescriptor) { return AddComplexProperty(propertyDescriptor.PropertyInfo); } @@ -408,7 +408,7 @@ public virtual ComplexPropertyConfiguration AddComplexProperty(PropertyInfo prop return propertyConfiguration; } - internal CollectionPropertyConfiguration AddCollectionProperty(PropertyDescriptor propertyDescriptor) + internal CollectionPropertyConfiguration AddCollectionProperty(MemberDescriptor propertyDescriptor) { return AddCollectionProperty(propertyDescriptor.PropertyInfo); } @@ -502,7 +502,7 @@ public virtual void AddDynamicPropertyDictionary(PropertyInfo propertyInfo) /// Removes the given property. /// /// The property being removed. - public virtual void RemoveProperty(PropertyDescriptor propertyDescriptor) + public virtual void RemoveProperty(MemberDescriptor propertyDescriptor) { if (propertyDescriptor == null) { @@ -552,7 +552,7 @@ public virtual void RemoveProperty(PropertyInfo propertyInfo) /// Returns the of the added property. public virtual NavigationPropertyConfiguration AddNavigationProperty(PropertyInfo navigationProperty, EdmMultiplicity multiplicity) { - PropertyDescriptor propertyDescriptor = new PropertyDescriptor(navigationProperty); + MemberDescriptor propertyDescriptor = new MemberDescriptor(navigationProperty); return AddNavigationProperty(propertyDescriptor, multiplicity, containsTarget: false); } @@ -562,7 +562,7 @@ public virtual NavigationPropertyConfiguration AddNavigationProperty(PropertyInf /// The backing CLR property. /// The of the navigation property. /// Returns the of the added property. - public virtual NavigationPropertyConfiguration AddNavigationProperty(PropertyDescriptor navigationProperty, EdmMultiplicity multiplicity) + public virtual NavigationPropertyConfiguration AddNavigationProperty(MemberDescriptor navigationProperty, EdmMultiplicity multiplicity) { return AddNavigationProperty(navigationProperty, multiplicity, containsTarget: false); } @@ -575,7 +575,7 @@ public virtual NavigationPropertyConfiguration AddNavigationProperty(PropertyDes /// Returns the of the added property. public virtual NavigationPropertyConfiguration AddContainedNavigationProperty(PropertyInfo navigationProperty, EdmMultiplicity multiplicity) { - PropertyDescriptor propertyDescriptor = new PropertyDescriptor(navigationProperty); + MemberDescriptor propertyDescriptor = new MemberDescriptor(navigationProperty); return AddNavigationProperty(propertyDescriptor, multiplicity, containsTarget: true); } @@ -585,12 +585,12 @@ public virtual NavigationPropertyConfiguration AddContainedNavigationProperty(Pr /// The backing CLR property. /// The of the navigation property. /// Returns the of the added property. - public virtual NavigationPropertyConfiguration AddContainedNavigationProperty(PropertyDescriptor navigationProperty, EdmMultiplicity multiplicity) + public virtual NavigationPropertyConfiguration AddContainedNavigationProperty(MemberDescriptor navigationProperty, EdmMultiplicity multiplicity) { return AddNavigationProperty(navigationProperty, multiplicity, containsTarget: true); } - private NavigationPropertyConfiguration AddNavigationProperty(PropertyDescriptor navigationProperty, EdmMultiplicity multiplicity, bool containsTarget) + private NavigationPropertyConfiguration AddNavigationProperty(MemberDescriptor navigationProperty, EdmMultiplicity multiplicity, bool containsTarget) { if (navigationProperty == null) { diff --git a/src/Microsoft.AspNet.OData.Shared/Builder/StructuralTypeConfigurationOfTStructuralType.cs b/src/Microsoft.AspNet.OData.Shared/Builder/StructuralTypeConfigurationOfTStructuralType.cs index 034217be58..657b04d739 100644 --- a/src/Microsoft.AspNet.OData.Shared/Builder/StructuralTypeConfigurationOfTStructuralType.cs +++ b/src/Microsoft.AspNet.OData.Shared/Builder/StructuralTypeConfigurationOfTStructuralType.cs @@ -765,8 +765,8 @@ internal NavigationPropertyConfiguration GetOrCreateNavigationProperty(Expressio PropertyInfo pinfo = navigationProperty as PropertyInfo; MethodInfo minfo = navigationProperty as MethodInfo; - PropertyDescriptor propDescr = pinfo!=null ? new PropertyDescriptor(pinfo) - : new PropertyDescriptor(minfo); + MemberDescriptor propDescr = pinfo!=null ? new MemberDescriptor(pinfo) + : new MemberDescriptor(minfo); return _configuration.AddNavigationProperty(propDescr, multiplicity); } @@ -776,8 +776,8 @@ internal NavigationPropertyConfiguration GetOrCreateContainedNavigationProperty( PropertyInfo pinfo = navigationProperty as PropertyInfo; MethodInfo minfo = navigationProperty as MethodInfo; - PropertyDescriptor propDescr = pinfo != null ? new PropertyDescriptor(pinfo) - : new PropertyDescriptor(minfo); + MemberDescriptor propDescr = pinfo != null ? new MemberDescriptor(pinfo) + : new MemberDescriptor(minfo); return _configuration.AddContainedNavigationProperty(propDescr, multiplicity); } diff --git a/src/Microsoft.AspNet.OData.Shared/ClrPropertyInfoAnnotation.cs b/src/Microsoft.AspNet.OData.Shared/ClrPropertyInfoAnnotation.cs index 94fde282bc..e0bd8cc9ae 100644 --- a/src/Microsoft.AspNet.OData.Shared/ClrPropertyInfoAnnotation.cs +++ b/src/Microsoft.AspNet.OData.Shared/ClrPropertyInfoAnnotation.cs @@ -24,14 +24,14 @@ public ClrPropertyInfoAnnotation(PropertyInfo clrPropertyInfo) throw Error.ArgumentNull("clrPropertyInfo"); } - ClrPropertyInfo = new PropertyDescriptor(clrPropertyInfo); + ClrPropertyInfo = new MemberDescriptor(clrPropertyInfo); } /// /// Initializes a new instance of class. /// /// The backing CLR property info for the EDM property. - public ClrPropertyInfoAnnotation(PropertyDescriptor propertyDescriptor) + public ClrPropertyInfoAnnotation(MemberDescriptor propertyDescriptor) { if (propertyDescriptor == null) { @@ -44,6 +44,6 @@ public ClrPropertyInfoAnnotation(PropertyDescriptor propertyDescriptor) /// /// Gets the backing CLR property info for the EDM property. /// - public PropertyDescriptor ClrPropertyInfo { get; private set; } + public MemberDescriptor ClrPropertyInfo { get; private set; } } } diff --git a/src/Microsoft.AspNet.OData.Shared/Formatter/EdmLibHelpers.cs b/src/Microsoft.AspNet.OData.Shared/Formatter/EdmLibHelpers.cs index 00d38a0a75..32e4a01e12 100644 --- a/src/Microsoft.AspNet.OData.Shared/Formatter/EdmLibHelpers.cs +++ b/src/Microsoft.AspNet.OData.Shared/Formatter/EdmLibHelpers.cs @@ -694,7 +694,7 @@ public static string GetClrPropertyName(IEdmProperty edmProperty, IEdmModel edmM ClrPropertyInfoAnnotation annotation = edmModel.GetAnnotationValue(edmProperty); if (annotation != null) { - PropertyDescriptor propDescr = annotation.ClrPropertyInfo; + MemberDescriptor propDescr = annotation.ClrPropertyInfo; if (propDescr != null) { propertyName = propDescr.Name; @@ -704,7 +704,7 @@ public static string GetClrPropertyName(IEdmProperty edmProperty, IEdmModel edmM return propertyName; } - public static PropertyDescriptor GetClrPropertyDescriptor(IEdmProperty edmProperty, IEdmModel edmModel) + public static MemberDescriptor GetClrPropertyDescriptor(IEdmProperty edmProperty, IEdmModel edmModel) { if (edmProperty == null) { diff --git a/src/Microsoft.AspNet.OData.Shared/Microsoft.AspNet.OData.Shared.projitems b/src/Microsoft.AspNet.OData.Shared/Microsoft.AspNet.OData.Shared.projitems index bdf1646702..41d6746971 100644 --- a/src/Microsoft.AspNet.OData.Shared/Microsoft.AspNet.OData.Shared.projitems +++ b/src/Microsoft.AspNet.OData.Shared/Microsoft.AspNet.OData.Shared.projitems @@ -15,7 +15,7 @@ - + diff --git a/src/Microsoft.AspNet.OData.Shared/Query/Expressions/AggregationBinder.cs b/src/Microsoft.AspNet.OData.Shared/Query/Expressions/AggregationBinder.cs index 39721c15fa..64288658fb 100644 --- a/src/Microsoft.AspNet.OData.Shared/Query/Expressions/AggregationBinder.cs +++ b/src/Microsoft.AspNet.OData.Shared/Query/Expressions/AggregationBinder.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; +using Microsoft.AspNet.OData.Builder; using Microsoft.AspNet.OData.Common; using Microsoft.AspNet.OData.Formatter; using Microsoft.AspNet.OData.Interfaces; @@ -500,14 +501,18 @@ private Expression BindAccessor(QueryNode node, Expression baseElement = null) private Expression CreatePropertyAccessExpression(Expression source, IEdmProperty property, string propertyPath = null) { - string propertyName = EdmLibHelpers.GetClrPropertyName(property, Model); + MemberDescriptor propertyDescriptor = EdmLibHelpers.GetClrPropertyDescriptor(property, Model); + string propertyName = propertyDescriptor != null + ? propertyDescriptor.MemberInfo.Name + : EdmLibHelpers.GetClrPropertyName(property, Model); propertyPath = propertyPath ?? propertyName; if (QuerySettings.HandleNullPropagation == HandleNullPropagationOption.True && IsNullable(source.Type) && source != this._lambdaParameter) { Expression cleanSource = RemoveInnerNullPropagation(source); Expression propertyAccessExpression = null; - propertyAccessExpression = GetFlattenedPropertyExpression(propertyPath) ?? Expression.Property(cleanSource, propertyName); + propertyAccessExpression = GetFlattenedPropertyExpression(propertyPath) + ?? CreatePropertyAccessExpression(source, propertyName, propertyDescriptor); // source.property => source == null ? null : [CastToNullable]RemoveInnerNullPropagation(source).property // Notice that we are checking if source is null already. so we can safely remove any null checks when doing source.Property @@ -521,10 +526,24 @@ private Expression CreatePropertyAccessExpression(Expression source, IEdmPropert } else { - return GetFlattenedPropertyExpression(propertyPath) ?? ConvertNonStandardPrimitives(Expression.Property(source, propertyName)); + return GetFlattenedPropertyExpression(propertyPath) + ?? ConvertNonStandardPrimitives(CreatePropertyAccessExpression(source, propertyName, propertyDescriptor)); } } + private Expression CreatePropertyAccessExpression(Expression source, string propertyName, MemberDescriptor propertyDescriptor) + { + if (propertyDescriptor != null) + { + if (propertyDescriptor.MethodInfo != null) + return Expression.Call(null, propertyDescriptor.MethodInfo, source); + else + return Expression.Property(source, propertyDescriptor.PropertyInfo); + } + else + return Expression.Property(source, propertyName); + } + private Expression CreateOpenPropertyAccessExpression(SingleValueOpenPropertyAccessNode openNode) { Expression sourceAccessor = BindAccessor(openNode.Source); diff --git a/src/Microsoft.AspNet.OData.Shared/Query/Expressions/FilterBinder.cs b/src/Microsoft.AspNet.OData.Shared/Query/Expressions/FilterBinder.cs index 39831ad11e..a79396d605 100644 --- a/src/Microsoft.AspNet.OData.Shared/Query/Expressions/FilterBinder.cs +++ b/src/Microsoft.AspNet.OData.Shared/Query/Expressions/FilterBinder.cs @@ -634,7 +634,7 @@ public virtual Expression BindSingleComplexNode(SingleComplexNode singleComplexN private Expression CreatePropertyAccessExpression(Expression source, IEdmProperty property, string propertyPath = null) { - PropertyDescriptor propertyDescriptor = EdmLibHelpers.GetClrPropertyDescriptor(property, Model); + MemberDescriptor propertyDescriptor = EdmLibHelpers.GetClrPropertyDescriptor(property, Model); string propertyName = propertyDescriptor!=null ? propertyDescriptor.MemberInfo.Name : EdmLibHelpers.GetClrPropertyName(property, Model); @@ -665,7 +665,7 @@ private Expression CreatePropertyAccessExpression(Expression source, IEdmPropert } } - private Expression CreatePropertyAccessExpression(Expression source, string propertyName, PropertyDescriptor propertyDescriptor) + private Expression CreatePropertyAccessExpression(Expression source, string propertyName, MemberDescriptor propertyDescriptor) { if (propertyDescriptor != null) { diff --git a/src/Microsoft.AspNet.OData.Shared/Query/Expressions/SelectExpandWrapperConverter.cs b/src/Microsoft.AspNet.OData.Shared/Query/Expressions/SelectExpandWrapperConverter.cs index 79c5c0a936..03f4260e52 100644 --- a/src/Microsoft.AspNet.OData.Shared/Query/Expressions/SelectExpandWrapperConverter.cs +++ b/src/Microsoft.AspNet.OData.Shared/Query/Expressions/SelectExpandWrapperConverter.cs @@ -59,7 +59,7 @@ public JsonPropertyNameMapper(IEdmModel model, IEdmStructuredType type) public string MapProperty(string propertyName) { IEdmProperty property = _type.Properties().Single(s => s.Name == propertyName); - PropertyDescriptor info = GetPropertyInfo(property); + MemberDescriptor info = GetPropertyInfo(property); JsonPropertyAttribute jsonProperty = GetJsonProperty(info); if (jsonProperty != null && !String.IsNullOrWhiteSpace(jsonProperty.PropertyName)) { @@ -71,7 +71,7 @@ public string MapProperty(string propertyName) } } - private PropertyDescriptor GetPropertyInfo(IEdmProperty property) + private MemberDescriptor GetPropertyInfo(IEdmProperty property) { ClrPropertyInfoAnnotation clrPropertyAnnotation = _model.GetAnnotationValue(property); if (clrPropertyAnnotation != null) @@ -85,10 +85,10 @@ private PropertyDescriptor GetPropertyInfo(IEdmProperty property) PropertyInfo info = clrTypeAnnotation.ClrType.GetProperty(property.Name); Contract.Assert(info != null); - return new PropertyDescriptor(info); + return new MemberDescriptor(info); } - private static JsonPropertyAttribute GetJsonProperty(PropertyDescriptor property) + private static JsonPropertyAttribute GetJsonProperty(MemberDescriptor property) { return property.GetCustomAttributes(typeof(JsonPropertyAttribute), inherit: false) .OfType().SingleOrDefault(); diff --git a/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/Attributes/AttributeEdmPropertyConventionTests.cs b/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/Attributes/AttributeEdmPropertyConventionTests.cs index 9c3a9b9063..c62fb56321 100644 --- a/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/Attributes/AttributeEdmPropertyConventionTests.cs +++ b/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/Attributes/AttributeEdmPropertyConventionTests.cs @@ -60,7 +60,7 @@ public static bool Apply() Mock propertyConfiguration; if(typeof(TProperty) == typeof(PropertyConfiguration)) { - Mock propertyDescriptor = new Mock(property.Object); + Mock propertyDescriptor = new Mock(property.Object); propertyConfiguration = new Mock(propertyDescriptor.Object, structuralType.Object); } else if (typeof(TProperty) == typeof(NavigationPropertyConfiguration)) diff --git a/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/Attributes/DataContractAttributeEdmTypeConventionTests.cs b/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/Attributes/DataContractAttributeEdmTypeConventionTests.cs index 1764f23f18..b99d134283 100644 --- a/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/Attributes/DataContractAttributeEdmTypeConventionTests.cs +++ b/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/Attributes/DataContractAttributeEdmTypeConventionTests.cs @@ -61,7 +61,7 @@ public void Apply_DoesnotRemove_ExplicitlyAddedProperties() _convention.Apply(entity, builder); // Assert - Assert.Contains(new PropertyDescriptor(propertyInfo), entity.ExplicitProperties.Keys); + Assert.Contains(new MemberDescriptor(propertyInfo), entity.ExplicitProperties.Keys); Assert.DoesNotContain(propertyInfo, entity.RemovedProperties); } diff --git a/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/Attributes/IgnoreDataMemberAttributeEdmPropertyConventionTests.cs b/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/Attributes/IgnoreDataMemberAttributeEdmPropertyConventionTests.cs index 96a809b139..eeb41a6cff 100644 --- a/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/Attributes/IgnoreDataMemberAttributeEdmPropertyConventionTests.cs +++ b/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/Attributes/IgnoreDataMemberAttributeEdmPropertyConventionTests.cs @@ -31,7 +31,7 @@ public void Apply_Calls_RemovesProperty() property.Setup(p => p.PropertyType).Returns(typeof(int)); property.Setup(p => p.GetCustomAttributes(It.IsAny())).Returns(new[] { new IgnoreDataMemberAttribute() }); - Mock propertyDescriptor = new Mock(property.Object); + Mock propertyDescriptor = new Mock(property.Object); Mock type = new Mock(); Mock structuralType = new Mock(MockBehavior.Strict); @@ -67,7 +67,7 @@ public void Apply_DoesnotRemoveProperty_TypeIsDataContractAndPropertyHasDataMemb new DataContractAttribute() }); - Mock propertyDescriptor = new Mock(property.Object); + Mock propertyDescriptor = new Mock(property.Object); Mock type = new Mock(); type.Setup(t => t.GetCustomAttributes(It.IsAny(), It.IsAny())).Returns(new[] { new DataContractAttribute() }); @@ -90,7 +90,7 @@ public void Apply_DoesnotRemove_ExplicitlyAddedProperties() // Arrange ODataConventionModelBuilder builder = ODataConventionModelBuilderFactory.Create(); PropertyInfo propertyInfo = typeof(TestEntity).GetProperty("ExplicitlyAddedProperty"); - PropertyDescriptor propertyDescriptor = new PropertyDescriptor(propertyInfo); + MemberDescriptor propertyDescriptor = new MemberDescriptor(propertyInfo); EntityTypeConfiguration entity = builder.AddEntityType(typeof(TestEntity)); PropertyConfiguration property = entity.AddProperty(propertyInfo); diff --git a/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/Attributes/NotMappedAttributeConventionTests.cs b/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/Attributes/NotMappedAttributeConventionTests.cs index 3fe644cd12..628ac7a121 100644 --- a/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/Attributes/NotMappedAttributeConventionTests.cs +++ b/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/Attributes/NotMappedAttributeConventionTests.cs @@ -31,7 +31,7 @@ public void Apply_Calls_RemovesProperty_ForInferredProperties() property.Setup(p => p.PropertyType).Returns(typeof(int)); property.Setup(p => p.GetCustomAttributes(It.IsAny())).Returns(new[] { new NotMappedAttribute() }); - Mock propertyDescriptor = new Mock(property.Object); + Mock propertyDescriptor = new Mock(property.Object); Mock structuralType = new Mock(MockBehavior.Strict); structuralType.Setup(e => e.RemoveProperty(property.Object)).Verifiable(); @@ -53,7 +53,7 @@ public void Apply_DoesnotRemove_ExplicitlyAddedProperties() ODataConventionModelBuilder builder = ODataConventionModelBuilderFactory.Create(); PropertyInfo propertyInfo = typeof(TestEntity).GetProperty("Property"); - PropertyDescriptor propertyDescriptor = new PropertyDescriptor(propertyInfo); + MemberDescriptor propertyDescriptor = new MemberDescriptor(propertyInfo); EntityTypeConfiguration entity = builder.AddEntityType(typeof(TestEntity)); PropertyConfiguration property = entity.AddProperty(propertyInfo); diff --git a/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/EntityKeyConventionTests.cs b/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/EntityKeyConventionTests.cs index 1d3187932f..0012097afb 100644 --- a/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/EntityKeyConventionTests.cs +++ b/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/Conventions/EntityKeyConventionTests.cs @@ -24,7 +24,7 @@ public void Apply_Calls_HasKey_OnEdmType(string propertyName) { // Arrange Mock mockEntityType = new Mock(); - PropertyDescriptor propertyDescriptor = new PropertyDescriptor(typeof(EntityKeyConventionTests_EntityType).GetProperty(propertyName)); + MemberDescriptor propertyDescriptor = new MemberDescriptor(typeof(EntityKeyConventionTests_EntityType).GetProperty(propertyName)); Mock property = new Mock(propertyDescriptor, mockEntityType.Object); mockEntityType.Setup(e => e.Name).Returns("SampleEntity"); @@ -43,7 +43,7 @@ public void Apply_Calls_HasKey_ForEnumProperty_OnEdmType() { // Arrange Mock mockEntityType = new Mock(); - PropertyDescriptor propertyDescriptor = new PropertyDescriptor(typeof(EntityKeyConventionTests_EntityType).GetProperty("ColorId")); + MemberDescriptor propertyDescriptor = new MemberDescriptor(typeof(EntityKeyConventionTests_EntityType).GetProperty("ColorId")); Mock property = new Mock(propertyDescriptor, mockEntityType.Object); diff --git a/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/EdmTypeConfigurationExtensionsTest.cs b/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/EdmTypeConfigurationExtensionsTest.cs index ec24311a01..2b298fcc65 100644 --- a/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/EdmTypeConfigurationExtensionsTest.cs +++ b/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/EdmTypeConfigurationExtensionsTest.cs @@ -437,7 +437,7 @@ private static PropertyConfiguration MockProperty(string name, StructuralTypeCon Mock propertyInfo = new Mock(); propertyInfo.Setup(p => p.Name).Returns(name); - Mock propertyDescriptor = new Mock(propertyInfo.Object); + Mock propertyDescriptor = new Mock(propertyInfo.Object); Mock property = new Mock(propertyDescriptor.Object, declaringType); return property.Object; diff --git a/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/PropertyConfigurationTest.cs b/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/PropertyConfigurationTest.cs index 8a6a3e32b2..045010aa44 100644 --- a/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/PropertyConfigurationTest.cs +++ b/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Builder/PropertyConfigurationTest.cs @@ -16,13 +16,13 @@ public class PropertyConfigurationTest private string _name = "name"; private StructuralTypeConfiguration _declaringType; private PropertyInfo _propertyInfo; - private PropertyDescriptor _propertyDescriptor; + private MemberDescriptor _propertyDescriptor; public PropertyConfigurationTest() { Mock mockPropertyInfo = new Mock(); _propertyInfo = mockPropertyInfo.Object; - Mock mockPropertyDescriptor = new Mock(_propertyInfo); + Mock mockPropertyDescriptor = new Mock(_propertyInfo); _propertyDescriptor = mockPropertyDescriptor.Object; Mock mockTypeConfig = new Mock(); _declaringType = mockTypeConfig.Object; diff --git a/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Common/MockPropertyInfo.cs b/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Common/MockPropertyInfo.cs index 32137f8834..6ae5fd681f 100644 --- a/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Common/MockPropertyInfo.cs +++ b/test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Common/MockPropertyInfo.cs @@ -46,9 +46,9 @@ public MockPropertyInfo Abstract() return this; } - public PropertyDescriptor AsPropertyDescriptor() + public MemberDescriptor AsPropertyDescriptor() { - return new PropertyDescriptor(this); + return new MemberDescriptor(this); } } } diff --git a/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore.OData.PublicApi.bsl b/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore.OData.PublicApi.bsl index 7b22a3ffc5..105e1991fe 100644 --- a/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore.OData.PublicApi.bsl +++ b/test/UnitTest/Microsoft.AspNetCore.OData.Test/PublicApi/Microsoft.AspNetCore.OData.PublicApi.bsl @@ -204,10 +204,10 @@ public sealed class Microsoft.AspNet.OData.ODataUriFunctions { } public class Microsoft.AspNet.OData.ClrPropertyInfoAnnotation { - public ClrPropertyInfoAnnotation (PropertyDescriptor propertyDescriptor) + public ClrPropertyInfoAnnotation (MemberDescriptor propertyDescriptor) public ClrPropertyInfoAnnotation (System.Reflection.PropertyInfo clrPropertyInfo) - PropertyDescriptor ClrPropertyInfo { public get; } + MemberDescriptor ClrPropertyInfo { public get; } } public class Microsoft.AspNet.OData.ClrTypeAnnotation { @@ -1057,7 +1057,7 @@ public abstract class Microsoft.AspNet.OData.Builder.ParameterConfiguration { } public abstract class Microsoft.AspNet.OData.Builder.PropertyConfiguration { - protected PropertyConfiguration (PropertyDescriptor property, StructuralTypeConfiguration declaringType) + protected PropertyConfiguration (MemberDescriptor property, StructuralTypeConfiguration declaringType) bool AddedExplicitly { public get; public set; } bool AutoExpand { public get; public set; } @@ -1073,7 +1073,7 @@ public abstract class Microsoft.AspNet.OData.Builder.PropertyConfiguration { bool NotNavigable { public get; public set; } bool NotSortable { public get; public set; } int Order { public get; public set; } - PropertyDescriptor PropertyInfo { public get; } + MemberDescriptor PropertyInfo { public get; } QueryConfiguration QueryConfiguration { public get; public set; } System.Type RelatedClrType { public abstract get; } bool Unsortable { public get; public set; } @@ -1132,7 +1132,7 @@ public abstract class Microsoft.AspNet.OData.Builder.StructuralTypeConfiguration StructuralTypeConfiguration BaseTypeInternal { protected virtual get; } System.Type ClrType { public virtual get; } System.Reflection.PropertyInfo DynamicPropertyDictionary { public get; } - System.Collections.Generic.IDictionary`2[[Microsoft.AspNet.OData.Builder.PropertyDescriptor],[Microsoft.AspNet.OData.Builder.PropertyConfiguration]] ExplicitProperties { protected get; } + System.Collections.Generic.IDictionary`2[[Microsoft.AspNet.OData.Builder.MemberDescriptor],[Microsoft.AspNet.OData.Builder.PropertyConfiguration]] ExplicitProperties { protected get; } string FullName { public virtual get; } System.Collections.ObjectModel.ReadOnlyCollection`1[[System.Reflection.PropertyInfo]] IgnoredProperties { public get; } System.Nullable`1[[System.Boolean]] IsAbstract { public virtual get; public virtual set; } @@ -1149,16 +1149,16 @@ public abstract class Microsoft.AspNet.OData.Builder.StructuralTypeConfiguration internal virtual void AbstractImpl () public virtual CollectionPropertyConfiguration AddCollectionProperty (System.Reflection.PropertyInfo propertyInfo) public virtual ComplexPropertyConfiguration AddComplexProperty (System.Reflection.PropertyInfo propertyInfo) - public virtual NavigationPropertyConfiguration AddContainedNavigationProperty (PropertyDescriptor navigationProperty, Microsoft.OData.Edm.EdmMultiplicity multiplicity) + public virtual NavigationPropertyConfiguration AddContainedNavigationProperty (MemberDescriptor navigationProperty, Microsoft.OData.Edm.EdmMultiplicity multiplicity) public virtual NavigationPropertyConfiguration AddContainedNavigationProperty (System.Reflection.PropertyInfo navigationProperty, Microsoft.OData.Edm.EdmMultiplicity multiplicity) public virtual void AddDynamicPropertyDictionary (System.Reflection.PropertyInfo propertyInfo) public virtual EnumPropertyConfiguration AddEnumProperty (System.Reflection.PropertyInfo propertyInfo) - public virtual NavigationPropertyConfiguration AddNavigationProperty (PropertyDescriptor navigationProperty, Microsoft.OData.Edm.EdmMultiplicity multiplicity) + public virtual NavigationPropertyConfiguration AddNavigationProperty (MemberDescriptor navigationProperty, Microsoft.OData.Edm.EdmMultiplicity multiplicity) public virtual NavigationPropertyConfiguration AddNavigationProperty (System.Reflection.PropertyInfo navigationProperty, Microsoft.OData.Edm.EdmMultiplicity multiplicity) public virtual PrimitivePropertyConfiguration AddProperty (System.Reflection.PropertyInfo propertyInfo) internal virtual void DerivesFromImpl (StructuralTypeConfiguration baseType) internal virtual void DerivesFromNothingImpl () - public virtual void RemoveProperty (PropertyDescriptor propertyDescriptor) + public virtual void RemoveProperty (MemberDescriptor propertyDescriptor) public virtual void RemoveProperty (System.Reflection.PropertyInfo propertyInfo) } @@ -1549,6 +1549,25 @@ public class Microsoft.AspNet.OData.Builder.LowerCamelCaser { public virtual string ToLowerCamelCase (string name) } +public class Microsoft.AspNet.OData.Builder.MemberDescriptor { + public MemberDescriptor (System.Reflection.MethodInfo methodInfo) + public MemberDescriptor (System.Reflection.PropertyInfo propertyInfo) + + System.Type DeclaringType { public get; } + System.Reflection.MemberInfo MemberInfo { public get; } + System.Reflection.MethodInfo MethodInfo { public get; } + string Name { public get; } + System.Reflection.PropertyInfo PropertyInfo { public get; } + System.Type PropertyType { public get; } + System.Type ReflectedType { public get; } + + public virtual bool Equals (object obj) + public T GetCustomAttribute (params bool inherit) + public IEnumerable`1 GetCustomAttributes (params bool inherit) + public object[] GetCustomAttributes (System.Type type, bool inherit) + public virtual int GetHashCode () +} + public class Microsoft.AspNet.OData.Builder.NavigationLinkBuilder { public NavigationLinkBuilder (System.Func`3[[Microsoft.AspNet.OData.ResourceContext],[Microsoft.OData.Edm.IEdmNavigationProperty],[System.Uri]] navigationLinkFactory, bool followsConventions) @@ -1567,7 +1586,7 @@ public class Microsoft.AspNet.OData.Builder.NavigationPropertyBindingConfigurati } public class Microsoft.AspNet.OData.Builder.NavigationPropertyConfiguration : PropertyConfiguration { - public NavigationPropertyConfiguration (PropertyDescriptor propertyDecriptor, Microsoft.OData.Edm.EdmMultiplicity multiplicity, StructuralTypeConfiguration declaringType) + public NavigationPropertyConfiguration (MemberDescriptor propertyDecriptor, Microsoft.OData.Edm.EdmMultiplicity multiplicity, StructuralTypeConfiguration declaringType) public NavigationPropertyConfiguration (System.Reflection.PropertyInfo property, Microsoft.OData.Edm.EdmMultiplicity multiplicity, StructuralTypeConfiguration declaringType) bool ContainsTarget { public get; } @@ -1583,7 +1602,7 @@ public class Microsoft.AspNet.OData.Builder.NavigationPropertyConfiguration : Pr public NavigationPropertyConfiguration CascadeOnDelete (bool cascade) public NavigationPropertyConfiguration Contained () public NavigationPropertyConfiguration HasConstraint (System.Collections.Generic.KeyValuePair`2[[System.Reflection.PropertyInfo],[System.Reflection.PropertyInfo]] constraint) - public NavigationPropertyConfiguration HasConstraint (PropertyDescriptor dependentPropertyInfo, PropertyDescriptor principalPropertyInfo) + public NavigationPropertyConfiguration HasConstraint (MemberDescriptor dependentPropertyInfo, MemberDescriptor principalPropertyInfo) public NavigationPropertyConfiguration HasConstraint (System.Reflection.PropertyInfo dependentPropertyInfo, System.Reflection.PropertyInfo principalPropertyInfo) public NavigationPropertyConfiguration NonContained () public NavigationPropertyConfiguration Optional () @@ -1707,25 +1726,6 @@ public class Microsoft.AspNet.OData.Builder.PrimitiveTypeConfiguration : IEdmTyp string Namespace { public virtual get; } } -public class Microsoft.AspNet.OData.Builder.PropertyDescriptor { - public PropertyDescriptor (System.Reflection.MethodInfo methodInfo) - public PropertyDescriptor (System.Reflection.PropertyInfo propertyInfo) - - System.Type DeclaringType { public get; } - System.Reflection.MemberInfo MemberInfo { public get; } - System.Reflection.MethodInfo MethodInfo { public get; } - string Name { public get; } - System.Reflection.PropertyInfo PropertyInfo { public get; } - System.Type PropertyType { public get; } - System.Type ReflectedType { public get; } - - public virtual bool Equals (object obj) - public T GetCustomAttribute (params bool inherit) - public IEnumerable`1 GetCustomAttributes (params bool inherit) - public object[] GetCustomAttributes (System.Type type, bool inherit) - public virtual int GetHashCode () -} - public class Microsoft.AspNet.OData.Builder.QueryConfiguration { public QueryConfiguration ()