Azavea.Open.DAO.CSV.CsvDaLayer.CoerceType C# (CSharp) Méthode

CoerceType() public méthode

Overridden to handle the case of converting an empty string to a non-string datatype. It's a slow check because you have to trim, and check type, etc, which is why it isn't in the base class. But CSV files apparently frequently use "" for blank numerical values which causes the base class implementation to error out.
public CoerceType ( Type desiredType, object input ) : object
desiredType System.Type Type we need the value to be.
input object Input value, may or may not already be the right type.
Résultat object
        public override object CoerceType(Type desiredType, object input)
        {
            try
            {
                // If we're on a non-string data type,
                // treat a blank string as a null.
                if (!desiredType.Equals(typeof (string)) &&
                    (input != null) &&
                    (input is string) &&
                    (((string) input).Trim().Length == 0))
                {
                    return null;
                }
            }
            catch (Exception e)
            {
                throw new DaoTypeCoercionException(desiredType, input, e);
            }
            return base.CoerceType(desiredType, input);
        }