BadScript 2
Loading...
Searching...
No Matches
CommandLine.Text.HeadingInfo Class Reference

Models the heading part of an help text. You can assign it where you assign any System.String instance. More...

Public Member Functions

 HeadingInfo (string programName, string version=null)
 Initializes a new instance of the CommandLine.Text.HeadingInfo class specifying program name and version.
 
override string ToString ()
 Returns the heading as a System.String.
 
void WriteMessage (string message, TextWriter writer)
 Writes out a string and a new line using the program name specified in the constructor and message parameter.
 
void WriteMessage (string message)
 Writes out a string and a new line using the program name specified in the constructor and message parameter to standard output stream.
 
void WriteError (string message)
 Writes out a string and a new line using the program name specified in the constructor and message parameter to standard error stream.
 

Static Public Member Functions

static implicit operator string (HeadingInfo info)
 Converts the heading to a System.String.
 

Properties

static HeadingInfo Empty [get]
 An empty object used for initialization.
 
static HeadingInfo Default [get]
 Gets the default heading instance. The title is retrieved from AssemblyTitleAttribute, or the assembly short name if its not defined. The version is retrieved from AssemblyInformationalVersionAttribute, or the assembly version if its not defined.
 

Private Attributes

readonly string programName
 
readonly string version
 

Detailed Description

Models the heading part of an help text. You can assign it where you assign any System.String instance.

Definition at line 18 of file HeadingInfo.cs.

Constructor & Destructor Documentation

◆ HeadingInfo()

CommandLine.Text.HeadingInfo.HeadingInfo ( string  programName,
string  version = null 
)

Initializes a new instance of the CommandLine.Text.HeadingInfo class specifying program name and version.

Parameters
programNameThe name of the program.
versionThe version of the program.
Exceptions
System.ArgumentExceptionThrown when parameter programName is null or empty string.

Definition at line 33 of file HeadingInfo.cs.

34 {
35 if (string.IsNullOrWhiteSpace("programName"))
36 {
37 throw new ArgumentException("programName");
38 }
39
40 this.programName = programName;
41 this.version = version;
42 }
readonly string programName

Member Function Documentation

◆ operator string()

static implicit CommandLine.Text.HeadingInfo.operator string ( HeadingInfo  info)
static

Converts the heading to a System.String.

Parameters
infoThis CommandLine.Text.HeadingInfo instance.
Returns
The System.String that contains the heading.

Definition at line 80 of file HeadingInfo.cs.

81 {
82 return info.ToString();
83 }

◆ ToString()

override string CommandLine.Text.HeadingInfo.ToString ( )

Returns the heading as a System.String.

Returns
The System.String that contains the heading.

Definition at line 89 of file HeadingInfo.cs.

90 {
91 bool isVersionNull = string.IsNullOrEmpty(version);
92
93 return new StringBuilder(programName.Length +
94 (!isVersionNull ? version.Length + 1 : 0)
95 )
97 .AppendWhen(!isVersionNull, " ", version)
98 .ToString();
99 }
override string ToString()
Returns the heading as a System.String.

◆ WriteError()

void CommandLine.Text.HeadingInfo.WriteError ( string  message)

Writes out a string and a new line using the program name specified in the constructor and message parameter to standard error stream.

Parameters
messageThe System.String message to write.
Exceptions
System.ArgumentExceptionThrown when parameter message is null or empty string.

Definition at line 146 of file HeadingInfo.cs.

147 {
148 WriteMessage(message, Console.Error);
149 }
void WriteMessage(string message, TextWriter writer)
Writes out a string and a new line using the program name specified in the constructor and message p...

◆ WriteMessage() [1/2]

void CommandLine.Text.HeadingInfo.WriteMessage ( string  message)

Writes out a string and a new line using the program name specified in the constructor and message parameter to standard output stream.

Parameters
messageThe System.String message to write.
Exceptions
System.ArgumentExceptionThrown when parameter message is null or empty string.

Definition at line 135 of file HeadingInfo.cs.

136 {
137 WriteMessage(message, Console.Out);
138 }

◆ WriteMessage() [2/2]

void CommandLine.Text.HeadingInfo.WriteMessage ( string  message,
TextWriter  writer 
)

Writes out a string and a new line using the program name specified in the constructor and message parameter.

Parameters
messageThe System.String message to write.
writerThe target System.IO.TextWriter derived type.
Exceptions
System.ArgumentExceptionThrown when parameter message is null or empty string.
System.ArgumentNullExceptionThrown when parameter writer is null.

Definition at line 109 of file HeadingInfo.cs.

110 {
111 if (string.IsNullOrWhiteSpace("message"))
112 {
113 throw new ArgumentException("message");
114 }
115
116 if (writer == null)
117 {
118 throw new ArgumentNullException("writer");
119 }
120
121 writer.WriteLine(new StringBuilder(programName.Length + message.Length + 2)
122 .Append(programName)
123 .Append(": ")
124 .Append(message)
125 .ToString()
126 );
127 }

Member Data Documentation

◆ programName

readonly string CommandLine.Text.HeadingInfo.programName
private

Definition at line 20 of file HeadingInfo.cs.

◆ version

readonly string CommandLine.Text.HeadingInfo.version
private

Definition at line 21 of file HeadingInfo.cs.

Property Documentation

◆ Default

HeadingInfo CommandLine.Text.HeadingInfo.Default
staticget

Gets the default heading instance. The title is retrieved from AssemblyTitleAttribute, or the assembly short name if its not defined. The version is retrieved from AssemblyInformationalVersionAttribute, or the assembly version if its not defined.

Definition at line 56 of file HeadingInfo.cs.

57 {
58 get
59 {
60 string title = ReflectionHelper.GetAttribute<AssemblyTitleAttribute>()
61 .MapValueOrDefault(titleAttribute => titleAttribute.Title,
63 );
64
65 string version = ReflectionHelper.GetAttribute<AssemblyInformationalVersionAttribute>()
66 .MapValueOrDefault(versionAttribute =>
67 versionAttribute.InformationalVersion,
69 );
70
71 return new HeadingInfo(title, version);
72 }
73 }
HeadingInfo(string programName, string version=null)
Initializes a new instance of the CommandLine.Text.HeadingInfo class specifying program name and vers...

◆ Empty

HeadingInfo CommandLine.Text.HeadingInfo.Empty
staticget

An empty object used for initialization.

Definition at line 47 of file HeadingInfo.cs.


The documentation for this class was generated from the following file: