asiftasleem / nbuilder

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

Be able to ignore properties #79

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
ran into a nasty bit of code today I couldn't change that was specifically 
throwing not implemented exceptions.

Would be nice to be able to tell NBuilder to ignore properties like this.

Original issue reported on code.google.com by nathans....@gmail.com on 10 Nov 2011 at 12:41

GoogleCodeExporter commented 8 years ago
You can actually do this already, through the BuilderSetup class.

BuilderSetup.DisablePropertyNamingFor<MyClass>(x => x.TheProperty);

Is this satisfactory or would you expect it to be done inline e.g.

Builder<MyClass>.CreateNew().Ignore(x => x.TheProperty).Build() ?

Original comment by garethdo...@googlemail.com on 15 Nov 2011 at 2:24

GoogleCodeExporter commented 8 years ago
Its nice you can do it already but would prefer in the inline as it fits better 
with the existing fluent interface.  Plus if it uses the fluent type such as: 
Builder<MyClass>.CreateNew().Ignore(x => x.FormattedData).With(x => x.Data1 = 
"a").With(x => x.Data2 = "b").Build()  you can see at a glance all the 
instructions for building in one place.

Original comment by nathans....@gmail.com on 15 Nov 2011 at 2:42

GoogleCodeExporter commented 8 years ago
Disabling the property naming inline sounds like an interesting idea. I'd like 
to take a crack at implementing it.

Having looked at it briefly today I can see one possible issue that may need to 
be resolved.

Doing the Ignoring through the BuilderSetup makes it a bit more obvious to the 
user that they will need to use BuilderSetup.ResetToDefaults() to put the 
builder back to normal. I'm a bit concerned that having it inline may result in 
users forgetting to reset the builder. That said, it may be just as likely that 
they could forget it using the current approach too. Do you think this is a 
valid concern?

I think there are a couple of approaches, in no particular order, that we might 
take.

 1 Leave this feature the way it currently is
 2 Implement the Ignore and leave it to the user to remember to reset to the defaults
 3 Implement the Ignore and also implement a method that allows the user to remove the Ignore
 4 Implement the Ignore and modify the Build method to remove the inline Ignored properties. This way the inline ignore would be a relatively temporary ignore compared to the BuilderSetup ignore.
 5 Is there some option I haven't considered?

Thoughts?

Original comment by joshuajr...@gmail.com on 30 Nov 2011 at 10:27

GoogleCodeExporter commented 8 years ago
I think approach 4 is the way to go, its intuitive, fits the fluent interface 
and makes it easy to read the code to see what is being built.

If a user always wants to ignore a property then they could go down the 
BuilderSetup route but from my personal use I usually only define what I want 
at the time I want and not reuse build instructions.

Original comment by nathans....@gmail.com on 30 Nov 2011 at 11:15