Is there a way I can configure the MidPointRounding enumeration default setting in a config file (I.e. web.config or app.config) I have a considerable source code base, and I need to configure at the application scope how rounding will occur, whether used in Math.Round or decimal type rounding... I would like to do this in order to get consistent rounding results throughout the application without changing every line that works with a decimal type or uses Math.Round....
A:
Enum.Parse() is your friend here
MyEnum GetEnumValue(string enumString) {
return (MyEnum)Enum.Parse(typeof(MyEnum),enumString);
}
Obviously you'd also need some error-checking on the string you're getting from you're config file in which case you might want to return a default.
rohancragg
2008-09-15 16:07:36
+1
A:
You can play games with post-compile tools that alter the assembly to call your function instead of Math.Round. However, I would just bite the bullet and change the source code.
Jonathan Allen
2008-10-06 05:55:20