I canβt say whether this will work or not, since I have not tested it. However, if it does not work, you can try using TypeConverter for your DataWrapper type.
For instance:
[TypeConverter(typeof(DataWrapperConverter))] public class DataWrapper { ... } public class DataWrapperConverter : TypeConverter { public override bool CanConvertFrom(ITypeDescriptorContext context, System.Type sourceType) { return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); } public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (value is string) { return (DataWrapper<string>)value; } return base.ConvertFrom(context, culture, value); } }
You can use the general helper methods of the Type class to more dynamically convert your type.
source share