internal static void RegisterFormatters() { if (isAnonymous) { Formatter <TSubject> .RegisterForMembers(); } // register the default formatter for this LogEntry type, which should be the non-generic LogEntry formatter Formatter <LogEntry <TSubject> > .Register((e, writer) => Formatter <LogEntry> .Format(e, writer)); }
/// <summary> /// Registers a formatter to be used when formatting instances of type <typeparamref name="T" />. /// </summary> public static void Register(Action <T, TextWriter> formatter) { if (formatter == null) { throw new ArgumentNullException("formatter"); } if (typeof(T) == typeof(Type)) { // special treatment is needed since typeof(Type) == System.RuntimeType, which is not public Formatter.Register(typeof(Type).GetType(), (o, writer) => formatter((T)o, writer)); } Custom = formatter; }
/// <summary> /// Registers a formatter function for the specified <see cref = "Type" /> <typeparamref name = "T" />. /// </summary> /// <typeparam name = "T">The <see cref = "Type" /> targeted by the formatter function.</typeparam> /// <param name = "format">A function that returs a string representation of instances of <typeparamref name="T" />.</param> public FormatterSet RegisterFormatter <T>(Func <T, string> format) { Formatter <T> .Register(format); return(this); }