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

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

Public Member Functions

 CopyrightInfo (string author, int year)
 Initializes a new instance of the CommandLine.Text.CopyrightInfo class specifying author and year.
 
 CopyrightInfo (string author, params int[] years)
 Initializes a new instance of the CommandLine.Text.CopyrightInfo class specifying author and copyrightYears.
 
 CopyrightInfo (bool isSymbolUpper, string author, params int[] copyrightYears)
 Initializes a new instance of the CommandLine.Text.CopyrightInfo class specifying symbol case, author and copyrightYears.
 
override string ToString ()
 Returns the copyright as a System.String.
 

Static Public Member Functions

static implicit operator string (CopyrightInfo info)
 Converts the copyright instance to a System.String.
 

Protected Member Functions

 CopyrightInfo ()
 Initializes a new instance of the CommandLine.Text.CopyrightInfo class.
 
virtual string FormatYears (int[] years)
 When overridden in a derived class, allows to specify a new algorithm to render copyright copyrightYears as a System.String instance.
 

Properties

static CopyrightInfo Empty [get]
 An empty object used for initialization.
 
static CopyrightInfo Default [get]
 Gets the default copyright information. Retrieved from AssemblyCopyrightAttribute, if it exists, otherwise it uses AssemblyCompanyAttribute as copyright holder with the current year. If neither exists it throws an InvalidOperationException.
 
virtual string CopyrightWord [get]
 Gets a different copyright word when overridden in a derived class.
 

Private Member Functions

 CopyrightInfo (AssemblyCopyrightAttribute attribute)
 Initializes a new instance of the CommandLine.Text.CopyrightInfo class with an assembly attribute, this overrides all formatting.
 

Private Attributes

readonly AssemblyCopyrightAttribute attribute
 
readonly string author
 
readonly int builderSize
 
readonly int[] copyrightYears
 
readonly bool isSymbolUpper
 

Static Private Attributes

const string DefaultCopyrightWord = "Copyright"
 
const string SymbolLower = "(c)"
 
const string SymbolUpper = "(C)"
 

Detailed Description

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

Definition at line 18 of file CopyrightInfo.cs.

Constructor & Destructor Documentation

◆ CopyrightInfo() [1/5]

CommandLine.Text.CopyrightInfo.CopyrightInfo ( string  author,
int  year 
)

Initializes a new instance of the CommandLine.Text.CopyrightInfo class specifying author and year.

Parameters
authorThe company or person holding the copyright.
yearThe year of coverage of copyright.
Exceptions
System.ArgumentExceptionThrown when parameter author is null or empty string.

Definition at line 36 of file CopyrightInfo.cs.

37 : this(true, author, year) { }

◆ CopyrightInfo() [2/5]

CommandLine.Text.CopyrightInfo.CopyrightInfo ( string  author,
params int[]  years 
)

Initializes a new instance of the CommandLine.Text.CopyrightInfo class specifying author and copyrightYears.

Parameters
authorThe company or person holding the copyright.
yearsThe copyrightYears of coverage of copyright.
Exceptions
System.ArgumentExceptionThrown when parameter author is null or empty string.
System.ArgumentOutOfRangeExceptionThrown when parameter years is not supplied.

Definition at line 47 of file CopyrightInfo.cs.

48 : this(true, author, years) { }

◆ CopyrightInfo() [3/5]

CommandLine.Text.CopyrightInfo.CopyrightInfo ( bool  isSymbolUpper,
string  author,
params int[]  copyrightYears 
)

Initializes a new instance of the CommandLine.Text.CopyrightInfo class specifying symbol case, author and copyrightYears.

Parameters
isSymbolUpperThe case of the copyright symbol.
authorThe company or person holding the copyright.
copyrightYearsThe copyrightYears of coverage of copyright.
Exceptions
System.ArgumentExceptionThrown when parameter author is null or empty string.
System.ArgumentOutOfRangeExceptionThrown when parameter copyrightYears is not supplied.

Definition at line 62 of file CopyrightInfo.cs.

63 {
64 if (string.IsNullOrWhiteSpace(author))
65 {
66 throw new ArgumentException("author");
67 }
68
69 if (copyrightYears.Length == 0)
70 {
71 throw new ArgumentOutOfRangeException("copyrightYears");
72 }
73
74 const int ExtraLength = 10;
75 this.isSymbolUpper = isSymbolUpper;
76 this.author = author;
77 this.copyrightYears = copyrightYears;
78 builderSize = 12 + author.Length + 4 * copyrightYears.Length + ExtraLength;
79 }

◆ CopyrightInfo() [4/5]

CommandLine.Text.CopyrightInfo.CopyrightInfo ( )
protected

Initializes a new instance of the CommandLine.Text.CopyrightInfo class.

Definition at line 84 of file CopyrightInfo.cs.

84{ }

◆ CopyrightInfo() [5/5]

CommandLine.Text.CopyrightInfo.CopyrightInfo ( AssemblyCopyrightAttribute  attribute)
private

Initializes a new instance of the CommandLine.Text.CopyrightInfo class with an assembly attribute, this overrides all formatting.

Parameters
attributeThe attribute which text to use.

Definition at line 91 of file CopyrightInfo.cs.

92 {
93 this.attribute = attribute;
94 }

Member Function Documentation

◆ FormatYears()

virtual string CommandLine.Text.CopyrightInfo.FormatYears ( int[]  years)
protectedvirtual

When overridden in a derived class, allows to specify a new algorithm to render copyright copyrightYears as a System.String instance.

Parameters
yearsA System.Int32 array of copyrightYears.
Returns
A System.String instance with copyright copyrightYears.

Definition at line 178 of file CopyrightInfo.cs.

179 {
180 if (years.Length == 1)
181 {
182 return years[0]
183 .ToString(CultureInfo.InvariantCulture);
184 }
185
186 StringBuilder yearsPart = new StringBuilder(years.Length * 6);
187
188 for (int i = 0; i < years.Length; i++)
189 {
190 yearsPart.Append(years[i]
191 .ToString(CultureInfo.InvariantCulture)
192 );
193 int next = i + 1;
194
195 if (next < years.Length)
196 {
197 yearsPart.Append(years[next] - years[i] > 1 ? " - " : ", ");
198 }
199 }
200
201 return yearsPart.ToString();
202 }

◆ operator string()

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

Converts the copyright instance to a System.String.

Parameters
infoThis CommandLine.Text.CopyrightInfo instance.
Returns
The System.String that contains the copyright.

Definition at line 145 of file CopyrightInfo.cs.

146 {
147 return info.ToString();
148 }

◆ ToString()

override string CommandLine.Text.CopyrightInfo.ToString ( )

Returns the copyright as a System.String.

Returns
The System.String that contains the copyright.

Definition at line 154 of file CopyrightInfo.cs.

155 {
156 if (attribute != null)
157 {
158 return attribute.Copyright;
159 }
160
161 return new StringBuilder(builderSize)
162 .Append(CopyrightWord)
163 .Append(' ')
165 .Append(' ')
167 .Append(' ')
168 .Append(author)
169 .ToString();
170 }

Member Data Documentation

◆ attribute

readonly AssemblyCopyrightAttribute CommandLine.Text.CopyrightInfo.attribute
private

Definition at line 23 of file CopyrightInfo.cs.

◆ author

readonly string CommandLine.Text.CopyrightInfo.author
private

Definition at line 24 of file CopyrightInfo.cs.

◆ builderSize

readonly int CommandLine.Text.CopyrightInfo.builderSize
private

Definition at line 25 of file CopyrightInfo.cs.

◆ copyrightYears

readonly int [] CommandLine.Text.CopyrightInfo.copyrightYears
private

Definition at line 26 of file CopyrightInfo.cs.

◆ DefaultCopyrightWord

const string CommandLine.Text.CopyrightInfo.DefaultCopyrightWord = "Copyright"
staticprivate

Definition at line 20 of file CopyrightInfo.cs.

◆ isSymbolUpper

readonly bool CommandLine.Text.CopyrightInfo.isSymbolUpper
private

Definition at line 27 of file CopyrightInfo.cs.

◆ SymbolLower

const string CommandLine.Text.CopyrightInfo.SymbolLower = "(c)"
staticprivate

Definition at line 21 of file CopyrightInfo.cs.

◆ SymbolUpper

const string CommandLine.Text.CopyrightInfo.SymbolUpper = "(C)"
staticprivate

Definition at line 22 of file CopyrightInfo.cs.

Property Documentation

◆ CopyrightWord

virtual string CommandLine.Text.CopyrightInfo.CopyrightWord
getprotected

Gets a different copyright word when overridden in a derived class.

Definition at line 138 of file CopyrightInfo.cs.

◆ Default

CopyrightInfo CommandLine.Text.CopyrightInfo.Default
staticget

Gets the default copyright information. Retrieved from AssemblyCopyrightAttribute, if it exists, otherwise it uses AssemblyCompanyAttribute as copyright holder with the current year. If neither exists it throws an InvalidOperationException.

Definition at line 107 of file CopyrightInfo.cs.

108 {
109 get
110 {
111 // if an exact copyright string has been specified, it takes precedence
113 ReflectionHelper.GetAttribute<AssemblyCopyrightAttribute>();
114
115 switch (copyrightAttr.Tag)
116 {
117 case MaybeType.Just:
118 return new CopyrightInfo(copyrightAttr.FromJustOrFail());
119 default:
121 ReflectionHelper.GetAttribute<AssemblyCompanyAttribute>();
122
123 return companyAttr.IsNothing()
124 //if both copyrightAttr and companyAttr aren't available in Assembly,don't fire Exception
125 ? Empty
126 // if no copyright attribute exist but a company attribute does, use it as copyright holder
127 : new CopyrightInfo(companyAttr.FromJust()
128 .Company,
129 DateTime.Now.Year
130 );
131 }
132 }
133 }
The Maybe type models an optional value. A value of type Maybe a either contains a value of type a (r...
Definition Maybe.cs:33
MaybeType Tag
Type discriminator.
Definition Maybe.cs:42
MaybeType
Discriminator for CSharpx.Maybe.
Definition Maybe.cs:19

◆ Empty

CopyrightInfo CommandLine.Text.CopyrightInfo.Empty
staticget

An empty object used for initialization.

Definition at line 99 of file CopyrightInfo.cs.


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