baylor <(E-Mail Removed)> wrote:
> This is probably an easy question but i apparently can't find the right
> Google key words
>
> i am passed a string and the name of the data type i'm hoping that string is
> (technically, i'm passed a System.TypeCode). My job is to verify that the
> item really is a valid bool value, int, single, whatever
>
> Not quite seeing what i want in reflection. Thought the various datatype
> .Parse methods would work but not directly. Maybe i could try Parse and catch
> the FormatException but i'm wondering if there's a more direct approach
You can use Convert.ChangeType to try to convert it to the right type,
but that will probably use the current culture etc, which may not be
what you're after. (You'd then have to catch the exception generated if
it the value was incorrect.)
--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too