BadScript 2
Loading...
Searching...
No Matches
Example.cs
Go to the documentation of this file.
1// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
2
3using System;
4using System.Collections.Generic;
5using System.Linq;
6
7namespace CommandLine.Text
8{
12 public sealed class Example : IEquatable<Example>
13 {
23 public Example(string helpText, IEnumerable<UnParserSettings> formatStyles, object sample)
24 {
25 if (string.IsNullOrEmpty(helpText))
26 {
27 throw new ArgumentException("helpText can't be null or empty", "helpText");
28 }
29
30 if (formatStyles == null)
31 {
32 throw new ArgumentNullException("formatStyles");
33 }
34
35 if (sample == null)
36 {
37 throw new ArgumentNullException("sample");
38 }
39
40 HelpText = helpText;
41 FormatStyles = formatStyles;
42 Sample = sample;
43 }
44
54 public Example(string helpText, UnParserSettings formatStyle, object sample)
55 : this(helpText,
56 new[] { formatStyle },
57 sample
58 ) { }
59
65 public Example(string helpText, object sample)
66 : this(helpText, Enumerable.Empty<UnParserSettings>(), sample) { }
67
71 public string HelpText { get; }
72
76 public IEnumerable<UnParserSettings> FormatStyles { get; }
77
81 public object Sample { get; }
82
83#region IEquatable<Example> Members
84
97 public bool Equals(Example other)
98 {
99 if (other == null)
100 {
101 return false;
102 }
103
104 return HelpText.Equals(other.HelpText) &&
105 FormatStyles.SequenceEqual(other.FormatStyles) &&
106 Sample.Equals(other.Sample);
107 }
108
109#endregion
110
121 public override bool Equals(object obj)
122 {
123 Example other = obj as Example;
124
125 if (other != null)
126 {
127 return Equals(other);
128 }
129
130 return base.Equals(obj);
131 }
132
137 public override int GetHashCode()
138 {
139 return new { HelpText, FormatStyles, Sample }.GetHashCode();
140 }
141 }
142
143 internal static class ExampleExtensions
144 {
145 public static IEnumerable<UnParserSettings> GetFormatStylesOrDefault(this Example example)
146 {
147 return example.FormatStyles.Any()
148 ? example.FormatStyles
149 : new[] { new UnParserSettings { Consumed = true } };
150 }
151 }
152}
static IEnumerable< UnParserSettings > GetFormatStylesOrDefault(this Example example)
Definition Example.cs:145
Models a command line usage example.
Definition Example.cs:13
Example(string helpText, UnParserSettings formatStyle, object sample)
Initializes a new instance of the CommandLine.Text.Example class.
Definition Example.cs:54
IEnumerable< UnParserSettings > FormatStyles
A sequence of format styles.
Definition Example.cs:76
object Sample
A sample instance.
Definition Example.cs:81
Example(string helpText, IEnumerable< UnParserSettings > formatStyles, object sample)
Initializes a new instance of the CommandLine.Text.Example class.
Definition Example.cs:23
override int GetHashCode()
Serves as a hash function for a particular type.
Definition Example.cs:137
string HelpText
Example description.
Definition Example.cs:71
override bool Equals(object obj)
Determines whether the specified System.Object is equal to the current System.Object.
Definition Example.cs:121
bool Equals(Example other)
Returns a value that indicates whether the current instance and a specified CommandLine....
Definition Example.cs:97
Example(string helpText, object sample)
Initializes a new instance of the CommandLine.Text.Example class.
Definition Example.cs:65
Provides settings for when formatting command line from an options instance../>.