Exemple #1
0
        private bool GetUnitValue(IDictionary properties, string keyIndex, ref Unit unitValue)
        {
            string str = properties[keyIndex] as string;

            if (string.IsNullOrEmpty(str))
            {
                return(false);
            }
            try
            {
                unitValue = Unit.Parse(str, CultureInfo.InvariantCulture);
            }
            catch
            {
                throw new FormatException(System.Web.SR.GetString("AdRotator_invalid_integer_format", new object[] { str, keyIndex, typeof(Unit).FullName }));
            }
            return(true);
        }
        private bool GetUnitValue(IDictionary properties, String keyIndex, ref Unit unitValue)
        {
            Debug.Assert(properties != null);

            string temp = properties[keyIndex] as string;

            if (!String.IsNullOrEmpty(temp))
            {
                try {
                    unitValue = Unit.Parse(temp, CultureInfo.InvariantCulture);
                }
                catch {
                    throw new FormatException(
                              SR.GetString(SR.AdRotator_invalid_integer_format, temp, keyIndex, typeof(Unit).FullName));
                }
                return(true);
            }
            return(false);
        }
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value == null)
            {
                return(null);
            }
            string str = value as string;

            if (str == null)
            {
                return(base.ConvertFrom(context, culture, value));
            }
            string s = str.Trim();

            if (s.Length == 0)
            {
                return(Unit.Empty);
            }
            if (culture != null)
            {
                return(Unit.Parse(s, culture));
            }
            return(Unit.Parse(s, CultureInfo.CurrentCulture));
        }