Click or drag to resize

Arguments Class

Represents an ordered set of arguments along with optional arguments parsed from a command-line.
Inheritance Hierarchy
SystemObject
  GSF.ConsoleArguments

Namespace: GSF.Console
Assembly: GSF.Core (in GSF.Core.dll) Version: 2.4.207-beta+1781b796b2aa7a54013a031eb432fe4ccee31867
Syntax
View Source

The Arguments type exposes the following members.

Constructors
 NameDescription
Public methodArguments(String) Initializes a new instance of the Arguments class.
Protected methodArguments(SerializationInfo, StreamingContext) Creates a new Arguments from serialization parameters.
Public methodArguments(String, Boolean) Initializes a new instance of the Arguments class.
Public methodArguments(String, String) Initializes a new instance of the Arguments class.
Public methodArguments(String, String, Boolean) Initializes a new instance of the Arguments class.
Top
Properties
 NameDescription
Public propertyContainsHelpRequest Gets a boolean value that indicates whether the command-line command contains request for displaying help.
Public propertyCount Gets the total number of arguments (ordered and optional) present in the command-line command.
Protected propertyInternalDictionary Gets the dictionary containing all of the arguments present in the command-line command.
Public propertyItem Gets the value for the specified argument from the command-line command.
Public propertyOrderedArgCount Gets the total number of ordered arguments in the command-line command.
Public propertyOrderedArgID Gets the prefix text in the identifier of ordered arguments present in the command-line command.
Public propertyOrderedArgs Gets the ordered arguments as an array of strings.
Top
Methods
 NameDescription
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Public methodStatic memberEscape Escapes a string so that it will be parsed as a single argument by the ToArgs(String) method.
Public methodExists Gets a boolean value that indicates whether the specified argument is present in the command-line command.
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
Public methodGetEnumerator Returns an IEnumerator for iterating through all the command-line command arguments.
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetObjectData Populates a SerializationInfo with the data needed to serialize the target object.
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Public methodStatic memberParseCommand This function can be used to parse a single parameterized string and turn it into an array of parameters.
Public methodStatic memberToArgs Provides an array of arguments parsed from the given command using parsing rules similar to those used in POSIX environments.
Public methodToString Gets a string representation of the Arguments object.
(Overrides ObjectToString)
Public methodTryGetValue Gets the value associated with the specified argument in the command-line command.
Top
Fields
 NameDescription
Public fieldStatic memberDefaultOrderedArgID Default value for OrderedArgID.
Public fieldStatic memberTokenRegex Regular expression pattern for tokenizing a list of arguments.
Top
Extension Methods
 NameDescription
Public Extension MethodAllParallelKeyValuePairString, String Determines whether all elements of a sequence satisfy a condition with each item being tested in parallel.
(Defined by CollectionExtensions)
Public Extension MethodDistinctByKeyValuePairString, String, TKey Returns only the elements whose keys are distinct.
(Defined by CollectionExtensions)
Public Extension MethodGetEnumValueOrDefault Gets the enumeration constant for value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Public Extension MethodGetEnumValueOrDefaultT Gets the enumeration constant for this value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Public Extension MethodMajorityKeyValuePairString, String Returns the majority value in the collection, or default type value if no item represents the majority.
(Defined by CollectionExtensions)
Public Extension MethodMajorityKeyValuePairString, String Returns the majority value in the collection, or defaultValue if no item represents the majority.
(Defined by CollectionExtensions)
Public Extension MethodMajorityByKeyValuePairString, String, TKey Returns the majority value in the collection, or default type value if no item represents the majority.
(Defined by CollectionExtensions)
Public Extension MethodMajorityByKeyValuePairString, String, TKey Returns the majority value in the collection, or defaultValue if no item represents the majority.
(Defined by CollectionExtensions)
Public Extension MethodMaxKeyValuePairString, StringReturns the largest item from the enumeration.
(Defined by CollectionExtensions)
Public Extension MethodMaxKeyValuePairString, StringReturns the largest item from the enumeration.
(Defined by CollectionExtensions)
Public Extension MethodMaxByKeyValuePairString, String, TKeySelects the largest item from the enumeration.
(Defined by CollectionExtensions)
Public Extension MethodMedianKeyValuePairString, String Gets the median item(s) from an enumeration, i.e., one return item for odd lengths, two for even lengths.
(Defined by CollectionExtensions)
Public Extension MethodMiddleKeyValuePairString, String Gets the middle item(s) from an enumeration, i.e., one return item for odd lengths, two for even lengths.
(Defined by CollectionExtensions)
Public Extension MethodMinKeyValuePairString, StringReturns the smallest item from the enumeration.
(Defined by CollectionExtensions)
Public Extension MethodMinKeyValuePairString, StringReturns the smallest item from the enumeration.
(Defined by CollectionExtensions)
Public Extension MethodMinByKeyValuePairString, String, TKeySelects the smallest item from the enumeration.
(Defined by CollectionExtensions)
Public Extension MethodMinorityKeyValuePairString, String Returns the minority value in the collection, or default type value if no item represents the minority.
(Defined by CollectionExtensions)
Public Extension MethodMinorityKeyValuePairString, String Returns the minority value in the collection, or defaultValue if no item represents the minority.
(Defined by CollectionExtensions)
Public Extension MethodMinorityByKeyValuePairString, String, TKey Returns the minority value in the collection, or default type value if no item represents the majority.
(Defined by CollectionExtensions)
Public Extension MethodMinorityByKeyValuePairString, String, TKey Returns the minority value in the collection, or defaultValue if no item represents the majority.
(Defined by CollectionExtensions)
Public Extension MethodStandardDeviationKeyValuePairString, String Computes the standard deviation over a sequence of Double values.
(Defined by NumericalAnalysisExtensions)
Public Extension MethodStandardDeviationKeyValuePairString, String Computes the standard deviation over a sequence of Decimal values.
(Defined by NumericalAnalysisExtensions)
Public Extension MethodStandardDeviationKeyValuePairString, String Computes the standard deviation over a sequence of Single values.
(Defined by NumericalAnalysisExtensions)
Public Extension MethodToDelimitedStringKeyValuePairString, StringConverts an enumeration to a string, using the default delimiter ("|") that can later be converted back to a list using LoadDelimitedString.
(Defined by CollectionExtensions)
Public Extension MethodToDelimitedStringKeyValuePairString, StringConverts an enumeration to a string that can later be converted back to a list using LoadDelimitedString.
(Defined by CollectionExtensions)
Public Extension MethodToDelimitedStringKeyValuePairString, StringConverts an enumeration to a string that can later be converted back to a list using LoadDelimitedString.
(Defined by CollectionExtensions)
Public Extension MethodToPagedListKeyValuePairString, String Gets a PagedListT to paginate source enumeration for a given page and specified pageSize.
(Defined by CollectionExtensions)
Top
Example
This example shows how to parse a command-line command that does not contain an executable name:
C#
using System;
using GSF;
using GSF.Console;

class Program
{
    static void Main()
    {
        Arguments args = new Arguments("Sample.txt -wrap=true");
        string file = args["OrderedArg1"];
        bool wrapText = args["wrap"].ParseBoolean();

        Console.WriteLine(string.Format("File: {0}", file));
        Console.WriteLine(string.Format("Wrap text: {0}", wrapText));
        Console.ReadLine();
    }
}
This example shows how to parse a command-line command that contains an executable name in it:
C#
using System;
using GSF.Console;

class Program
{
    static void Main()
    {
        // Environment.CommandLine = @"""c:\program files\tva\theme application\app.exe"" Document1.dcx -theme=default"
        Arguments args = new Arguments(Environment.CommandLine, true);
        string doc = args["OrderedArg1"];
        string theme = args["theme"];

        Console.WriteLine(string.Format("Document: {0}", doc));
        Console.WriteLine(string.Format("Application theme: {0}", theme));
        Console.ReadLine();
    }
}
See Also