SuperMap.WindowsPhone.Core.Point2DConverter.ConvertFrom C# (CSharp) Method

ConvertFrom() public method

${WP_core_Point2DConverter_method_ConvertFrom_D}
public ConvertFrom ( ITypeDescriptorContext context, CultureInfo culture, object value ) : object
context ITypeDescriptorContext ${WP_core_Point2DConverter_method_ConvertFrom_param_context}
culture System.Globalization.CultureInfo ${WP_core_Point2DConverter_method_ConvertFrom_param_culture}
value object ${WP_core_Point2DConverter_method_ConvertFrom_param_value}
return object
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string str = value as string;
            if (str != null)
            {
                string[] strArray = str.Split(new char[] { ',' });
                if (2 == strArray.Length)
                {
                    return new Point2D(double.Parse(strArray[0], CultureInfo.InvariantCulture), double.Parse(strArray[1], CultureInfo.InvariantCulture));
                }
            }
            throw new ArgumentException(SuperMap.WindowsPhone.Resources.ExceptionStrings.TextParseFailed, "value");
            //TODO:资源 Text Parse Failed
        }
    }

Usage Example

 /// <summary>${WP_core_Point2DCollectionConverter_method_ConvertFrom_D}</summary>
 /// <param name="value">${WP_core_Point2DCollectionConverter_method_ConvertFrom_param_value}</param>
 /// <param name="context">${WP_core_Point2DCollectionConverter_method_ConvertFrom_param_context}</param>
 /// <param name="culture">${WP_core_Point2DCollectionConverter_method_ConvertFrom_param_culture}</param>
 /// <returns>${WP_core_Point2DCollectionConverter_method_ConvertFrom_return}</returns>
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     string str = value as string;
     if (str == null)
     {
         throw new NotSupportedException();
     }
     Point2DCollection points = new Point2DCollection();
     Point2DConverter converter = new Point2DConverter();
     int num = -1;
     for (int i = 0; i < (str.Length + 1); i++)
     {
         if ((i >= str.Length) || char.IsWhiteSpace(str[i]))
         {
             int startIndex = num + 1;
             int length = i - startIndex;
             if (length >= 1)
             {
                 string str2 = str.Substring(startIndex, length);
                 points.Add((Point2D)converter.ConvertFrom(str2));
             }
             num = i;
         }
     }
     return points;
 }