asiftasleem / nbuilder

Automatically exported from code.google.com/p/nbuilder
0 stars 0 forks source link

Enhance BuilderSetup.ShouldIgnoreProperty #85

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
BuilderSetup.ShouldIgnoreProperty doesn't consider interface types used with 
BuilderSetup.DisablePropertyNamingFor.

Assume we have a generic Interface like 

  public interface INameable {
    string Name { get; set; };
  }

and want to disable the property naming for the Name property:

  BuilderSetup.DisablePropertyNamingFor<INameable, string>(x => x.Name);

When creating a new test object that derives from INameable the property Name 
would be set.
It works, if you change the implementation of BuilderSetup.ShouldIgnoreProperty 
to:

  public static bool ShouldIgnoreProperty(PropertyInfo info)
  {
    if (disabledAutoNameProperties.Any(x => x.DeclaringType.IsInterface ? x.DeclaringType.IsAssignableFrom(info.DeclaringType) : x.DeclaringType == info.DeclaringType && x.Name == info.Name))
      return true;

    return false;
  }

Hope you consider using my change in a future release.

Original issue reported on code.google.com by michaelk...@gmail.com on 9 May 2012 at 10:00

GoogleCodeExporter commented 8 years ago
The changed implementation isn't working because of missing parentheses. This 
way it should work:
disabledAutoNameProperties.Any(x => (x.DeclaringType.IsInterface ? 
x.DeclaringType.IsAssignableFrom(info.DeclaringType) : x.DeclaringType == 
info.DeclaringType) && x.Name == info.Name)

Original comment by michaelk...@gmail.com on 9 May 2012 at 10:20