Esempio n. 1
0
        public void ConversionTest()
        {
            var f = new FormattableFormatter <UserDefinedFormattable>();
            IFormatterEx <UserDefinedDrivedFormattable> fobj = f;

            Assert.AreEqual("Hello world!", fobj.Format(new UserDefinedDrivedFormattable()));
        }
 /// <summary>
 /// Returns a humanize string with a formatter that represents the current object.
 /// </summary>
 /// <typeparam name="T">The type of the object.</typeparam>
 /// <param name="obj">The current object.</param>
 /// <param name="formatter">The formatter.</param>
 /// <returns>A humanize string.</returns>
 /// <exception cref="ArgumentNullException">When <paramref name="obj"/> is <see langword="null"/> (<see langword="Nothing"/> in Visual Basic).</exception>
 public static string ToStringEx <T>(this T obj, IFormatterEx <T> formatter)
 {
     if (formatter == null || !formatter.TargetType.IsAssignableFrom(typeof(T)))
     {
         return(obj.ToStringEx());
     }
     else
     {
         return(formatter.Format(obj));
     }
 }
 /// <summary>
 /// Returns a humanize string with a formatter that represents the current object.
 /// </summary>
 /// <param name="obj">The current object.</param>
 /// <param name="formatter">The formatter.</param>
 /// <returns>A humanize string.</returns>
 /// <exception cref="ArgumentNullException">When <paramref name="obj"/> is <see langword="null"/> (<see langword="Nothing"/> in Visual Basic).</exception>
 public static string ToStringEx(this object obj, IFormatterEx formatter)
 {
     if (formatter == null)
     {
         return(obj.ToStringEx());
     }
     else
     {
         return(formatter.Format(obj));
     }
 }