示例#1
0
        /// <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&lt;int&gt;(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)));
        }
示例#2
0
        /// <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&lt;int&gt;(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);
        }
示例#5
0
 /// <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));
 }
示例#7
0
 public void ConvertToInvalidDestination()
 {
     new Action(() => _converter.ConvertTo(new Size(), typeof(int))).Should().Throw <NotSupportedException>();
 }