1

i read the MapBuilder.cs source code in the ent lib 5.0;

some code seems so weird for me, i just can`t figurt out whats the purpose of doing so:

public static IMapBuilderContext<TResult> MapAllProperties()
{
   IMapBuilderContext<TResult> context = new MapBuilderContext();
   var properties =
            from property in typeof(TResult).GetProperties(BindingFlags.Instance | BindingFlags.Public)
            where IsAutoMappableProperty(property)
            select property;
   foreach (var property in properties)
   {
       context = context.MapByName(property);
   }
   return context;
}

in the MapAllProperties(), we get properties using Type.GetProperties(), then, in the MapByName(), we using a method called NormalizePropertyInfo() to get "another" property. i mean call Type.GetProperty() again!!!:

private static PropertyInfo NormalizePropertyInfo(PropertyInfo property)
{
    if (property == null) throw new ArgumentNullException("property");
    return typeof(TResult).GetProperty(property.Name);
}

why need calling the GetProperty() again? what`s the purpose of NormalizePropertyInfo()?

any help would be appreciated, thanks.

pinopino
  • 264
  • 2
  • 12
  • That is quite strange. One difference I notice is that the first GetProperty() call is looking for instance properties only, while the second call could return instance or static. It should only return the same PropertyInfo though, since a type cannot have both instance and static properties with the same name, as far as I know. I wonder, is TResult the same type in both calls? – Tim B May 22 '13 at 13:01
  • @TimB yes, in fact the NormalizePropertyInfo() reside in MapBuilderContext class which is a nested class in class MapBuilder. so the TResult was just the same as outer class(the MapBuilder). so... both GetProperty(ies) should return the same value, which was the key point confusing me the most. – pinopino May 22 '13 at 14:22

0 Answers0