internal 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(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
                {
                    m_type = GetTypeFromString(text.Substring(num + 1).Trim().ToLowerInvariant());
                }
                catch (ArgumentException ex)
                {
                    throw new FormatException(ex.Message);
                }
            }
            else
            {
                if (defaultType == SizeTypes.Invalid)
                {
                    throw new FormatException(SRErrors.UnitParseNoUnit(value));
                }
                m_type = defaultType;
            }
            string text2 = text.Substring(0, num + 1);

            try
            {
                m_value = double.Parse(text2, provider);
            }
            catch
            {
                throw new FormatException(SRErrors.UnitParseNumericPart(value, text2, m_type.ToString("G")));
            }
        }
Example #3
0
        internal 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 void Init(string value)
        {
            int num = m_names.IndexOf(value);

            if (num < 0)
            {
                throw new ArgumentException(SRErrors.InvalidValue(value));
            }
            m_value = (T)Enum.ToObject(typeof(T), num);
        }
        internal static Color RdlStringToColor(string value)
        {
            if (value[0] == '#')
            {
                return(RgbStringToColor(value));
            }
            Color result = FromName(value);

            if (!result.IsKnownColor)
            {
                throw new ArgumentException(SRErrors.InvalidColor(value));
            }
            return(result);
        }
        private static Color RgbStringToColor(string value)
        {
            byte alpha = byte.MaxValue;

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

            if ((value.Length != 7 && value.Length != 9) || value[0] != '#')
            {
                flag = false;
            }
            else
            {
                string text = "abcdefABCDEF";
                for (int i = 1; i < value.Length; i++)
                {
                    if (!char.IsDigit(value[i]) && -1 == text.IndexOf(value[i]))
                    {
                        flag = false;
                        break;
                    }
                }
            }
            if (flag)
            {
                int num = 1;
                if (value.Length == 9)
                {
                    alpha = Convert.ToByte(value.Substring(num, 2), 16);
                    num  += 2;
                }
                byte red   = Convert.ToByte(value.Substring(num, 2), 16);
                byte green = Convert.ToByte(value.Substring(num + 2, 2), 16);
                byte blue  = Convert.ToByte(value.Substring(num + 4, 2), 16);
                return(Color.FromArgb(alpha, red, green, blue));
            }
            throw new ArgumentException(SRErrors.InvalidColor(value));
        }
Example #7
0
 public ArgumentTooSmallException(object component, string property, object value, object minimum)
     : base(component, property, value, minimum, SRErrors.InvalidParamGreaterThan(property, minimum))
 {
 }
 public ArgumentTooLargeException(object component, string property, object value, object maximum)
     : base(component, property, value, maximum, SRErrors.InvalidParamLessThan(property, maximum))
 {
 }
Example #9
0
 public void Validate(object component, int value)
 {
     if (m_validIntValues != null && !m_validIntValues.Contains(value))
     {
         object value2 = Enum.ToObject(m_type, value);
         throw new ArgumentConstraintException(component, base.Name, value2, null, SRErrors.InvalidParam(base.Name, value2));
     }
 }