Esempio n. 1
0
 ///<summary>
 /// Convert a string into an amount and a font size type that can be used to create
 /// and instance of a Fontsize, or to serialize in a more compact representation to
 /// a baml stream.
 ///</summary>
 internal static void FromString(
     string text,
     CultureInfo culture,
     out double amount)
 {
     amount = LengthConverter.FromString(text, culture);
 }
Esempio n. 2
0
        // Token: 0x06000C56 RID: 3158 RVA: 0x0002DEF8 File Offset: 0x0002C0F8
        internal static Thickness FromString(string s, CultureInfo cultureInfo)
        {
            TokenizerHelper tokenizerHelper = new TokenizerHelper(s, cultureInfo);

            double[] array = new double[4];
            int      num   = 0;

            while (tokenizerHelper.NextToken())
            {
                if (num >= 4)
                {
                    num = 5;
                    break;
                }
                array[num] = LengthConverter.FromString(tokenizerHelper.GetCurrentToken(), cultureInfo);
                num++;
            }
            switch (num)
            {
            case 1:
                return(new Thickness(array[0]));

            case 2:
                return(new Thickness(array[0], array[1], array[0], array[1]));

            case 4:
                return(new Thickness(array[0], array[1], array[2], array[3]));
            }
            throw new FormatException(SR.Get("InvalidStringThickness", new object[]
            {
                s
            }));
        }
 /// <summary>Converts instances of other data types into instances of <see cref="T:System.Double" /> that represent an object's length. </summary>
 /// <param name="typeDescriptorContext">Provides contextual information about a component.</param>
 /// <param name="cultureInfo">Represents culture-specific information that is maintained during a conversion.</param>
 /// <param name="source">Identifies the object that is being converted to <see cref="T:System.Double" />.</param>
 /// <returns>An instance of <see cref="T:System.Double" /> that is the value of the conversion.</returns>
 /// <exception cref="T:System.ArgumentNullException">Occurs if the <paramref name="source" /> is <see langword="null" />.</exception>
 /// <exception cref="T:System.ArgumentException">Occurs if the <paramref name="source" /> is not <see langword="null" /> and is not a valid type for conversion.</exception>
 // Token: 0x06000756 RID: 1878 RVA: 0x00016D4E File Offset: 0x00014F4E
 public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object source)
 {
     if (source == null)
     {
         throw base.GetConvertFromException(source);
     }
     if (source is string)
     {
         return(LengthConverter.FromString((string)source, cultureInfo));
     }
     return(Convert.ToDouble(source, cultureInfo));
 }
        static internal Thickness FromString(string s, CultureInfo cultureInfo)
        {
            TokenizerHelper th = new TokenizerHelper(s, cultureInfo);

            double[] lengths = new double[4];
            int      i       = 0;

            // Peel off each double in the delimited list.
            while (th.NextToken())
            {
                if (i >= 4)
                {
                    i = 5;    // Set i to a bad value.
                    break;
                }

                lengths[i] = LengthConverter.FromString(th.GetCurrentToken(), cultureInfo);
                i++;
            }

            // We have a reasonable interpreation for one value (all four edges), two values (horizontal, vertical),
            // and four values (left, top, right, bottom).
            switch (i)
            {
            case 1:
                return(new Thickness(lengths[0]));

            case 2:
                return(new Thickness(lengths[0], lengths[1], lengths[0], lengths[1]));

            case 4:
                return(new Thickness(lengths[0], lengths[1], lengths[2], lengths[3]));
            }

            throw new FormatException(SR.Get(SRID.InvalidStringThickness, s));
        }