PostSharpAPI ReferencePost­Sharp.​Patterns.​FormattersFormatter­Repository<TRole>Register
Open sandboxFocus

FormatterRepository<TRole>.Register Method

Register<T>(IFormatter<T>)

Registers the given formatter for the type T.

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

Register(Type, IFormatter)

Registers the given formatter for the given targetType.

Declaration
public static void Register(Type targetType, IFormatter formatter)
Parameters
Type Name Description
System.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.

Register(Type, Type)

Registers the given formatterType for the given targetType.

Declaration
public static void Register(Type targetType, Type formatterType)
Parameters
Type Name Description
System.Type targetType
System.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>.