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
{{ message }}
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.
The current implementation uses Convert.ChangeType which only handles types that implement IConvertible.
A small change to allow the use of TypeConverters would improve mapping values to other types.
e.g.
#if NET45||ASPNET50||ASPNETCORE50publicstaticTGet<T>(thisIConfigurationconfiguration,stringkey){vartype=typeof(T);varvalue=configuration.Get(key);
#if ASPNETCORE50return(T)Convert.ChangeType(value,type);
#elif NET45||ASPNET50if(typeof(IConvertible).IsAssignableFrom(type)){return(T)Convert.ChangeType(value,type);}else{varconverter=TypeDescriptor.GetConverter(type);if(converter==null)thrownewInvalidCastException("Could not find a valid TypeConverter for type "+type.FullName);return(T)converter.ConvertFromInvariantString(value);}
#endif
}
#endif
The text was updated successfully, but these errors were encountered:
Hey all, I guess with #199 in place, this can be closed?
Edit: Looks like the ConfigurationBinder has been moved into this project from Options. So the above still applies (but in the ConfigurationBinder class)
POCO binding was moved from Options into the Configuration repo recently (see #205). It is currently in Microsoft.Framework.ConfigurationModel although I think it is misplaced there (see #210). Regardless of the specific location, would any part of this improvement apply to the new code?
The current implementation uses
Convert.ChangeType
which only handles types that implementIConvertible
.A small change to allow the use of TypeConverters would improve mapping values to other types.
e.g.
The text was updated successfully, but these errors were encountered: