ChrisMissal / Formo

Formo allows you to use your configuration file as a dynamic object. Turn your web.config or application settings into a rich, dynamic object.
http://chrismissal.com/Formo/
MIT License
259 stars 33 forks source link

Improve fallback values syntax with "Or" #16

Closed ChrisMissal closed 11 years ago

ChrisMissal commented 11 years ago

Instead of using:

config.RetryAttempts(5);

for a fallback default, consider:

config.RetryAttemptsOr(5);

or

config.RetryAttempts.Or(5);

I'm not sure which I like more.

gmasselli commented 11 years ago

If you're trying to make it a "fluent interface" I'd prefer the last example. However, "Or" implies some type of conditional statement to invoke the "Or" path, like an out-of-range configuration value.

Personally I find the "Or" syntax vague for default or fallback values. Consider:

config.RetryAttempts.DefaultTo(5);

or

config.DefaultTo(5).RetryAttempts();
ChrisMissal commented 11 years ago

I'm a bit on the fence about this feature because you could simple do this as:

config.RetryAttempts ?? 5;

It's already built into the language so adding something like .DefaultsTo() would basically be that one line.

ChrisMissal commented 11 years ago

Not enough interest