Skip to content

Commit 674d25f

Browse files
committed
rename PropertyDescripor and refactor
1 parent f87be69 commit 674d25f

25 files changed

+151
-133
lines changed

src/Microsoft.AspNet.OData.Shared/Builder/EdmModelHelperMethods.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ private static string ConvertBindingPath(EdmTypeMap edmMap, NavigationPropertyBi
185185
}
186186
else if (propertyInfo != null)
187187
{
188-
PropertyDescriptor propDescr = new PropertyDescriptor(propertyInfo);
188+
MemberDescriptor propDescr = new MemberDescriptor(propertyInfo);
189189
bindings.Add(edmMap.EdmProperties[propDescr].Name);
190190
}
191191
else if (methodInfo != null)
192192
{
193-
PropertyDescriptor propDescr = new PropertyDescriptor(methodInfo);
193+
MemberDescriptor propDescr = new MemberDescriptor(methodInfo);
194194
bindings.Add(edmMap.EdmProperties[propDescr].Name);
195195
}
196196
}
@@ -431,7 +431,7 @@ private static Dictionary<Type, IEdmType> AddTypes(this EdmModel model, EdmTypeM
431431
model.AddClrTypeAnnotations(edmTypes);
432432

433433
// add annotation for properties
434-
Dictionary<PropertyDescriptor, IEdmProperty> edmProperties = edmTypeMap.EdmProperties;
434+
Dictionary<MemberDescriptor, IEdmProperty> edmProperties = edmTypeMap.EdmProperties;
435435
model.AddClrPropertyInfoAnnotations(edmProperties);
436436
model.AddPropertyRestrictionsAnnotations(edmTypeMap.EdmPropertiesRestrictions);
437437
model.AddPropertiesQuerySettings(edmTypeMap.EdmPropertiesQuerySettings);
@@ -495,12 +495,12 @@ private static void AddClrTypeAnnotations(this EdmModel model, Dictionary<Type,
495495
}
496496
}
497497

498-
private static void AddClrPropertyInfoAnnotations(this EdmModel model, Dictionary<PropertyDescriptor, IEdmProperty> edmProperties)
498+
private static void AddClrPropertyInfoAnnotations(this EdmModel model, Dictionary<MemberDescriptor, IEdmProperty> edmProperties)
499499
{
500-
foreach (KeyValuePair<PropertyDescriptor, IEdmProperty> edmPropertyMap in edmProperties)
500+
foreach (KeyValuePair<MemberDescriptor, IEdmProperty> edmPropertyMap in edmProperties)
501501
{
502502
IEdmProperty edmProperty = edmPropertyMap.Value;
503-
PropertyDescriptor clrProperty = edmPropertyMap.Key;
503+
MemberDescriptor clrProperty = edmPropertyMap.Key;
504504
if (clrProperty.MethodInfo != null || edmProperty.Name != clrProperty.Name)
505505
{
506506
model.SetAnnotationValue(edmProperty, new ClrPropertyInfoAnnotation(clrProperty));

src/Microsoft.AspNet.OData.Shared/Builder/EdmTypeBuilder.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal class EdmTypeBuilder
2222
{
2323
private readonly List<IEdmTypeConfiguration> _configurations;
2424
private readonly Dictionary<Type, IEdmType> _types = new Dictionary<Type, IEdmType>();
25-
private readonly Dictionary<PropertyDescriptor, IEdmProperty> _properties = new Dictionary<PropertyDescriptor, IEdmProperty>();
25+
private readonly Dictionary<MemberDescriptor, IEdmProperty> _properties = new Dictionary<MemberDescriptor, IEdmProperty>();
2626
private readonly Dictionary<IEdmProperty, QueryableRestrictions> _propertiesRestrictions = new Dictionary<IEdmProperty, QueryableRestrictions>();
2727
private readonly Dictionary<IEdmProperty, ModelBoundQuerySettings> _propertiesQuerySettings = new Dictionary<IEdmProperty, ModelBoundQuerySettings>();
2828
private readonly Dictionary<IEdmStructuredType, ModelBoundQuerySettings> _structuredTypeQuerySettings = new Dictionary<IEdmStructuredType, ModelBoundQuerySettings>();
@@ -433,7 +433,7 @@ private IList<IEdmStructuralProperty> GetDeclaringPropertyInfo(IEnumerable<Prope
433433
foreach (PropertyInfo propInfo in propertyInfos)
434434
{
435435
IEdmProperty edmProperty;
436-
PropertyDescriptor propDescr = new PropertyDescriptor(propInfo);
436+
MemberDescriptor propDescr = new MemberDescriptor(propInfo);
437437
if (_properties.TryGetValue(propDescr, out edmProperty))
438438
{
439439
edmProperties.Add(edmProperty);
@@ -445,7 +445,7 @@ private IList<IEdmStructuralProperty> GetDeclaringPropertyInfo(IEnumerable<Prope
445445
while (baseType != null)
446446
{
447447
PropertyInfo basePropInfo = baseType.GetProperty(propInfo.Name);
448-
PropertyDescriptor basePropDescr = new PropertyDescriptor(basePropInfo);
448+
MemberDescriptor basePropDescr = new MemberDescriptor(basePropInfo);
449449
if (_properties.TryGetValue(basePropDescr, out edmProperty))
450450
{
451451
edmProperties.Add(edmProperty);

src/Microsoft.AspNet.OData.Shared/Builder/EdmTypeMap.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal class EdmTypeMap
1313
{
1414
public EdmTypeMap(
1515
Dictionary<Type, IEdmType> edmTypes,
16-
Dictionary<PropertyDescriptor, IEdmProperty> edmProperties,
16+
Dictionary<MemberDescriptor, IEdmProperty> edmProperties,
1717
Dictionary<IEdmProperty, QueryableRestrictions> edmPropertiesRestrictions,
1818
Dictionary<IEdmProperty, ModelBoundQuerySettings> edmPropertiesQuerySettings,
1919
Dictionary<IEdmStructuredType, ModelBoundQuerySettings> edmStructuredTypeQuerySettings,
@@ -31,7 +31,7 @@ public EdmTypeMap(
3131

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

34-
public Dictionary<PropertyDescriptor, IEdmProperty> EdmProperties { get; private set; }
34+
public Dictionary<MemberDescriptor, IEdmProperty> EdmProperties { get; private set; }
3535

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

src/Microsoft.AspNet.OData.Shared/Builder/PropertyDescriptor.cs renamed to src/Microsoft.AspNet.OData.Shared/Builder/MemberDescriptor.cs

+29-30
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
1-
using Microsoft.AspNet.OData.Common;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
24
using System;
35
using System.Collections.Generic;
46
using System.Reflection;
5-
using System.Text;
7+
using Microsoft.AspNet.OData.Common;
68

79
namespace Microsoft.AspNet.OData.Builder
810
{
911
/// <summary>
10-
/// Property descriptor
12+
/// Member descriptor
1113
/// </summary>
12-
public class PropertyDescriptor
14+
public class MemberDescriptor
1315
{
14-
private readonly PropertyInfo _propertyInfo;
15-
private readonly MethodInfo _methodInfo;
16+
private readonly MemberInfo _memberInfo;
1617

1718
/// <summary>
18-
/// Initializes a new instance of the <see cref="PropertyDescriptor"/> class.
19+
/// Initializes a new instance of the <see cref="MemberDescriptor"/> class.
1920
/// </summary>
2021
/// <param name="propertyInfo">Property information</param>
21-
public PropertyDescriptor(PropertyInfo propertyInfo)
22+
public MemberDescriptor(PropertyInfo propertyInfo)
2223
{
2324
if (propertyInfo == null)
2425
{
2526
throw Error.ArgumentNull("propertyInfo");
2627
}
2728

28-
this._propertyInfo = propertyInfo;
29+
this._memberInfo = propertyInfo;
2930
}
3031

3132
/// <summary>
32-
/// Initializes a new instance of the <see cref="PropertyDescriptor"/> class.
33+
/// Initializes a new instance of the <see cref="MemberDescriptor"/> class.
3334
/// </summary>
34-
/// <param name="methodInfo">Extension property information</param>
35-
public PropertyDescriptor(MethodInfo methodInfo)
35+
/// <param name="methodInfo">Extension method information</param>
36+
public MemberDescriptor(MethodInfo methodInfo)
3637
{
37-
if(methodInfo==null)
38+
if(methodInfo == null)
3839
{
3940
throw Error.ArgumentNull("methodInfo");
4041
}
41-
this._methodInfo = methodInfo;
42+
this._memberInfo = methodInfo;
4243
}
4344

4445
/// <summary>
@@ -48,9 +49,7 @@ public MemberInfo MemberInfo
4849
{
4950
get
5051
{
51-
if (_propertyInfo != null)
52-
return _propertyInfo;
53-
return _methodInfo;
52+
return _memberInfo;
5453
}
5554
}
5655

@@ -61,7 +60,7 @@ public PropertyInfo PropertyInfo
6160
{
6261
get
6362
{
64-
return _propertyInfo;
63+
return _memberInfo as PropertyInfo;
6564
}
6665
}
6766

@@ -72,7 +71,7 @@ public MethodInfo MethodInfo
7271
{
7372
get
7473
{
75-
return _methodInfo;
74+
return _memberInfo as MethodInfo;
7675
}
7776
}
7877

@@ -94,9 +93,9 @@ public Type PropertyType
9493
{
9594
get
9695
{
97-
if (_propertyInfo != null)
98-
return _propertyInfo.PropertyType;
99-
return _methodInfo.ReturnType;
96+
if (PropertyInfo != null)
97+
return PropertyInfo.PropertyType;
98+
return MethodInfo.ReturnType;
10099
}
101100
}
102101

@@ -107,9 +106,9 @@ public Type DeclaringType
107106
{
108107
get
109108
{
110-
if (_propertyInfo != null)
111-
return _propertyInfo.DeclaringType;
112-
return _methodInfo.GetParameters()[0].ParameterType;
109+
if (PropertyInfo != null)
110+
return PropertyInfo.DeclaringType;
111+
return MethodInfo.GetParameters()[0].ParameterType;
113112
}
114113
}
115114

@@ -120,14 +119,14 @@ public Type ReflectedType
120119
{
121120
get
122121
{
123-
if (_propertyInfo != null)
124-
return TypeHelper.GetReflectedType(_propertyInfo);
125-
return _methodInfo.GetParameters()[0].ParameterType;
122+
if (PropertyInfo != null)
123+
return TypeHelper.GetReflectedType(PropertyInfo);
124+
return MethodInfo.GetParameters()[0].ParameterType;
126125
}
127126
}
128127

129128
/// <inheritdoc/>
130-
public static implicit operator MemberInfo(PropertyDescriptor propertyDescriptor)
129+
public static implicit operator MemberInfo(MemberDescriptor propertyDescriptor)
131130
{
132131
return propertyDescriptor.MemberInfo;
133132
}
@@ -161,7 +160,7 @@ public override int GetHashCode()
161160
/// <inheritdoc/>
162161
public override bool Equals(object obj)
163162
{
164-
PropertyDescriptor propDescr = obj as PropertyDescriptor;
163+
MemberDescriptor propDescr = obj as MemberDescriptor;
165164
if (propDescr == null)
166165
return false;
167166

src/Microsoft.AspNet.OData.Shared/Builder/NavigationPropertyConfiguration.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public NavigationPropertyConfiguration(PropertyInfo property, EdmMultiplicity mu
4040
/// <param name="propertyDecriptor">The backing CLR property.</param>
4141
/// <param name="multiplicity">The <see cref="EdmMultiplicity"/>.</param>
4242
/// <param name="declaringType">The declaring structural type.</param>
43-
public NavigationPropertyConfiguration(PropertyDescriptor propertyDecriptor, EdmMultiplicity multiplicity, StructuralTypeConfiguration declaringType)
43+
public NavigationPropertyConfiguration(MemberDescriptor propertyDecriptor, EdmMultiplicity multiplicity, StructuralTypeConfiguration declaringType)
4444
: base(propertyDecriptor, declaringType)
4545
{
4646
if (propertyDecriptor == null)
@@ -65,13 +65,13 @@ public NavigationPropertyConfiguration(PropertyDescriptor propertyDecriptor, Edm
6565
OnDeleteAction = EdmOnDeleteAction.None;
6666
}
6767

68-
private static PropertyDescriptor CreatePropertyDescriptor(PropertyInfo property)
68+
private static MemberDescriptor CreatePropertyDescriptor(PropertyInfo property)
6969
{
7070
if(property == null)
7171
{
7272
throw Error.ArgumentNull("property");
7373
}
74-
return new PropertyDescriptor(property);
74+
return new MemberDescriptor(property);
7575
}
7676

7777
/// <summary>
@@ -219,8 +219,8 @@ public NavigationPropertyConfiguration HasConstraint(PropertyInfo dependentPrope
219219
/// </summary>
220220
/// <param name="dependentPropertyInfo">The dependent property info for the referential constraint.</param>
221221
/// <param name="principalPropertyInfo">The principal property info for the referential constraint.</param>
222-
public NavigationPropertyConfiguration HasConstraint(PropertyDescriptor dependentPropertyInfo,
223-
PropertyDescriptor principalPropertyInfo)
222+
public NavigationPropertyConfiguration HasConstraint(MemberDescriptor dependentPropertyInfo,
223+
MemberDescriptor principalPropertyInfo)
224224
{
225225
return HasConstraint(dependentPropertyInfo.PropertyInfo, principalPropertyInfo.PropertyInfo);
226226
}

src/Microsoft.AspNet.OData.Shared/Builder/PropertyConfiguration.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public abstract class PropertyConfiguration
2020
/// </summary>
2121
/// <param name="property">The name of the property.</param>
2222
/// <param name="declaringType">The declaring EDM type of the property.</param>
23-
protected PropertyConfiguration(PropertyDescriptor property, StructuralTypeConfiguration declaringType)
23+
protected PropertyConfiguration(MemberDescriptor property, StructuralTypeConfiguration declaringType)
2424
{
2525
if (property == null)
2626
{
@@ -67,7 +67,7 @@ public string Name
6767
/// <summary>
6868
/// Gets the mapping CLR <see cref="PropertyInfo"/>.
6969
/// </summary>
70-
public PropertyDescriptor PropertyInfo { get; private set; }
70+
public MemberDescriptor PropertyInfo { get; private set; }
7171

7272
/// <summary>
7373
/// Gets the CLR <see cref="Type"/> of the property.

src/Microsoft.AspNet.OData.Shared/Builder/StructuralPropertyConfiguration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public abstract class StructuralPropertyConfiguration : PropertyConfiguration
1717
/// <param name="property">The property of the configuration.</param>
1818
/// <param name="declaringType">The declaring type of the property.</param>
1919
protected StructuralPropertyConfiguration(PropertyInfo property, StructuralTypeConfiguration declaringType)
20-
: base(new PropertyDescriptor(property), declaringType)
20+
: base(new MemberDescriptor(property), declaringType)
2121
{
2222
OptionalProperty = EdmLibHelpers.IsNullable(property.PropertyType);
2323
}

src/Microsoft.AspNet.OData.Shared/Builder/StructuralTypeConfiguration.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public abstract class StructuralTypeConfiguration : IEdmTypeConfiguration
3131
/// <remarks>The default constructor is intended for use by unit testing only.</remarks>
3232
protected StructuralTypeConfiguration()
3333
{
34-
ExplicitProperties = new Dictionary<PropertyDescriptor, PropertyConfiguration>();
34+
ExplicitProperties = new Dictionary<MemberDescriptor, PropertyConfiguration>();
3535
RemovedProperties = new List<PropertyInfo>();
3636
QueryConfiguration = new QueryConfiguration();
3737
}
@@ -213,7 +213,7 @@ public virtual IEnumerable<NavigationPropertyConfiguration> NavigationProperties
213213
/// <summary>
214214
/// Gets the collection of explicitly added properties.
215215
/// </summary>
216-
protected internal IDictionary<PropertyDescriptor, PropertyConfiguration> ExplicitProperties { get; private set; }
216+
protected internal IDictionary<MemberDescriptor, PropertyConfiguration> ExplicitProperties { get; private set; }
217217

218218
/// <summary>
219219
/// Gets the base type of this structural type.
@@ -361,7 +361,7 @@ public virtual EnumPropertyConfiguration AddEnumProperty(PropertyInfo propertyIn
361361
return propertyConfiguration;
362362
}
363363

364-
internal ComplexPropertyConfiguration AddComplexProperty(PropertyDescriptor propertyDescriptor)
364+
internal ComplexPropertyConfiguration AddComplexProperty(MemberDescriptor propertyDescriptor)
365365
{
366366
return AddComplexProperty(propertyDescriptor.PropertyInfo);
367367
}
@@ -408,7 +408,7 @@ public virtual ComplexPropertyConfiguration AddComplexProperty(PropertyInfo prop
408408
return propertyConfiguration;
409409
}
410410

411-
internal CollectionPropertyConfiguration AddCollectionProperty(PropertyDescriptor propertyDescriptor)
411+
internal CollectionPropertyConfiguration AddCollectionProperty(MemberDescriptor propertyDescriptor)
412412
{
413413
return AddCollectionProperty(propertyDescriptor.PropertyInfo);
414414
}
@@ -502,7 +502,7 @@ public virtual void AddDynamicPropertyDictionary(PropertyInfo propertyInfo)
502502
/// Removes the given property.
503503
/// </summary>
504504
/// <param name="propertyDescriptor">The property being removed.</param>
505-
public virtual void RemoveProperty(PropertyDescriptor propertyDescriptor)
505+
public virtual void RemoveProperty(MemberDescriptor propertyDescriptor)
506506
{
507507
if (propertyDescriptor == null)
508508
{
@@ -552,7 +552,7 @@ public virtual void RemoveProperty(PropertyInfo propertyInfo)
552552
/// <returns>Returns the <see cref="NavigationPropertyConfiguration"/> of the added property.</returns>
553553
public virtual NavigationPropertyConfiguration AddNavigationProperty(PropertyInfo navigationProperty, EdmMultiplicity multiplicity)
554554
{
555-
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(navigationProperty);
555+
MemberDescriptor propertyDescriptor = new MemberDescriptor(navigationProperty);
556556
return AddNavigationProperty(propertyDescriptor, multiplicity, containsTarget: false);
557557
}
558558

@@ -562,7 +562,7 @@ public virtual NavigationPropertyConfiguration AddNavigationProperty(PropertyInf
562562
/// <param name="navigationProperty">The backing CLR property.</param>
563563
/// <param name="multiplicity">The <see cref="EdmMultiplicity"/> of the navigation property.</param>
564564
/// <returns>Returns the <see cref="NavigationPropertyConfiguration"/> of the added property.</returns>
565-
public virtual NavigationPropertyConfiguration AddNavigationProperty(PropertyDescriptor navigationProperty, EdmMultiplicity multiplicity)
565+
public virtual NavigationPropertyConfiguration AddNavigationProperty(MemberDescriptor navigationProperty, EdmMultiplicity multiplicity)
566566
{
567567
return AddNavigationProperty(navigationProperty, multiplicity, containsTarget: false);
568568
}
@@ -575,7 +575,7 @@ public virtual NavigationPropertyConfiguration AddNavigationProperty(PropertyDes
575575
/// <returns>Returns the <see cref="NavigationPropertyConfiguration"/> of the added property.</returns>
576576
public virtual NavigationPropertyConfiguration AddContainedNavigationProperty(PropertyInfo navigationProperty, EdmMultiplicity multiplicity)
577577
{
578-
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(navigationProperty);
578+
MemberDescriptor propertyDescriptor = new MemberDescriptor(navigationProperty);
579579
return AddNavigationProperty(propertyDescriptor, multiplicity, containsTarget: true);
580580
}
581581

@@ -585,12 +585,12 @@ public virtual NavigationPropertyConfiguration AddContainedNavigationProperty(Pr
585585
/// <param name="navigationProperty">The backing CLR property.</param>
586586
/// <param name="multiplicity">The <see cref="EdmMultiplicity"/> of the navigation property.</param>
587587
/// <returns>Returns the <see cref="NavigationPropertyConfiguration"/> of the added property.</returns>
588-
public virtual NavigationPropertyConfiguration AddContainedNavigationProperty(PropertyDescriptor navigationProperty, EdmMultiplicity multiplicity)
588+
public virtual NavigationPropertyConfiguration AddContainedNavigationProperty(MemberDescriptor navigationProperty, EdmMultiplicity multiplicity)
589589
{
590590
return AddNavigationProperty(navigationProperty, multiplicity, containsTarget: true);
591591
}
592592

593-
private NavigationPropertyConfiguration AddNavigationProperty(PropertyDescriptor navigationProperty, EdmMultiplicity multiplicity, bool containsTarget)
593+
private NavigationPropertyConfiguration AddNavigationProperty(MemberDescriptor navigationProperty, EdmMultiplicity multiplicity, bool containsTarget)
594594
{
595595
if (navigationProperty == null)
596596
{

0 commit comments

Comments
 (0)