PC Review


Reply
Thread Tools Rate Thread

What data type is this?

 
 
=?Utf-8?B?YmF5bG9y?=
Guest
Posts: n/a
 
      23rd Jun 2005
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?YmF5bG9y?=
Guest
Posts: n/a
 
      23rd Jun 2005
By the way, here's the code i'm using. Just want to know if there's a more
elegant way to do this:

bool isExpectedType = true;
switch (criteria.DataType)
{
case TypeCode.Single:
try { float temp = float.Parse(value); }
catch (FormatException ex) { isExpectedType = false; }
return isExpectedType;

 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      23rd Jun 2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert a Number data type to a Text data type TKM Microsoft Access Queries 9 6th Nov 2008 10:59 PM
Data Type Mismatch in Expression - can I force a query to read as a diferent data type? S Davis Microsoft Access Queries 1 8th Jun 2007 12:33 AM
Append Data Type Text Y/N to Data Type Y/N in Query HELP! =?Utf-8?B?dHJveQ==?= Microsoft Access Queries 1 25th Apr 2006 02:11 AM
Change Memo data type to Text data type DS Microsoft Access Getting Started 1 26th Jan 2005 05:56 PM
Convert String Data Type to UniqueIdentifier data type =?Utf-8?B?YW5n?= Microsoft ADO .NET 4 26th Jan 2004 11:58 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:44 AM.