-
-
Notifications
You must be signed in to change notification settings - Fork 837
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
TypeConverters on Properties are not used #445
Comments
From travis.illig on June 21, 2013 07:28:00 Labels: -Type-Defect Type-Enhancement Module-Configuration |
From countpri...@gmail.com on June 21, 2013 08:15:43 It should be TypeConverterAttribute, not TypeConverter in the sample code. Then get the TypeConverter from the attribute. (I'm not aware of a TypeDescriptor helper that will get the TypeConverter for a property.) |
From travis.illig on August 12, 2013 08:09:36 Status: Started |
From travis.illig on August 12, 2013 10:31:05 Added support for parameters and properties to provide specific TypeConverter information using TypeConverterAttribute. Due to the way the attribute works, when using list or dictionary properties in XML, the specific TypeConverter implementation needs to actually convert the full list or dictionary from the ListElementCollection or DictionaryElementCollection (respectively), not just the element type. Examples of all of these can be seen in the unit tests. I'll push the changes shortly. |
From travis.illig on August 12, 2013 10:37:44 This issue was closed by revision 20711b9288fd . Status: Fixed |
From countpri...@gmail.com on June 21, 2013 08:14:19
The TypeManipulation.ChangeToCompatibleType call looks for a TypeConverter defined on the target data type. However, it is also possible to define them on properties directly. This is useful for built-in .NET types (like IPAddress) where you want a to/from string converter. To use these converters, modify the PropertyElementCollection to look like this:
(pi, c) =>
{
var value = localParameter.CoerceValue();
PropertyInfo prop;
if (pi.TryGetDeclaringProperty(out prop))
{
foreach (var converter in prop.GetCustomAttributes(typeof(TypeConverter), false).Cast())
{
if (converter.CanConvertTo(pi.ParameterType))
return converter.ConvertTo(value, pi.ParameterType);
}
}
return TypeManipulation.ChangeToCompatibleType(value, pi.ParameterType);
});
Original issue: http://code.google.com/p/autofac/issues/detail?id=445
The text was updated successfully, but these errors were encountered: