You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ClassStructBinder sets values from ISettingNode recursively to provided default value. So it can change even some static readonly field of another class.
For example:
So, if we provide object source to ConfigurationProvider:
configurationProvider.SetupSourceFor<AppSettings>(new ObjectSource(new AppSettings(){DefaultFormat=new MessageFormat(){Format="A"},SpecificFormat=new MessageFormat(){Format="B"}}));varsettings= provider.Get<AppSettings>();
Console.WriteLine(settings.DefaultFormat.Format);// B
Console.WriteLine(settings.SpecificFormat.Format);// B
Console.WriteLine(MessageFormat.Default.Format);// B
Maybe ConfigurationProvider should create object copy instead of changing existing object or even throw any exception, or print warning about this issue
The text was updated successfully, but these errors were encountered:
This code is wrong even without ConfigurationProvider:
auto settings1 = new MessageFormat();
settings1.SpecificFormat.Format = "B";
auto settings2 = new MessageFormat();
Console.WriteLine(settings.SpecificFormat.Format); // B
Or do you really expect that behaviour if you see that code?
Maybe some users expect that ConfigurationProvider copy an object and call setters on it instead of changing the orgin. For example this case appeared recently: user had set a default value and could not understand why another object changed too. I think we should at least warn users about this non-obvious behavior in some way. Or just copy an object before set values
ClassStructBinder sets values from ISettingNode recursively to provided default value. So it can change even some static readonly field of another class.
For example:
So, if we provide object source to ConfigurationProvider:
Maybe ConfigurationProvider should create object copy instead of changing existing object or even throw any exception, or print warning about this issue
The text was updated successfully, but these errors were encountered: