28using System.ComponentModel;
30#if !CompactFramework && !WindowsCE && !PocketPC && !XBOX360 && !SILVERLIGHT && !WINDOWS_PHONE && !NETFX_CORE
31using System.ComponentModel.Design.Serialization;
37#if !CompactFramework && !WindowsCE && !PocketPC && !XBOX360 && !SILVERLIGHT && !WINDOWS_PHONE && !NETFX_CORE
47 Type t = typeof(TType);
52 this.instanceNoArgsCtor = t.GetConstructor(Type.EmptyTypes);
54 if (this.instanceCtor !=
null)
56 ParameterInfo[] paraminfos =
instanceCtor.GetParameters();
62 PropertyDescriptor descriptor =
descriptions.Find(name,
false);
63 if (descriptor ==
null || descriptor.PropertyType != paraminfos[index].ParameterType)
77 public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
80 (
parse !=
null && sourceType == typeof(
string) ) ||
81 base.CanConvertFrom(context, sourceType);
83 public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
87 destinationType == typeof(InstanceDescriptor)) ||
88 base.CanConvertTo(context, destinationType);
95 base.GetCreateInstanceSupported(context);
101 base.GetPropertiesSupported(context);
107 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture,
object value)
109 if (
parse !=
null && value is
string)
113 return parse.Invoke(
null,
new object[] { value });
115 catch (TargetInvocationException ex)
117 throw ex.InnerException;
120 return base.ConvertFrom(context, culture, value);
122 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture,
object value, Type destinationType)
124 if (value is TType &&
125 destinationType == typeof(InstanceDescriptor))
136 return base.ConvertTo(context, culture, value, destinationType);
139 public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues)
143 PropertyDescriptor propertyDescriptor = context.Instance as PropertyDescriptor;
144 object result =
null;
148 foreach (
string name
in propertyValues.Keys)
150 descriptions.Find(name,
false).SetValue(result, propertyValues[name]);
159 if (propertyDescriptor !=
null)
161 propertyDescriptor.SetValue(
null, result);
166 catch (TargetInvocationException ex) {
throw ex.InnerException; }
167 return base.CreateInstance(context, propertyValues);
169 public override PropertyDescriptorCollection
GetProperties(ITypeDescriptorContext context,
object value, Attribute[] attributes)
171 if (this.descriptions !=
null)
175 return base.GetProperties(context, value, attributes);
189 if (value is IDictionary)
197 rv[index] = descriptor.GetValue(value);
static PropertyDescriptorCollection GetDispMembers(Type t)
override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
ConstructorInfo instanceNoArgsCtor
override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
override bool GetCreateInstanceSupported(ITypeDescriptorContext context)
override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues)
object[] GetInstanceDescriptorObjects(IDictionary propertyValues)
override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
ConstructorInfo instanceCtor
object[] GetInstanceDescriptorObjects(object value)
PropertyDescriptorCollection descriptions
string[] instanceCtorParamNames
override bool GetPropertiesSupported(ITypeDescriptorContext context)
override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
static ConstructorInfo GetConstructor(Type t, out string[] paramNames)
static MethodInfo GetParseMethod(Type t)