Enhanced C#
Language of your choice: library documentation

Documentation moved to ecsharp.net

GitHub doesn't support HTTP redirects, so you'll be redirected in 3 seconds.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Nested classes | Public static fields | Properties | Static Public Member Functions | List of all members
Loyc.MessageSink Class Reference

Holds the default message sink for this thread (Current), Symbols for the common message types, such as Warning and Error, and default instances of ConsoleMessageSink, TraceMessageSink and NullMessageSink. More...


Source file:

Remarks

Holds the default message sink for this thread (Current), Symbols for the common message types, such as Warning and Error, and default instances of ConsoleMessageSink, TraceMessageSink and NullMessageSink.

See also
IMessageSink

Nested classes

struct  PushedCurrent
 Returned by PushCurrent(IMessageSink). More...
 

Public static fields

static readonly TraceMessageSink Trace = new TraceMessageSink()
 Sends all messages to System.Diagnostics.Trace.WriteLine(string). More...
 
static readonly ConsoleMessageSink Console = new ConsoleMessageSink()
 Sends all messages to the System.Console.WriteLine(string). More...
 
static readonly NullMessageSink Null = new NullMessageSink()
 Discards all messages. More...
 

Properties

static IMessageSink Current [get, set]
 

Static Public Member Functions

static PushedCurrent PushCurrent (IMessageSink sink)
 Used to change the MessageSink.Current property temporarily. More...
 
static string LocationString (object context)
 Gets the location information from the specified object, or converts the object to a string. More...
 
static object LocationOf (object context)
 Returns context.Location if context implements IHasLocation; otherwise, returns context itself. More...
 
static string FormatMessage (Severity type, object context, string format, params object[] args)
 
static MessageSinkFromDelegate FromDelegate (WriteMessageFn writer, Func< Severity, bool > isEnabled=null)
 Sends all messages to a user-defined method. More...
 

Member Function Documentation

static MessageSinkFromDelegate Loyc.MessageSink.FromDelegate ( WriteMessageFn  writer,
Func< Severity, bool >  isEnabled = null 
)
inlinestatic

Sends all messages to a user-defined method.

static object Loyc.MessageSink.LocationOf ( object  context)
inlinestatic

Returns context.Location if context implements IHasLocation; otherwise, returns context itself.

static string Loyc.MessageSink.LocationString ( object  context)
inlinestatic

Gets the location information from the specified object, or converts the object to a string.

Parameters
contextA value whose string representation you want to get.
Returns
If context implements IHasLocation, this function returns IHasLocation.Location; if context is null, this method returns null; otherwise it returns context.ToString().

Message sinks are commonly used to display error and warning messages, and when you write a message with IMessageSink.Write(), the second parameter is a "context" argument which specifies the object to which the message is related (for example, when writing compiler output, the context might be a node in a syntax tree). Most message sinks display the message in text form (in a log file or terminal), and in that case the best option is to display the location information associated with the context object (e.g. Foo.cpp:45), rather than a string representation of the object itself.

Therefore, message sinks that display a message in text form will call this method to convert the context object to a string, and if available, this method calls the IHasLocation.Location property of the context object.

static PushedCurrent Loyc.MessageSink.PushCurrent ( IMessageSink  sink)
inlinestatic

Used to change the MessageSink.Current property temporarily.

using (var old = MessageSink.PushCurrent(MessageSink.Console)) MessageSink.Current.Write(Severity.Warning, null, "This prints on the console.")

Member Data Documentation

readonly ConsoleMessageSink Loyc.MessageSink.Console = new ConsoleMessageSink()
static

Sends all messages to the System.Console.WriteLine(string).

readonly NullMessageSink Loyc.MessageSink.Null = new NullMessageSink()
static

Discards all messages.

readonly TraceMessageSink Loyc.MessageSink.Trace = new TraceMessageSink()
static

Sends all messages to System.Diagnostics.Trace.WriteLine(string).