Open sandboxFocus

Method AddFormatter

AddFormatter<T>(IFormatter<T>)

Registers the given formatter for the type T.

Declaration
public void AddFormatter<T>(IFormatter<T> formatter)
Parameters
Type Name Description
IFormatter<T> formatter
Type Parameters
Name Description
T

AddFormatter<T>(Func<IFormatterRepository, IFormatter<T>>)

Declaration
public void AddFormatter<T>(Func<IFormatterRepository, IFormatter<T>> formatterFactory)
Parameters
Type Name Description
Func<IFormatterRepository, IFormatter<T>> formatterFactory
Type Parameters
Name Description
T

AddFormatter(Type, IFormatter)

Registers the given formatter for the given targetType.

Declaration
public void AddFormatter(Type targetType, IFormatter formatter)
Parameters
Type Name Description
Type targetType
IFormatter formatter
Remarks

The formatter will work for the given target type, and also for any type that inherits/implements the target type.

AddFormatter(Type, Func<IFormatterRepository, IFormatter>)

Declaration
public void AddFormatter(Type targetType, Func<IFormatterRepository, IFormatter> formatterFactory)
Parameters
Type Name Description
Type targetType
Func<IFormatterRepository, IFormatter> formatterFactory

AddFormatter(Type, Type)

Registers the given formatterType for the given targetType.

Declaration
public void AddFormatter(Type targetType, Type formatterType)
Parameters
Type Name Description
Type targetType
Type formatterType
Remarks

Instances of formatterType are going to be created using a parameterless constructor.

When targetType is generic, the registration applies to its generic instantiations (and types that inherit/implement them).

Examples

If you register a formatter as FormattingServices.RegisterFormatter(typeof(IDictionary<,>), typeof(MyDictionaryFormatter<,>) and then log a parameter of type Dictionary<int, string>, the formatter for that parameter will be created by calling new MyDictionaryFormatter<int, string>.