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(); } }
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)); }
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); }
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); } }
public RVUnit(string value, CultureInfo culture) { this = new RVUnit(value, culture, RVUnit.DefaultType); }
public RVUnit(string value) { this = new RVUnit(value, CultureInfo.CurrentCulture, RVUnit.DefaultType); }
public static bool TryParse(string s, out RVUnit rvUnit) { return(RVUnit.TryParse(s, (CultureInfo)null, out rvUnit)); }