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

Add Binding Support for Period Separated Keys #26

Closed abombss closed 10 years ago

abombss commented 10 years ago

A common convention is to use period separated strings. Looking for keys with the following might be useful, not sure if it breaks backwards compat.

DeclaringType.Name + "." + PropertyInfo.Name
DeclaringType.FullName + "." + PropertyInfo.Name
ChrisMissal commented 10 years ago

I like this idea, but I don't know exactly how it should work. Take the following example:

dynamic config = new Configuration();
var value = config.SettingsClass.PropertyValue;

What should the default behavior be when SettingsClass isn't defined in the config file? If it's not found, currently, null is returned and then a NullReferenceException is thrown on PropertyValue.

I think the best option is to throw a custom exception, but I really try to make Formo fall back to sensible defaults and require try/catches.

I'm open to any ideas or thoughts on this.

abombss commented 10 years ago

Interesting, i wasn't thinking that use case, i was just thinking it would only work for bind for exactly that reason.

I might have to think about that use case.

Adam On Jan 26, 2014 6:40 PM, "Chris Missal" notifications@github.com wrote:

I like this idea, but I don't know exactly how it should work. Take the following example:

dynamic config = new Configuration(); var value = config.SettingsClass.PropertyValue;

What should the default behavior be when SettingsClass isn't defined in the config file? If it's not found, currently, null is returned and then a NullReferenceException is thrown on PropertyValue.

I think the best option is to throw a custom exception, but I really try to make Formo fall back to sensible defaults and require try/catches.

I'm open to any ideas or thoughts on this.

— Reply to this email directly or view it on GitHubhttps://github.com/ChrisMissal/Formo/issues/26#issuecomment-33335832 .

keichinger commented 10 years ago

With the upcoming null propagating C# language feature this might be worth another look.

https://roslyn.codeplex.com/discussions/540883

ChrisMissal commented 10 years ago

Hey all, how are we feeling about this?