/// <summary> /// Implementation of Freezable.GetAsFrozenCore() /// </summary> protected override void GetAsFrozenCore(Freezable source) { VectorCollection sourceVectorCollection = (VectorCollection)source; base.GetAsFrozenCore(source); int count = sourceVectorCollection._collection.Count; _collection = new FrugalStructList <Vector>(count); for (int i = 0; i < count; i++) { _collection.Add(sourceVectorCollection._collection[i]); } }
/// <summary> /// Attempts to convert to a VectorCollection from the given object. /// </summary> /// <returns> /// The VectorCollection which was constructed. /// </returns> /// <exception cref="NotSupportedException"> /// A NotSupportedException is thrown if the example object is null or is not a valid type /// which can be converted to a VectorCollection. /// </exception> /// <param name="context"> The ITypeDescriptorContext for this call. </param> /// <param name="culture"> The requested CultureInfo. Note that conversion uses "en-US" rather than this parameter. </param> /// <param name="value"> The object to convert to an instance of VectorCollection. </param> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value == null) { throw GetConvertFromException(value); } String source = value as string; if (source != null) { return(VectorCollection.Parse(source)); } return(base.ConvertFrom(context, culture, value)); }
/// <summary> /// ConvertTo - Attempt to convert an instance of VectorCollection to the given type /// </summary> /// <returns> /// The object which was constructoed. /// </returns> /// <exception cref="NotSupportedException"> /// A NotSupportedException is thrown if "value" is null or not an instance of VectorCollection, /// or if the destinationType isn't one of the valid destination types. /// </exception> /// <param name="context"> The ITypeDescriptorContext for this call. </param> /// <param name="culture"> The CultureInfo which is respected when converting. </param> /// <param name="value"> The object to convert to an instance of "destinationType". </param> /// <param name="destinationType"> The type to which this will convert the VectorCollection instance. </param> public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType != null && value is VectorCollection) { VectorCollection instance = (VectorCollection)value; if (destinationType == typeof(string)) { // Delegate to the formatting/culture-aware ConvertToString method. #pragma warning suppress 6506 // instance is obviously not null return(instance.ConvertToString(null, culture)); } } // Pass unhandled cases to base class (which will throw exceptions for null value or destinationType.) return(base.ConvertTo(context, culture, value, destinationType)); }
/// <summary> /// Parse - returns an instance converted from the provided string /// using the current culture /// <param name="source"> string with VectorCollection data </param> /// </summary> public static VectorCollection Parse(string source) { IFormatProvider formatProvider = System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS; TokenizerHelper th = new TokenizerHelper(source, formatProvider); VectorCollection resource = new VectorCollection(); Vector value; while (th.NextToken()) { value = new Vector( Convert.ToDouble(th.GetCurrentToken(), formatProvider), Convert.ToDouble(th.NextTokenRequired(), formatProvider)); resource.Add(value); } return(resource); }