Here is the background information:
*** *** *** *** *** *** *** ***
In order to display enum string values in my application with
localized values, I created a class called MyEnumConverter that
derives from EnumConverter and will convert To and From localized
string representations of an enum's values.
Now, every enum whose values I desire to be displayed as localized
strings have an attribute
[System.ComponentModel.TypeConverter(typeof(MyEnumC onverter))] added
to them where I tell .NET to use my type converter whenever it tries
to convert these enums to/from strings.
Next, I have a custom ExtenderProvider that extends one of these
"localizable" enums (see enum Unit below) as a property to any .Net
Control. This way, the controls will gain a new "Unit" property. My
ExtenderProvider is a component, so extension is made in the Designer
- not at run-time.
enum Unit
{
ShortDistance,
LongDistance
}
*** *** *** *** *** *** *** ***
Here is my problem:
My EnumConverter is interfering with the Designer-Generated code for
the extended Unit enum property. The English-US localized string
values for the two Unit enum values would be "Short Distance" and
"Long Distance" respectively (with spaces). When I extend the Unit
enum using my ExtenderProvider to a TextBox on my form called
"textBox1", it is supposed to receive a default value of
"ShortDistance" but the Designer-Generated code looks like this:
this.sperryUnitsExtender1.SetUnitGroup(this.textBo x1, UnitGroup.Short
Distance);
This will not compile because the enum name has been given the
localized string rather than the actual enum value name. I've narrowed
the problem to my EnumConverter, because if it's code is commented
out, the Designer-Generated code looks correct, like this:
this.sperryUnitsExtender1.SetUnitGroup(this.textBo x1,
UnitGroup.ShortDistance);
In MyEnumConverter, I use localized string values if the ConvertTo and
ConvertFrom is dealing with the Type of string (assuming it's for
display purposes). Well apparently, .NET is asking for "strings" when
it is creating the Designer-generated code from the control's property
grid, rather than asking for the actual Unit enum Type.
************************************************** ****
QUESTION:
How can I tell if the MyEnumConverter code is being exercised at
Design-Time or at Run-Time (so that I can use the localization
features at Run-Time and the default .NET TypeConverter at
Design-Time)? Is this even the correct way to fix this? Or, should
MyEnumConverter be smarter about it's conversion to localized strings?
Any help is much appreciated...
MattO