getopt.net
A port of getopt in pure C#.
getopt.net.Extensions Class Reference

Static Public Member Functions

static ? Option FindOptionOrDefault (this Option[] list, string optName)
 Finds an option with the name optName More...
 
static ? Option FindOptionOrDefault (this Option[] list, char optVal)
 Finds an option in the list list with the Option.Value optVal . More...
 
static ? string ToShortOptString (this Option[] list)
 Creates a short opt string from an array of Option objects. More...
 

Detailed Description

This class contains extension methods specific to getopt.net. If these extension methods help you in your program, you're free to use them too!

Definition at line 12 of file Extensions.cs.

Member Function Documentation

◆ FindOptionOrDefault() [1/2]

static ? Option getopt.net.Extensions.FindOptionOrDefault ( this Option[]  list,
char  optVal 
)
static

Finds an option in the list list with the Option.Value optVal .

Parameters
listThe list of options to search.
optValThe value to search for.
Returns
The Option with the Option.Value optVal , or
null
if no option was found matching the name.

◆ FindOptionOrDefault() [2/2]

static ? Option getopt.net.Extensions.FindOptionOrDefault ( this Option[]  list,
string  optName 
)
inlinestatic

Finds an option with the name optName

Parameters
listThe list of options to search.
optNameThe name of the argument to search for.
Returns
The Option with the name optName , or
null
if no option was found matching the name.

Definition at line 20 of file Extensions.cs.

20 {
21 if (string.IsNullOrEmpty(optName)) { throw new ArgumentNullException(nameof(optName), "optName must not be null!"); }
22
23 return list.FirstOrDefault(o => o.Name?.Equals(optName, StringComparison.InvariantCulture) == true);
24 }

◆ ToShortOptString()

static ? string getopt.net.Extensions.ToShortOptString ( this Option[]  list)
inlinestatic

Creates a short opt string from an array of Option objects.

Parameters
listThe options to convert.
Returns
null
if the option list is empty or null. A string contain a shortopt-form string representing all the options from list .

Definition at line 39 of file Extensions.cs.

39 {
40 if (list is null || list.Length == 0) { return null; }
41
42 var sBuilder = new StringBuilder();
43
44 foreach (var opt in list) {
45 sBuilder.Append((char)opt.Value);
46 switch (opt.ArgumentType) {
47 case ArgumentType.Required:
48 sBuilder.Append(':');
49 break;
50 case ArgumentType.Optional:
51 sBuilder.Append(';');
52 break;
53 default: break;
54 }
55 }
56
57 return sBuilder.ToString();
58 }
ArgumentType
Enumeration containing the argument types possible for getopt.
Definition: ArgumentType.cs:8

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