TypeConverters are lacking!!!
So, I'm using TypeConverter and UITypeEditors to work in a runtime scenario within my property grid like control...
Now this property grid like control is used to edit some arbitrary data that we have, and the user associates TypeConverters and UITypeEditors with their data fields using a simple config file...so in one place we have:
Field Data
Name = "FavouriteColour"
Type = "blah.fred.jones"
Value = 45, 45, 45
TypeConverter = "SomeTypeConverter"
UITypeEditor = "SomeUITypeEditor"
and in a config file somewhere, we have:
KeyedName = "SomeTypeConverter"
ActualName = "blah.fred.jones.OnlyTypeConverter"
...and something pretty similar for the UITypeEditor association too.
When the property grid like control is displaying, it get's the meta data associated with the field, and uses it to find the correct type converter instance by looking it up in a map.
So far so good. Now, I want to be able to verify ahead of time, that the user hasn't made a mistake in their config file or data, where they have specified a TypeConverter that doesn't have the same implicit type as the field.
Now, I would like to be able to write:
if (myTypeConverter.CanConverterFrom(null, theValue.GetType()))
DoSomething();
else
DoSomethingElse();
...however, the MS implemented type converters don't return true for the above test, when the type matches the implicit type!
Example:
float fBob=1.0f;
TypeConverter converter = TypeDescriptor.GetConverter(fBob);
bool bCanConvertertFrom = converter.CanConvertFrom(null, fBob.GetType());
bCanConvertFrom will return false, meaning that I can't use this test...but the type converter architecture doesn't provide any other way to find the implicit type...all it would take is the addition of a TypeConverter::GetImplicitType() and that would solve my problems...
The thing is, regardles of how I'm using this stuff, there's no way that MS's design time stuff can be performing the right checks...that is...they don't know that the TypeConverter that you've associated with your class using a TypeConverterAttribute derived class, actually has the same implicit type as the class you've associated it with!
So, the questions are:
1. Am I wrong or missing something?
- Please something better than, oh well, it was designed to work with property grids...there's still a hole in their implementation as I see it...
2. Are their implementations of CanConvertFrom() wrong?
- Use net reflector on their SingleConverter to see what I mean...
3. Is the architecture missing a GetImplicitType() method?
- Given a TypeConverter in isolation there is no way or knowing the implicit type.
...and on a related note...a problem exists with the UITypeEditors too, if you're trying to verify upfront that it will work with a given type...why? because there is no way to ask one if then are capable of working with a given type. The most you can do is call EditValue() and see if it throws an exception or returns null, and that's no good in validation code, because you're only try to catch problems up front...you don't want the editor to actually appear and start editing at that point!
Oh, and by the way, I'm using .net 1.1 and c#.
Thanks in advance for all help and replies!
Cheers,
T

