// --------------------------------------------------------------------------------------------------------------------
//
// N/A
//
//
// Message class represents a message generated at a point of execution
//
// --------------------------------------------------------------------------------------------------------------------
namespace Xsd2Code.Library.Helpers
{
using System;
using System.Threading;
///
/// Message class represents a message generated at a point of execution
///
public class Message
{
///
/// Name of rule
///
private string ruleNameField = string.Empty;
///
/// Initializes a new instance of the class.
/// Message constructor with initializers
///
/// Message type
/// Message text
public Message(MessageType messageType, string text)
: this(messageType, string.Empty, text)
{
}
///
/// Initializes a new instance of the class.
/// Message constructor with initializers
///
/// Message type
/// Name of business rule
/// Message text
public Message(MessageType messageType, string ruleName, string text)
: this()
{
this.MessageType = messageType;
this.ruleNameField = ruleName;
this.Text = text ?? string.Empty;
}
///
/// Initializes a new instance of the class.
/// Message constructor with initializers
///
/// Message type
/// Name of business rule
/// Message text format string
/// Format string arguments
public Message(MessageType messageType, string ruleName, string format, params object[] args)
: this(messageType, ruleName, string.Format(Thread.CurrentThread.CurrentCulture, format, args))
{
}
///
/// Initializes a new instance of the class.
/// Message constructor with initializers
///
/// Message type
/// Message text
/// Arguments list
public Message(MessageType messageType, string format, params object[] args)
: this(messageType, string.Empty, string.Format(Thread.CurrentThread.CurrentCulture, format, args))
{
}
///
/// Initializes a new instance of the class.
/// Message class constructor
///
/// parameter value
public Message(string text)
: this(default(MessageType), text)
{
}
///
/// Prevents a default instance of the class from being created.
///
private Message()
{
this.MessageSubtype = MessageSubtype.Unspecified;
}
///
/// Gets the name of the rule.
///
public string RuleName
{
get { return this.ruleNameField; }
}
///
/// Gets or sets the type of the message.
///
public MessageType MessageType { get; set; }
///
/// Gets or sets the message subtype.
///
public MessageSubtype MessageSubtype { get; set; }
///
/// Gets or sets the text.
///
public string Text { get; set; }
///
/// Represents message object in a form of a string
///
/// Formatted Message
public override string ToString()
{
return string.Format(
Thread.CurrentThread.CurrentCulture,
"{1}: {2}{0}\tSubType: {3}{0}{0}\tRule: {4}",
Environment.NewLine,
this.MessageType,
this.Text,
this.MessageSubtype,
this.RuleName);
}
}
}