示例#1
0
        /// //////////////////////////////////////////////
        public override void TraiteDouble(ref double fVal)
        {
            switch (Mode)
            {
            case ModeSerialisation.Ecriture:
                WriteString(fVal.ToString(CultureInfo.InvariantCulture));
                break;

            case ModeSerialisation.Lecture:
                fVal = CUtilDouble.DoubleFromString(ReadString());
                break;
            }
        }
示例#2
0
 public static object FromUniversalString(string strValue, Type type)
 {
     if (strValue == c_strConstNull)
     {
         return(null);
     }
     try
     {
         if (type == typeof(SByte) || type == typeof(SByte?))
         {
             return(SByte.Parse(strValue, CultureInfo.CurrentCulture));
         }
         else if (type == typeof(Int16) || type == typeof(Int16?))
         {
             return(Int16.Parse(strValue, CultureInfo.CurrentCulture));
         }
         else if (type == typeof(Int32) || type == typeof(Int32?))
         {
             return(Int32.Parse(strValue, CultureInfo.CurrentCulture));
         }
         else if (type == typeof(Int64) || type == typeof(Int64?))
         {
             return(Int64.Parse(strValue, CultureInfo.CurrentCulture));
         }
         else if (type == typeof(Byte) || type == typeof(Byte?))
         {
             return(Byte.Parse(strValue, CultureInfo.CurrentCulture));
         }
         else if (type == typeof(UInt16) || type == typeof(UInt16?))
         {
             return(UInt16.Parse(strValue, CultureInfo.CurrentCulture));
         }
         else if (type == typeof(UInt32) || type == typeof(UInt32?))
         {
             return(UInt32.Parse(strValue, CultureInfo.CurrentCulture));
         }
         else if (type == typeof(UInt64) || type == typeof(UInt64?))
         {
             return(UInt64.Parse(strValue, CultureInfo.CurrentCulture));
         }
         else if (type == typeof(Single) || type == typeof(Single?))
         {
             try
             {
                 return(Single.Parse(strValue, CultureInfo.CurrentCulture));
             }
             catch
             {
                 if (strValue.IndexOf('.') >= 0)
                 {
                     strValue = strValue.Replace('.', ',');
                 }
                 else
                 {
                     strValue = strValue.Replace(',', '.');
                 }
                 return(Single.Parse(strValue, CultureInfo.CurrentCulture));
             }
         }
         else if (type == typeof(Double) || type == typeof(Double?))
         {
             return(CUtilDouble.DoubleFromString(strValue));
         }
         else if (type == typeof(Decimal) || type == typeof(Decimal?))
         {
             try
             {
                 return(Decimal.Parse(strValue, CultureInfo.CurrentCulture));
             }
             catch
             {
                 if (strValue.IndexOf('.') >= 0)
                 {
                     strValue = strValue.Replace('.', ',');
                 }
                 else
                 {
                     strValue = strValue.Replace(',', '.');
                 }
                 return(Decimal.Parse(strValue, CultureInfo.CurrentCulture));
             }
         }
         else if (type == typeof(Boolean) || type == typeof(Boolean?))
         {
             return(strValue == "1");
         }
         else if (type == typeof(Char) || type == typeof(Char?))
         {
             if (strValue.Length > 0)
             {
                 return(strValue[0]);
             }
             return('\0');
         }
         else if (type == typeof(String))
         {
             if (strValue == "@" + c_strConstNull)
             {
                 return(c_strConstNull);
             }
             return(strValue);
         }
         else if (type == typeof(DateTime) || type == typeof(DateTime?))
         {
             return(CUtilDate.FromUniversalString(strValue));
         }
         else if (type == typeof(CDateTimeEx))
         {
             return(new CDateTimeEx(CUtilDate.FromUniversalString(strValue)));
         }
     }
     catch
     {
         return(null);
     }
     throw new Exception(I.T("Unknown type for ToUniversalString |30107") + type.ToString());
 }