-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCommandLineArgumentParser.cs
More file actions
46 lines (39 loc) · 1.15 KB
/
CommandLineArgumentParser.cs
File metadata and controls
46 lines (39 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* 由SharpDevelop创建。
* 用户: itmak
* 日期: 2018/10/14 星期日
* 时间: 10:43
*
* 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
*/
using System;
using System.Collections.Generic;
using System.Linq;
namespace wm_tools
{
/// <summary>
/// refer to https://www.cnblogs.com/linxuanchen/p/c-sharp-command-line-argument-parser.html
/// </summary>
public class CommandLineArgumentParser
{
List<CommandLineArgument> _arguments;
public static CommandLineArgumentParser Parse(string[] args) {
return new CommandLineArgumentParser(args);
}
public CommandLineArgumentParser(string[] args)
{
_arguments = new List<CommandLineArgument>();
for (int i = 0; i < args.Length; i++)
{
_arguments.Add(new CommandLineArgument(_arguments,i,args[i]));
}
}
public CommandLineArgument Get(string argumentName)
{
return _arguments.FirstOrDefault(p => p == argumentName);
}
public bool Has(string argumentName) {
return _arguments.Count(p=>p==argumentName)>0;
}
}
}