Kevin
Fri Sep 22 17:32:41 CDT 2006
What do you mean by "convert a String to a Type?" Are you referring to
converting a string to the type "System.Type?" You didn't mention any other
type, and your example uses "typeof(Type)" which seems to bear this out. If
so, you are barking way up the wrong tree. A string can not be converted to
the type "System.Type". To convert one type to another, the data must be
consistent with the type being converted to. A string can be converted, for
example, to an array, because it IS an array. It can be converted to a
number if the characters in the string can be read as a number (as in
"123.456"). But the System.Type class has nothing in common with any string.
Perhaps you could tell us what requirement you're trying to fulfill, and we
can help you get there.
--
HTH,
Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com
A watched clock never boils.
"Keith Patrick" <richard_keith_patrick@nospam.hotmail.com> wrote in message
news:e%23ZKaYo3GHA.5032@TK2MSFTNGP04.phx.gbl...
> Does anyone know of a way (without looking through decompiled ASP.Net
> code) to convert a String to a Type using the generic TypeConverter stuff?
> I am writing a deserializer, but I would prefer not to have a custom
> codepath just for String->Type, but the following code throws a
> NotSupportedException:
>
>
> TypeDescriptor.GetConverter(typeof(Type)).ConvertFrom("System.String")
>
> The problem with the above code is that GetConverter returns the base
> TypeDescriptor, which always throws an exception on ConvertFrom, but I'm
> not aware of any gneeric codepaths to do this that don't involve
> typedescriptors
>