Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Knowing string value, can we know the actual data type?
Message
 
 
À
06/03/2013 03:40:50
Information générale
Forum:
ASP.NET
Catégorie:
XML
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01567536
Message ID:
01567584
Vues:
19
>>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform