asiftasleem / nbuilder

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

BuilderSetup.SetPropertyNamerFor<T> does not prevent auto naming properties of some types (probably nesting or something with generics) #20

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Downaload SharpArch's binaries from
http://code.google.com/p/sharp-architecture/ and include them in your project
2. Create your own "Foo" Class that derives from Entity
3. Create a test:
{
 BuilderSetup.DisablePropertyNamingFor<Foo, int>(x => x.Id);
 var output = Builder<Product>.CreateNew().Build().Id;

What is the expected output? What do you see instead?
output = 0; instead: output = 1.

What version of the product are you using? On what operating system?
2.1.8, Vista

Please provide any additional information below.
SharpArch's Entity is inheritance tree looks like this: 

IEntityWithTypedId<TId> (Contains definition: Idt Id { get; }
  -> EntityWithTypedId<IdT> ( contains: public virtual IdT { get; protected
set;}
     -> Entity 
          -> Your custom class like Foo

The problem is with ShouldIgnoreProperty method on BuilderSetup class which
only checks whether propertyInfo that is being currently examined exists in
the disabledAutoNameProperties collection. It uses default Contains()
method on it and I see no comparer specified explicitly, so that means, the
Equals() method of PropertyInfo class is being used to determine equality.
Reflector didn't show me any Equals implementation neither PropertyInfo
class or any base class that derives from. 

I do not really understand why for normal classes (not derived from those
SharpArch's Core) current implementation works, however I this couple of
lines solves my problem:

public static bool ShouldIgnoreProperty(PropertyInfo info)
        {
            foreach(var propertyInfo in disabledAutoNameProperties)
            {
                if (propertyInfo.Name.Equals(info.Name) &&
                    propertyInfo.PropertyType.Equals(info.PropertyType) &&
                    propertyInfo.DeclaringType == propertyInfo.DeclaringType)
                    return true;
            }

            return false;
        }

Original issue reported on code.google.com by lukasz.p...@gmail.com on 22 Jun 2009 at 5:50

Attachments:

GoogleCodeExporter commented 8 years ago
Hi,

Very sorry that it's taken me so long to respond to this.

I've just applied the patch but it doesn't include the test. Any chance you 
could
include the test in the patch?

Thanks

Original comment by garethdo...@googlemail.com on 15 Jul 2009 at 6:49

GoogleCodeExporter commented 8 years ago
Hello,

I had this exact same problem and successfully used the patch to get around it. 
I
noticed that you requested a test for the patch and since I really like your 
tool, I
created a new patch with a unit test included that demonstrates the problem the 
patch
fixes.

Thanks for the great tool.

Original comment by bobby.jo...@gmail.com on 30 Jul 2009 at 3:30

Attachments:

GoogleCodeExporter commented 8 years ago
Integrated, released in 2.1.9 beta.

Original comment by garethdo...@googlemail.com on 20 Oct 2009 at 8:21