Skip to content

Commit

Permalink
rename PropertyDescripor and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
genusP committed Jul 17, 2018
1 parent f87be69 commit b347a48
Show file tree
Hide file tree
Showing 24 changed files with 139 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -431,7 +431,7 @@ private static Dictionary<Type, IEdmType> AddTypes(this EdmModel model, EdmTypeM
model.AddClrTypeAnnotations(edmTypes);

// add annotation for properties
Dictionary<PropertyDescriptor, IEdmProperty> edmProperties = edmTypeMap.EdmProperties;
Dictionary<MemberDescriptor, IEdmProperty> edmProperties = edmTypeMap.EdmProperties;
model.AddClrPropertyInfoAnnotations(edmProperties);
model.AddPropertyRestrictionsAnnotations(edmTypeMap.EdmPropertiesRestrictions);
model.AddPropertiesQuerySettings(edmTypeMap.EdmPropertiesQuerySettings);
Expand Down Expand Up @@ -495,12 +495,12 @@ private static void AddClrTypeAnnotations(this EdmModel model, Dictionary<Type,
}
}

private static void AddClrPropertyInfoAnnotations(this EdmModel model, Dictionary<PropertyDescriptor, IEdmProperty> edmProperties)
private static void AddClrPropertyInfoAnnotations(this EdmModel model, Dictionary<MemberDescriptor, IEdmProperty> edmProperties)
{
foreach (KeyValuePair<PropertyDescriptor, IEdmProperty> edmPropertyMap in edmProperties)
foreach (KeyValuePair<MemberDescriptor, IEdmProperty> 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));
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.AspNet.OData.Shared/Builder/EdmTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal class EdmTypeBuilder
{
private readonly List<IEdmTypeConfiguration> _configurations;
private readonly Dictionary<Type, IEdmType> _types = new Dictionary<Type, IEdmType>();
private readonly Dictionary<PropertyDescriptor, IEdmProperty> _properties = new Dictionary<PropertyDescriptor, IEdmProperty>();
private readonly Dictionary<MemberDescriptor, IEdmProperty> _properties = new Dictionary<MemberDescriptor, IEdmProperty>();
private readonly Dictionary<IEdmProperty, QueryableRestrictions> _propertiesRestrictions = new Dictionary<IEdmProperty, QueryableRestrictions>();
private readonly Dictionary<IEdmProperty, ModelBoundQuerySettings> _propertiesQuerySettings = new Dictionary<IEdmProperty, ModelBoundQuerySettings>();
private readonly Dictionary<IEdmStructuredType, ModelBoundQuerySettings> _structuredTypeQuerySettings = new Dictionary<IEdmStructuredType, ModelBoundQuerySettings>();
Expand Down Expand Up @@ -433,7 +433,7 @@ private IList<IEdmStructuralProperty> GetDeclaringPropertyInfo(IEnumerable<Prope
foreach (PropertyInfo propInfo in propertyInfos)
{
IEdmProperty edmProperty;
PropertyDescriptor propDescr = new PropertyDescriptor(propInfo);
MemberDescriptor propDescr = new MemberDescriptor(propInfo);
if (_properties.TryGetValue(propDescr, out edmProperty))
{
edmProperties.Add(edmProperty);
Expand All @@ -445,7 +445,7 @@ private IList<IEdmStructuralProperty> GetDeclaringPropertyInfo(IEnumerable<Prope
while (baseType != null)
{
PropertyInfo basePropInfo = baseType.GetProperty(propInfo.Name);
PropertyDescriptor basePropDescr = new PropertyDescriptor(basePropInfo);
MemberDescriptor basePropDescr = new MemberDescriptor(basePropInfo);
if (_properties.TryGetValue(basePropDescr, out edmProperty))
{
edmProperties.Add(edmProperty);
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.AspNet.OData.Shared/Builder/EdmTypeMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class EdmTypeMap
{
public EdmTypeMap(
Dictionary<Type, IEdmType> edmTypes,
Dictionary<PropertyDescriptor, IEdmProperty> edmProperties,
Dictionary<MemberDescriptor, IEdmProperty> edmProperties,
Dictionary<IEdmProperty, QueryableRestrictions> edmPropertiesRestrictions,
Dictionary<IEdmProperty, ModelBoundQuerySettings> edmPropertiesQuerySettings,
Dictionary<IEdmStructuredType, ModelBoundQuerySettings> edmStructuredTypeQuerySettings,
Expand All @@ -31,7 +31,7 @@ public EdmTypeMap(

public Dictionary<Type, IEdmType> EdmTypes { get; private set; }

public Dictionary<PropertyDescriptor, IEdmProperty> EdmProperties { get; private set; }
public Dictionary<MemberDescriptor, IEdmProperty> EdmProperties { get; private set; }

public Dictionary<IEdmProperty, QueryableRestrictions> EdmPropertiesRestrictions { get; private set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Property descriptor
/// Member descriptor
/// </summary>
public class PropertyDescriptor
public class MemberDescriptor
{
private readonly PropertyInfo _propertyInfo;
private readonly MethodInfo _methodInfo;
private readonly MemberInfo _memberInfo;

/// <summary>
/// Initializes a new instance of the <see cref="PropertyDescriptor"/> class.
/// Initializes a new instance of the <see cref="MemberDescriptor"/> class.
/// </summary>
/// <param name="propertyInfo">Property information</param>
public PropertyDescriptor(PropertyInfo propertyInfo)
public MemberDescriptor(PropertyInfo propertyInfo)
{
if (propertyInfo == null)
{
throw Error.ArgumentNull("propertyInfo");
}

this._propertyInfo = propertyInfo;
this._memberInfo = propertyInfo;
}

/// <summary>
/// Initializes a new instance of the <see cref="PropertyDescriptor"/> class.
/// Initializes a new instance of the <see cref="MemberDescriptor"/> class.
/// </summary>
/// <param name="methodInfo">Extension property information</param>
public PropertyDescriptor(MethodInfo methodInfo)
/// <param name="methodInfo">Extension method information</param>
public MemberDescriptor(MethodInfo methodInfo)
{
if(methodInfo==null)
if(methodInfo == null)
{
throw Error.ArgumentNull("methodInfo");
}
this._methodInfo = methodInfo;
this._memberInfo = methodInfo;
}

/// <summary>
Expand All @@ -48,9 +49,7 @@ public MemberInfo MemberInfo
{
get
{
if (_propertyInfo != null)
return _propertyInfo;
return _methodInfo;
return _memberInfo;
}
}

Expand All @@ -61,7 +60,7 @@ public PropertyInfo PropertyInfo
{
get
{
return _propertyInfo;
return _memberInfo as PropertyInfo;
}
}

Expand All @@ -72,7 +71,7 @@ public MethodInfo MethodInfo
{
get
{
return _methodInfo;
return _memberInfo as MethodInfo;
}
}

Expand All @@ -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;
}
}

Expand All @@ -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;
}
}

Expand All @@ -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;
}
}

/// <inheritdoc/>
public static implicit operator MemberInfo(PropertyDescriptor propertyDescriptor)
public static implicit operator MemberInfo(MemberDescriptor propertyDescriptor)
{
return propertyDescriptor.MemberInfo;
}
Expand Down Expand Up @@ -161,7 +160,7 @@ public override int GetHashCode()
/// <inheritdoc/>
public override bool Equals(object obj)
{
PropertyDescriptor propDescr = obj as PropertyDescriptor;
MemberDescriptor propDescr = obj as MemberDescriptor;
if (propDescr == null)
return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public NavigationPropertyConfiguration(PropertyInfo property, EdmMultiplicity mu
/// <param name="propertyDecriptor">The backing CLR property.</param>
/// <param name="multiplicity">The <see cref="EdmMultiplicity"/>.</param>
/// <param name="declaringType">The declaring structural type.</param>
public NavigationPropertyConfiguration(PropertyDescriptor propertyDecriptor, EdmMultiplicity multiplicity, StructuralTypeConfiguration declaringType)
public NavigationPropertyConfiguration(MemberDescriptor propertyDecriptor, EdmMultiplicity multiplicity, StructuralTypeConfiguration declaringType)
: base(propertyDecriptor, declaringType)
{
if (propertyDecriptor == null)
Expand All @@ -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);
}

/// <summary>
Expand Down Expand Up @@ -219,8 +219,8 @@ public NavigationPropertyConfiguration HasConstraint(PropertyInfo dependentPrope
/// </summary>
/// <param name="dependentPropertyInfo">The dependent property info for the referential constraint.</param>
/// <param name="principalPropertyInfo">The principal property info for the referential constraint.</param>
public NavigationPropertyConfiguration HasConstraint(PropertyDescriptor dependentPropertyInfo,
PropertyDescriptor principalPropertyInfo)
public NavigationPropertyConfiguration HasConstraint(MemberDescriptor dependentPropertyInfo,
MemberDescriptor principalPropertyInfo)
{
return HasConstraint(dependentPropertyInfo.PropertyInfo, principalPropertyInfo.PropertyInfo);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class PropertyConfiguration
/// </summary>
/// <param name="property">The name of the property.</param>
/// <param name="declaringType">The declaring EDM type of the property.</param>
protected PropertyConfiguration(PropertyDescriptor property, StructuralTypeConfiguration declaringType)
protected PropertyConfiguration(MemberDescriptor property, StructuralTypeConfiguration declaringType)
{
if (property == null)
{
Expand Down Expand Up @@ -67,7 +67,7 @@ public string Name
/// <summary>
/// Gets the mapping CLR <see cref="PropertyInfo"/>.
/// </summary>
public PropertyDescriptor PropertyInfo { get; private set; }
public MemberDescriptor PropertyInfo { get; private set; }

/// <summary>
/// Gets the CLR <see cref="Type"/> of the property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class StructuralPropertyConfiguration : PropertyConfiguration
/// <param name="property">The property of the configuration.</param>
/// <param name="declaringType">The declaring type of the property.</param>
protected StructuralPropertyConfiguration(PropertyInfo property, StructuralTypeConfiguration declaringType)
: base(new PropertyDescriptor(property), declaringType)
: base(new MemberDescriptor(property), declaringType)
{
OptionalProperty = EdmLibHelpers.IsNullable(property.PropertyType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public abstract class StructuralTypeConfiguration : IEdmTypeConfiguration
/// <remarks>The default constructor is intended for use by unit testing only.</remarks>
protected StructuralTypeConfiguration()
{
ExplicitProperties = new Dictionary<PropertyDescriptor, PropertyConfiguration>();
ExplicitProperties = new Dictionary<MemberDescriptor, PropertyConfiguration>();
RemovedProperties = new List<PropertyInfo>();
QueryConfiguration = new QueryConfiguration();
}
Expand Down Expand Up @@ -213,7 +213,7 @@ public virtual IEnumerable<NavigationPropertyConfiguration> NavigationProperties
/// <summary>
/// Gets the collection of explicitly added properties.
/// </summary>
protected internal IDictionary<PropertyDescriptor, PropertyConfiguration> ExplicitProperties { get; private set; }
protected internal IDictionary<MemberDescriptor, PropertyConfiguration> ExplicitProperties { get; private set; }

/// <summary>
/// Gets the base type of this structural type.
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -502,7 +502,7 @@ public virtual void AddDynamicPropertyDictionary(PropertyInfo propertyInfo)
/// Removes the given property.
/// </summary>
/// <param name="propertyDescriptor">The property being removed.</param>
public virtual void RemoveProperty(PropertyDescriptor propertyDescriptor)
public virtual void RemoveProperty(MemberDescriptor propertyDescriptor)
{
if (propertyDescriptor == null)
{
Expand Down Expand Up @@ -552,7 +552,7 @@ public virtual void RemoveProperty(PropertyInfo propertyInfo)
/// <returns>Returns the <see cref="NavigationPropertyConfiguration"/> of the added property.</returns>
public virtual NavigationPropertyConfiguration AddNavigationProperty(PropertyInfo navigationProperty, EdmMultiplicity multiplicity)
{
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(navigationProperty);
MemberDescriptor propertyDescriptor = new MemberDescriptor(navigationProperty);
return AddNavigationProperty(propertyDescriptor, multiplicity, containsTarget: false);
}

Expand All @@ -562,7 +562,7 @@ public virtual NavigationPropertyConfiguration AddNavigationProperty(PropertyInf
/// <param name="navigationProperty">The backing CLR property.</param>
/// <param name="multiplicity">The <see cref="EdmMultiplicity"/> of the navigation property.</param>
/// <returns>Returns the <see cref="NavigationPropertyConfiguration"/> of the added property.</returns>
public virtual NavigationPropertyConfiguration AddNavigationProperty(PropertyDescriptor navigationProperty, EdmMultiplicity multiplicity)
public virtual NavigationPropertyConfiguration AddNavigationProperty(MemberDescriptor navigationProperty, EdmMultiplicity multiplicity)
{
return AddNavigationProperty(navigationProperty, multiplicity, containsTarget: false);
}
Expand All @@ -575,7 +575,7 @@ public virtual NavigationPropertyConfiguration AddNavigationProperty(PropertyDes
/// <returns>Returns the <see cref="NavigationPropertyConfiguration"/> of the added property.</returns>
public virtual NavigationPropertyConfiguration AddContainedNavigationProperty(PropertyInfo navigationProperty, EdmMultiplicity multiplicity)
{
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(navigationProperty);
MemberDescriptor propertyDescriptor = new MemberDescriptor(navigationProperty);
return AddNavigationProperty(propertyDescriptor, multiplicity, containsTarget: true);
}

Expand All @@ -585,12 +585,12 @@ public virtual NavigationPropertyConfiguration AddContainedNavigationProperty(Pr
/// <param name="navigationProperty">The backing CLR property.</param>
/// <param name="multiplicity">The <see cref="EdmMultiplicity"/> of the navigation property.</param>
/// <returns>Returns the <see cref="NavigationPropertyConfiguration"/> of the added property.</returns>
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)
{
Expand Down
Loading

0 comments on commit b347a48

Please sign in to comment.