EnumConverter problem
-
I have the following enum:
\[TypeConverter(typeof(E1C))\] public enum E1 { a = 1, b = 2, c = 3 }
And the following converter:
public class E1C : EnumConverter { public E1C(): base(typeof(E1)) { } public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { if(value != null) { if(destinationType == typeof(string)) { if((E1)value == E1.a) { return "a a a"; } else if((E1)value == E1.b) { return "b b b"; } else if((E1)value == E1.c) { return "c c c"; } } if(destinationType == typeof(InstanceDescriptor)) { FieldInfo fi = EnumType.GetField(value.ToString()); if(fi != null) { return new InstanceDescriptor(fi, null); } } } return base.ConvertTo (context, culture, value, destinationType); } public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if(value != null && value is string) { if((string) value == "a a a") { return E1.a; } else if((string) value == "b b b") { return E1.b; } else if((string) value == "c c c") { return E1.c; } } return base.ConvertFrom (context, culture, value); } }
Now, on the property page every thing works fine, as well as in ASP .net page, but within Windows Form, the designer generates the folowing code:
#region Windows Form Designer generated code ... ... this.userControl11.E1 = WindowsApplication2.E1.b b b; ... ... #endregion
As you can see, instead of generating:
**this.userControl11.E1 = WindowsApplication2.E1.b;**
It generated:**this.userControl11.E1 = WindowsApplication2.E1.b b b;**
If anyone know this problem and its solution, it would be nice! Thanks in advance! Ilan -
I have the following enum:
\[TypeConverter(typeof(E1C))\] public enum E1 { a = 1, b = 2, c = 3 }
And the following converter:
public class E1C : EnumConverter { public E1C(): base(typeof(E1)) { } public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { if(value != null) { if(destinationType == typeof(string)) { if((E1)value == E1.a) { return "a a a"; } else if((E1)value == E1.b) { return "b b b"; } else if((E1)value == E1.c) { return "c c c"; } } if(destinationType == typeof(InstanceDescriptor)) { FieldInfo fi = EnumType.GetField(value.ToString()); if(fi != null) { return new InstanceDescriptor(fi, null); } } } return base.ConvertTo (context, culture, value, destinationType); } public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if(value != null && value is string) { if((string) value == "a a a") { return E1.a; } else if((string) value == "b b b") { return E1.b; } else if((string) value == "c c c") { return E1.c; } } return base.ConvertFrom (context, culture, value); } }
Now, on the property page every thing works fine, as well as in ASP .net page, but within Windows Form, the designer generates the folowing code:
#region Windows Form Designer generated code ... ... this.userControl11.E1 = WindowsApplication2.E1.b b b; ... ... #endregion
As you can see, instead of generating:
**this.userControl11.E1 = WindowsApplication2.E1.b;**
It generated:**this.userControl11.E1 = WindowsApplication2.E1.b b b;**
If anyone know this problem and its solution, it would be nice! Thanks in advance! Ilan