/// <summary> /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be /// used as generic method and casting is not required. /// <example> /// sizeconverter.ConvertTo<int>(context, culture, value); /// </example> /// </summary> public static T ConvertTo <T>(this SizeConverter sizeconverter, System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, Object value) { if (sizeconverter == null) { throw new ArgumentNullException("sizeconverter"); } return((T)sizeconverter.ConvertTo(context, culture, value, typeof(T))); }
/// <summary> /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be /// used as generic method and casting is not required. /// <example> /// typeconverter.ConvertTo<int>(value); /// </example> /// </summary> public static T ConvertTo <T>(this SizeConverter typeconverter, Object value) { if (typeconverter == null) { throw new ArgumentNullException("typeconverter"); } return((T)typeconverter.ConvertTo(value, typeof(T))); }
public void ConvertTo() { SizeConverter r = new SizeConverter(); Size rect = new Size(1, 2); object o = r.ConvertTo(rect, typeof(string)); Assert.AreEqual(typeof(string), o.GetType()); Assert.AreEqual("1,2", (string)o); }
public void ConvertTo() { SizeConverter r = new SizeConverter(); Size rect = new Size(1, 2); object o = r.ConvertTo(null, CultureInfo.InvariantCulture, rect, typeof(string)); Assert.AreEqual(typeof(string), o.GetType()); Assert.AreEqual("1,2", (string)o); }
/// <summary> /// Convert a Size instance into a string representation. /// </summary> /// <param name="size">Size instance to be converted.</param> /// <returns>String representation of the Size instance.</returns> public static string SizeToString(Size size) { return((string)_sc.ConvertTo(null, CultureInfo.InvariantCulture, size, _stringType)); }
public static string SizeToString(Size size) { return((string)_sc.ConvertTo(size, _stringType)); }
public void ConvertToInvalidDestination() { new Action(() => _converter.ConvertTo(new Size(), typeof(int))).Should().Throw <NotSupportedException>(); }