Class GenericTextFormatter<T>
- Namespace
- Microsoft.Practices.EnterpriseLibrary.Logging.Formatters
- Assembly
- Microsoft.Practices.EnterpriseLibrary.Logging.dll
Formats an instance for T
with a sequence of Formatter<T> instances.
public class GenericTextFormatter<T>
Type Parameters
T
The type of object to format.
- Inheritance
-
GenericTextFormatter<T>
- Inherited Members
Remarks
A formatter will convert a template into a sequence of Formatter<T> instances with the help of a set of TokenHandler<T> instances that help parse the tokens in the template.
The character '{' is used to determine the start of a token, and token handlers perform the actual parsing of each token.
Constructors
GenericTextFormatter(string, IDictionary<string, TokenHandler<T>>)
Initializes a new instance of GenericTextFormatter<T> with a template and a set of token handlers.
public GenericTextFormatter(string template, IDictionary<string, TokenHandler<T>> tokenHandlers)
Parameters
template
stringThe template to use when
tokenHandlers
IDictionary<string, TokenHandler<T>>The handlers to use when parsing the template.
Methods
CreateParameterizedTokenHandler(ParameterizedFormatterFactory<T>)
Utility method to create a handler for tokens with parameters surrounded by parenthesis.
public static TokenHandler<T> CreateParameterizedTokenHandler(ParameterizedFormatterFactory<T> formatterFactory)
Parameters
formatterFactory
ParameterizedFormatterFactory<T>The factory delegate to create a formatter based on the token parameter.
Returns
- TokenHandler<T>
A token handler.
CreateSimpleTokenHandler(Formatter<T>)
Utility method to create a handler for tokens without parameters that parse a template into a given formatter.
public static TokenHandler<T> CreateSimpleTokenHandler(Formatter<T> formatter)
Parameters
formatter
Formatter<T>The formatter to be returned by the created token handler.
Returns
- TokenHandler<T>
A token handler.
CreateSimpleTokenHandler(string)
Utility method to create a handler for tokens without parameters that parse a template into a formatter for a constant string.
public static TokenHandler<T> CreateSimpleTokenHandler(string constant)
Parameters
constant
stringThe constant for the token handler's formatter
Returns
- TokenHandler<T>
A token handler.
Format(T, StringBuilder)
Formats instance
based on the template specified for the formatter.
public void Format(T instance, StringBuilder output)
Parameters
instance
TThe instance to format.
output
StringBuilderThe result of formatting the instance.