Click or drag to resize

YArgumentParser Class

The Upsilon Ecosystem argument parsing engine.
Inheritance Hierarchy
SystemObject
  Upsilon.Common.LibraryYArgumentParser

Namespace: Upsilon.Common.Library
Assembly: Upsilon.Common.Library (in Upsilon.Common.Library.dll) Version: 2.2.2+14985a67b419f90e14e6b1bde61d18cf6cf12b27
Syntax
C#
public sealed class YArgumentParser

The YArgumentParser type exposes the following members.

Constructors
 NameDescription
Public methodCode exampleYArgumentParser(String) Create a new argument parser engine from an argument string.
Example
C#
YArgumentParser argumentParser = new YArgumentParser("\"First value of the main argument\" \"Second value of the main argument\" -s source /d destination -readonly");
In results, argumentParser will have 4 arguments :
  • the main argument which has 2 values
  • s argument which has source as value
  • d argument which has destination as value
  • readonly argument which is set as boolean
Public methodCode exampleYArgumentParser(String) Create a new argument parser engine from an argument list.
Example
C#
YArgumentParser argumentParser = new YArgumentParser(new string[]
{ 
    "First value of the main argument",
    "Second value of the main argument",
    "-s",
    "source",
    "/d",
    "destination",
    "-readonly"
});
In results, argumentParser will have 4 arguments :
  • the main argument which has 2 values
  • s argument which has source as value
  • d argument which has destination as value
  • readonly argument which is set as boolean
Top
Properties
 NameDescription
Public propertyArgs Get the argument list as a list of string.
Public propertyArgsLine Get the argument list as a string line.
Public propertyArguments Get the list of YArgument parsed by the engine.
Public propertyItemEnum Get a YArgument from the argName or null if the given param is not found.
Public propertyItemInt32 Get the string argument at the given index.
Public propertyItemString Get a YArgument from the argName or null if the given param is not found.
Top
Methods
 NameDescription
Public methodCode exampleArgumentIsSet(String) Check if the argName is set as a boolean.
Example
C#
YArgumentParser argumentParser = new YArgumentParser(new string[]
{ 
    "First value of the main argument",
    "Second value of the main argument",
    "-s",
    "source",
    "/d",
    "destination",
    "-readonly"
});
In results :
  • argumentParser.ArgumentIsSet(string.Empty) will return false because the main argument cannot be set as boolean
  • argumentParser.ArgumentIsSet("s") will return false because this argument is not set as boolean
  • argumentParser.ArgumentIsSet("readonly") will return true
  • argumentParser.ArgumentIsSet("override") will return false
Public methodCode exampleArgumentIsSetT(T) Check if the argName is set as a boolean.
Example
C#
enum ArumentsTypes
{
    main = 0,
    s,
    m,
    readonly,
}
YArgumentParser argumentParser = new YArgumentParser(new string[]
{ 
    "First value of the main argument",
    "Second value of the main argument",
    "-s",
    "source",
    "/d",
    "destination",
    "-readonly"
});
In results :
  • argumentParser.ArgumentIsSet(ArumentsTypes.main) will return false because the main argument cannot be set as boolean
  • argumentParser.ArgumentIsSet(ArumentsTypes.s) will return false because this argument is not set as boolean
  • argumentParser.ArgumentIsSet(ArumentsTypes.readonly) will return true
  • argumentParser.ArgumentIsSet(ArumentsTypes.m) will return false
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Public methodCode exampleGetArgument(String) Get a YArgument from the argName. Throw a KeyNotFoundException if the given param is not found.
Example
C#
YArgumentParser argumentParser = new YArgumentParser(new string[]
{ 
    "First value of the main argument",
    "Second value of the main argument",
    "-s",
    "source",
    "/d",
    "destination",
    "-readonly"
});
YArgument argument = argumentParser.GetArgument("s");
YArgument mainArgument = argumentParser.GetArgument(string.Empty);
YArgument nullArgument = argumentParser.GetArgument("m");
In results :
  • argument.Values will be { "source" }
  • mainArgument.Values will be { "First value of the main argument", "Second value of the main argument"}
  • nullArgument will be null
Public methodCode exampleGetArgumentT(T) Get a YArgument from the argName. Throw a KeyNotFoundException if the given param is not found.
Example
C#
enum ArumentsTypes
{
    main = 0,
    s,
    m,
    readonly,
}
YArgumentParser argumentParser = new YArgumentParser(new string[]
{ 
    "First value of the main argument",
    "Second value of the main argument",
    "-s",
    "source",
    "/d",
    "destination",
    "-readonly"
});
YArgument argument = argumentParser.GetArgument(ArumentsTypes.s);
YArgument mainArgument = argumentParser.GetArgument(ArumentsTypes.main);
YArgument nullArgument = argumentParser.GetArgument(ArumentsTypes.m);
In results :
  • argument.Values will be { "source" }
  • mainArgument.Values will be { "First value of the main argument", "Second value of the main argument"}
  • nullArgument will be null
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetMainArgument Get the main YArgument or null if not found.
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Public methodCode exampleHasArgument(String) Check if the argName is set.
Example
C#
YArgumentParser argumentParser = new YArgumentParser(new string[]
{ 
    "First value of the main argument",
    "Second value of the main argument",
    "-s",
    "source",
    "/d",
    "destination",
    "-readonly"
});
In results :
  • argumentParser.HasArgument(string.Empty) will return true because it has main argument
  • argumentParser.HasArgument("s") will return true
  • argumentParser.HasArgument("readonly") will return true
  • argumentParser.HasArgument("m") will return false
Public methodCode exampleHasArgumentT(T) Check if the enum value argName is set.
Example
C#
enum ArumentsTypes
{
    main = 0,
    s,
    m,
    readonly,
}
YArgumentParser argumentParser = new YArgumentParser(new string[]
{ 
    "First value of the main argument",
    "Second value of the main argument",
    "-s",
    "source",
    "/d",
    "destination",
    "-readonly"
});
In results :
  • argumentParser.ArgumentIsSet(ArumentsTypes.main) will return true
  • argumentParser.HasArgument(ArumentsTypes.s) will return true
  • argumentParser.HasArgument(ArumentsTypes.readonly) will return true
  • argumentParser.HasArgument(ArumentsTypes.m) will return false
Public methodRegisterArgumentNameSet(String) Register an Argument name set.
Public methodRegisterArgumentNameSetT(T) Register an Argument name set.
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Public methodCode exampleTryGetArgument(String) Try to get a YArgument from the argName or null if the given param is not found.
Example
C#
YArgumentParser argumentParser = new YArgumentParser(new string[]
{ 
    "First value of the main argument",
    "Second value of the main argument",
    "-s",
    "source",
    "/d",
    "destination",
    "-readonly"
});
YArgument argument = argumentParser.GetArgument("s");
YArgument mainArgument = argumentParser.GetArgument(string.Empty);
YArgument nullArgument = argumentParser.GetArgument("m");
In results :
  • argument.Values will be { "source" }
  • mainArgument.Values will be { "First value of the main argument", "Second value of the main argument"}
  • nullArgument will be null
Public methodCode exampleTryGetArgumentT(T) Try to get a YArgument from the argName or null if the given param is not found.
Example
C#
enum ArumentsTypes
{
    main = 0,
    s,
    m,
    readonly,
}
YArgumentParser argumentParser = new YArgumentParser(new string[]
{ 
    "First value of the main argument",
    "Second value of the main argument",
    "-s",
    "source",
    "/d",
    "destination",
    "-readonly"
});
YArgument argument = argumentParser.GetArgument(ArumentsTypes.s);
YArgument mainArgument = argumentParser.GetArgument(ArumentsTypes.main);
YArgument nullArgument = argumentParser.GetArgument(ArumentsTypes.m);
In results :
  • argument.Values will be { "source" }
  • mainArgument.Values will be { "First value of the main argument", "Second value of the main argument"}
  • nullArgument will be null
Top
Fields
 NameDescription
Public fieldStatic memberArgModifiers Get the list of argument modifiers :
  • the dash '-'
  • the slash '/'
Top
Extension Methods
 NameDescription
Public Extension MethodGetMD5HashCode Get the MD5 Hash code of an Objectobj as a string.
(Defined by YObjectExtentionMethods)
Public Extension MethodSerializeObject Serialize an ObjecttoSerialize.
(Defined by YSerializationCenter)
Top
See Also