コード例 #1
0
ファイル: LogEntry{T}.cs プロジェクト: ckurt/Its.Monitoring
        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));
        }
コード例 #2
0
ファイル: Formatter{T}.cs プロジェクト: ckurt/Its.Monitoring
        /// <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;
        }
コード例 #3
0
ファイル: FormatterSet.cs プロジェクト: ckurt/Its.Monitoring
        /// <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);
        }