Enhanced C#
Language of your choice: library documentation
Properties | Public Member Functions | List of all members
Loyc.MessageSinkWithContext< TContext > Class Template Reference

A message sink wrapper that has a default value for the context parameter, which is used when the context provided is null, and an optional message prefix which is inserted at the beginning of the format string. More...


Source file:
Inheritance diagram for Loyc.MessageSinkWithContext< TContext >:
Loyc.IMessageSink< TContext > Loyc.IMessageSink< in in TContext >

Remarks

A message sink wrapper that has a default value for the context parameter, which is used when the context provided is null, and an optional message prefix which is inserted at the beginning of the format string.

Alias for MessageSinkWithContext<object>.

Type Constraints
TContext :class 

Properties

IMessageSink< TContext >?? Target [get, set]
 
TContext DefaultContext [get, set]
 
string MessagePrefix [get, set]
 

Public Member Functions

 MessageSinkWithContext (IMessageSink< TContext > target, TContext defaultContext, string messagePrefix=null, bool scrubPrefix=true)
 Initializes the wrapper. More...
 
bool IsEnabled (Severity level)
 Returns true if messages of the specified type will actually be printed, or false if Write(type, ...) has no effect. More...
 
void Write (Severity level, TContext context, string format)
 Writes a message to the target that this object represents. More...
 
void Write (Severity level, TContext context, string format, params object[] args)
 
void Write (Severity level, TContext context, string format, object arg0, object arg1=null)
 
 MessageSinkWithContext (IMessageSink target, object defaultContext, string messagePrefix=null, bool scrubPrefix=true)
 
- Public Member Functions inherited from Loyc.IMessageSink< TContext >
void Write (Severity level, TContext context,[Localizable] string format)
 Writes a message to the target that this object represents. More...
 
void Write (Severity level, TContext context,[Localizable] string format, object arg0, object arg1=null)
 
void Write (Severity level, TContext context,[Localizable] string format, params object[] args)
 
bool IsEnabled (Severity level)
 Returns true if messages of the specified type will actually be printed, or false if Write(type, ...) has no effect. More...
 

Constructor & Destructor Documentation

◆ MessageSinkWithContext()

Loyc.MessageSinkWithContext< TContext >.MessageSinkWithContext ( IMessageSink< TContext >  target,
TContext  defaultContext,
string  messagePrefix = null,
bool  scrubPrefix = true 
)
inline

Initializes the wrapper.

Parameters
targetMessage sink to which all messages are forwarded. If this parameter is null, then messages are written to MessageSink.Default at the time a message is written.
defaultContextDefault context object, used if Write is called with a context of null.
messagePrefixA prefix to prepend at the beginning of all messages written.
scrubPrefixWhether to replace "{" with ""{{" and "}" with "}}" in messagePrefix to avoid accidental misbehavior when the string is formatted. Note: in fact, messagePrefix should not contain braces at all, because message formatting is optional. Write(Severity, TContext, string) does not perform formatting while Write(Severity, TContext, string, object[]) does. Consequently, when calling the first overload, the scrubbing process will cause braces in messagePrefix to be doubled as in "{{" or "}}". We could fix this by storing two separate MessagePrefix strings in this object, one for each situation, but that's currently not implemented as it is simpler to just ask users not to put braces in prefixes.

Member Function Documentation

◆ IsEnabled()

bool Loyc.MessageSinkWithContext< TContext >.IsEnabled ( Severity  level)
inline

Returns true if messages of the specified type will actually be printed, or false if Write(type, ...) has no effect.

Implements Loyc.IMessageSink< in in TContext >.

References Loyc.IMessageSink< in in TContext >.IsEnabled().

Referenced by Loyc.MessageSinkWithContext< TContext >.Write().

◆ Write()

void Loyc.MessageSinkWithContext< TContext >.Write ( Severity  level,
TContext  context,
string  format 
)
inline

Writes a message to the target that this object represents.

Parameters
levelSeverity or importance of the message; widely-used types include Error, Warning, Note, Debug, and Verbose. The special type Detail is intended to provide more information about a previous message.
contextAn object that the message is related to, or that represents the location that the message applies to. The message sink may try to convert this object to a string and include it in its output. See also MessageSink.ContextToString().
formatA message to display. If there are additional arguments, placeholders such as {0} and {1} refer to these arguments.

Implements Loyc.IMessageSink< in in TContext >.

References Loyc.MessageSinkWithContext< TContext >.IsEnabled(), and Loyc.IMessageSink< in in TContext >.Write().