public static SizeTypes GetTypeFromString(string value)
 {
     if (value != null && value.Length > 0)
     {
         if (value.Equals("pt"))
         {
             return(SizeTypes.Point);
         }
         if (value.Equals("pc"))
         {
             return(SizeTypes.Pica);
         }
         if (value.Equals("in"))
         {
             return(SizeTypes.Inch);
         }
         if (value.Equals("mm"))
         {
             return(SizeTypes.Mm);
         }
         if (value.Equals("cm"))
         {
             return(SizeTypes.Cm);
         }
         throw new ArgumentException(SRErrors.InvalidUnitType(value));
     }
     return(ReportSize.DefaultType);
 }
        private void Init(string value, IFormatProvider provider, SizeTypes defaultType)
        {
            if (provider == null)
            {
                provider = CultureInfo.CurrentCulture;
            }
            string           text             = value.Trim();
            int              length           = text.Length;
            NumberFormatInfo numberFormatInfo = provider.GetFormat(typeof(NumberFormatInfo)) as NumberFormatInfo;

            if (numberFormatInfo == null)
            {
                numberFormatInfo = CultureInfo.InvariantCulture.NumberFormat;
            }
            int num = -1;

            for (int i = 0; i < length; i++)
            {
                char c = text[i];
                if (!char.IsDigit(c) && c != numberFormatInfo.NegativeSign[0] && c != numberFormatInfo.NumberDecimalSeparator[0] && c != numberFormatInfo.NumberGroupSeparator[0])
                {
                    break;
                }
                num = i;
            }
            if (num == -1)
            {
                throw new FormatException(SRErrors.UnitParseNoDigits(value));
            }
            if (num < length - 1)
            {
                try
                {
                    this.m_type = ReportSize.GetTypeFromString(text.Substring(num + 1).Trim().ToLowerInvariant());
                }
                catch (ArgumentException ex)
                {
                    throw new FormatException(ex.Message);
                }
                goto IL_00f1;
            }
            if (defaultType != 0)
            {
                this.m_type = defaultType;
                goto IL_00f1;
            }
            throw new FormatException(SRErrors.UnitParseNoUnit(value));
IL_00f1:
            string text2 = text.Substring(0, num + 1);

            try
            {
                this.m_value = double.Parse(text2, provider);
            }
            catch
            {
                throw new FormatException(SRErrors.UnitParseNumericPart(value, text2, ((Enum)(object)this.m_type).ToString("G")));
            }
        }
        private void Init(string value)
        {
            int num = ReportEnum <T> .m_names.IndexOf(value);

            if (num < 0)
            {
                throw new ArgumentException(SRErrors.InvalidValue(value));
            }
            this.m_value = (T)Enum.ToObject(typeof(T), num);
        }
Example #4
0
        public static object ParseEnum(Type type, string value)
        {
            int num = Array.IndexOf(Enum.GetNames(type), value);

            if (num < 0)
            {
                throw new ArgumentException(SRErrors.InvalidValue(value));
            }
            return(Enum.GetValues(type).GetValue(num));
        }
        private static Color RgbStringToColor(string value)
        {
            byte alpha = 255;

            if (value == "#00ffffff")
            {
                return(Color.Transparent);
            }
            if (value == "#00000000")
            {
                return(Color.Empty);
            }
            bool flag = true;

            if (value.Length != 7 && value.Length != 9)
            {
                goto IL_004d;
            }
            if (value[0] != '#')
            {
                goto IL_004d;
            }
            string text = "abcdefABCDEF";
            int    num  = 1;

            while (num < value.Length)
            {
                if (char.IsDigit(value[num]) || -1 != text.IndexOf(value[num]))
                {
                    num++;
                    continue;
                }
                flag = false;
                break;
            }
            goto IL_0094;
IL_0094:
            if (flag)
            {
                int num2 = 1;
                if (value.Length == 9)
                {
                    alpha = Convert.ToByte(value.Substring(num2, 2), 16);
                    num2 += 2;
                }
                byte red   = Convert.ToByte(value.Substring(num2, 2), 16);
                byte green = Convert.ToByte(value.Substring(num2 + 2, 2), 16);
                byte blue  = Convert.ToByte(value.Substring(num2 + 4, 2), 16);
                return(Color.FromArgb(alpha, red, green, blue));
            }
            throw new ArgumentException(SRErrors.InvalidColor(value));
IL_004d:
            flag = false;
            goto IL_0094;
        }
 public ArgumentTooLargeException(object component, string property, object value, object maximum)
     : base(component, property, value, maximum, SRErrors.InvalidParamLessThan(property, maximum))
 {
 }
 public ArgumentTooSmallException(object component, string property, object value, object minimum)
     : base(component, property, value, minimum, SRErrors.InvalidParamGreaterThan(property, minimum))
 {
 }
        public void Validate(object component, int value)
        {
            if (this.m_validIntValues == null)
            {
                return;
            }
            if (this.m_validIntValues.Contains(value))
            {
                return;
            }
            object value2 = Enum.ToObject(this.m_type, value);

            throw new ArgumentConstraintException(component, base.Name, value2, null, SRErrors.InvalidParam(base.Name, value2));
        }