Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Knowing string value, can we know the actual data type?
Message
 
 
General information
Forum:
ASP.NET
Category:
XML
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01567536
Message ID:
01567584
Views:
18
>>I am wondering if there is a way to figure out a type based on the string represenation and also check if it's empty or not (for that type)?
>>
>>Thanks in advance.
>
>From the other thread it looks as if you may no longer need an answer to this. But the short answer is 'no' - unless you have the relavent XSL for the file or an attribute on the element defining the type.

When discussing with my colleague we were thinking of having a dictionary of columns with their types. This way I could have checked based on the tagname.

For now I opted for this simple implementation
 /// <summary>
      /// Tests if string representation of data is empty
      /// </summary>
      /// <param name="input"></param>
      /// <returns></returns>
      public static Boolean IsValueEmpty(this String input)
      {
         Boolean returnValue = false;

         if (String.IsNullOrEmpty(input))
            returnValue = true;
         else
         {
            if ("false" == input.ToLower()) // Boolean false
               returnValue = true;
            else
            {
               Double testValue;
               if (Double.TryParse(input, out testValue) && 0 == testValue)
                  returnValue = true;
            }
         }

         return returnValue; 
      }
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform