示例#1
0
        private void Init(string value, CultureInfo culture, RVUnitType defaultType)
        {
            if (culture == null)
            {
                culture = CultureInfo.CurrentCulture;
            }
            string text   = value.Trim().ToLower(culture);
            int    length = text.Length;
            int    num    = -1;

            for (int i = 0; i < length; i++)
            {
                char c = text[i];
                if ((c < '0' || c > '9') && c != '-' && c != '.' && c != ',')
                {
                    break;
                }
                num = i;
            }
            if (num == -1)
            {
                throw new FormatException();
            }
            if (num < length - 1)
            {
                this.m_type = RVUnit.GetTypeFromString(text.Substring(num + 1).Trim());
            }
            else
            {
                if (defaultType == (RVUnitType)0)
                {
                    throw new FormatException();
                }
                this.m_type = defaultType;
            }
            string text2 = text.Substring(0, num + 1);

            try
            {
                TypeConverter typeConverter = new SingleConverter();
                this.m_value = (double)(float)typeConverter.ConvertFromString(null, culture, text2);
            }
            catch (Exception ex)
            {
                Exception ex2 = RVUnit.FindStoppingException(ex);
                if (ex2 == ex)
                {
                    throw;
                }
                if (ex2 != null)
                {
                    throw ex2;
                }
                throw new FormatException();
            }
        }
示例#2
0
        public string ToString(CultureInfo culture)
        {
            if (this.IsEmpty)
            {
                return(string.Empty);
            }
            string str = this.m_value.ToString("0.#####", culture);

            return(str + RVUnit.GetStringFromType(this.m_type));
        }
示例#3
0
 private static Exception FindStoppingException(Exception e)
 {
     if (!(e is OutOfMemoryException) && !(e is ExecutionEngineException) && !(e is StackOverflowException) && !(e is ThreadAbortException))
     {
         Exception innerException = e.InnerException;
         if (innerException != null)
         {
             return(RVUnit.FindStoppingException(innerException));
         }
         return(null);
     }
     return(e);
 }
示例#4
0
 public static bool TryParse(string s, CultureInfo culture, out RVUnit rvUnit)
 {
     try
     {
         rvUnit = new RVUnit(s, culture);
         return(true);
     }
     catch (Exception ex)
     {
         Exception ex2 = RVUnit.FindStoppingException(ex);
         if (ex2 == ex)
         {
             throw;
         }
         if (ex2 != null)
         {
             throw ex2;
         }
         rvUnit = RVUnit.Empty;
         return(false);
     }
 }
示例#5
0
 public RVUnit(string value, CultureInfo culture)
 {
     this = new RVUnit(value, culture, RVUnit.DefaultType);
 }
示例#6
0
 public RVUnit(string value)
 {
     this = new RVUnit(value, CultureInfo.CurrentCulture, RVUnit.DefaultType);
 }
示例#7
0
 public static bool TryParse(string s, out RVUnit rvUnit)
 {
     return(RVUnit.TryParse(s, (CultureInfo)null, out rvUnit));
 }