Skip to content

Commit 8643c13

Browse files
committed
Create ArgumentRequiredException.cs
Added Exceptions folder and namespace Added Exceptions\ArgumentRequiredException.cs file ArgumentsManager.cs: - Changed modifiers
1 parent 8d37114 commit 8643c13

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

ProgramArgumentsManager/ArgumentsManager.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,36 +88,36 @@ public string GetUsage(int padLeft = _DEFAULT_PAD_LEFT)
8888
current + option.Key.ToString().PadLeft(padLeft) + " = " + option.Key.Description + "\n");
8989
}
9090

91-
private class Argument
91+
public class Argument
9292
{
93-
public enum Ask
93+
private enum Ask
9494
{
9595
Required,
9696
Optional
9797
}
9898

99-
private readonly string[] _names;
99+
public string[] Names { get; }
100100
public string Description { get; }
101-
private Ask ask;
101+
private readonly Ask _ask;
102102

103-
private Argument(string name, string desc) : this(new[] {name}, desc) { }
103+
internal Argument(string name, string desc) : this(new[] {name}, desc) { }
104104

105-
public Argument(string[] names, string desc)
105+
internal Argument(string[] names, string desc)
106106
{
107-
_names = names;
107+
Names = names;
108108
Description = desc;
109109

110110
if (desc.StartsWith("[OPTIONAL]", StringComparison.InvariantCultureIgnoreCase))
111-
ask = Ask.Optional;
111+
_ask = Ask.Optional;
112112
else if (desc.StartsWith("[REQUIRED]", StringComparison.InvariantCultureIgnoreCase))
113-
ask = Ask.Required;
113+
_ask = Ask.Required;
114114
else
115-
ask = Ask.Required;
115+
_ask = Ask.Required;
116116
}
117117

118-
private bool Equals(Argument other) => other._names.Any(s => _names.Contains(s));
118+
private bool Equals(Argument other) => other.Names.Any(s => Names.Contains(s));
119119

120-
public override string ToString() => string.Join(", ", _names);
120+
public override string ToString() => string.Join(", ", Names);
121121

122122
public override bool Equals(object obj)
123123
{
@@ -149,10 +149,10 @@ public override int GetHashCode()
149149

150150
public class ArgValues
151151
{
152-
public List<string> Values { get; set; }
153-
public bool Specified { get; set; }
152+
public List<string> Values { get; internal set; }
153+
public bool Specified { get; internal set; }
154154

155-
public ArgValues()
155+
internal ArgValues()
156156
{
157157
Values = new List<string>();
158158
Specified = false;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Runtime.Serialization;
3+
4+
namespace ProgramArgumentsManager.Exceptions
5+
{
6+
[Serializable]
7+
public class ArgumentRequiredException : Exception
8+
{
9+
internal ArgumentsManager.Argument Argument;
10+
11+
public ArgumentRequiredException() { }
12+
13+
internal ArgumentRequiredException(ArgumentsManager.Argument argument) : this($"The argument {argument} is required !")
14+
{
15+
Argument = argument;
16+
}
17+
public ArgumentRequiredException(string message) : base(message) { }
18+
public ArgumentRequiredException(string message, Exception inner) : base(message, inner) { }
19+
protected ArgumentRequiredException(SerializationInfo info, StreamingContext context) : base(info, context) { }
20+
}
21+
}

ProgramArgumentsManager/ProgramArgumentsManager.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
</ItemGroup>
4646
<ItemGroup>
4747
<Compile Include="ArgumentsManager.cs" />
48+
<Compile Include="Exceptions\ArgumentRequiredException.cs" />
4849
<Compile Include="Properties\AssemblyInfo.cs" />
4950
</ItemGroup>
51+
<ItemGroup />
5052
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5153
</Project>

0 commit comments

Comments
 (0)