internal static string Format(T obj) { var writer = Formatter.CreateWriter(); Format(obj, writer); return(writer.ToString()); }
/// <summary> /// Dynamically generates a formatter function that will output the specified properties of objects of type <typeparamref name="T"/> as a string. /// </summary> /// <typeparam name="T">The <see cref="Type"/> targeted by the formatter function.</typeparam> /// <param name="members">An array of MemberExpressions specifying the members to include in formatting.</param> /// <returns> /// A formatter function. /// </returns> public Func <T, string> CreateFormatterFor <T>(params Expression <Func <T, object> >[] members) { var write = Formatter <T> .GenerateForMembers(members); return(t => { var writer = Formatter.CreateWriter(); write(t, writer); return writer.ToString(); }); }
/// <summary> /// Dynamically generates a formatter function that will output the public properties of objects of type <typeparamref name = "T" /> as a string. /// </summary> /// <typeparam name = "T">The <see cref = "Type" /> targeted by the formatter function.</typeparam> /// <returns>A formatter function.</returns> public Func <T, string> CreatePropertiesFormatter <T>(bool includeInternals = false) { var write = Formatter <T> .GenerateForAllMembers(includeInternals); return(t => { var writer = Formatter.CreateWriter(); write(t, writer); return writer.ToString(); }); }