OutWit.Common.CommandLine
1.0.0
dotnet add package OutWit.Common.CommandLine --version 1.0.0
NuGet\Install-Package OutWit.Common.CommandLine -Version 1.0.0
<PackageReference Include="OutWit.Common.CommandLine" Version="1.0.0" />
paket add OutWit.Common.CommandLine --version 1.0.0
#r "nuget: OutWit.Common.CommandLine, 1.0.0"
// Install OutWit.Common.CommandLine as a Cake Addin #addin nuget:?package=OutWit.Common.CommandLine&version=1.0.0 // Install OutWit.Common.CommandLine as a Cake Tool #tool nuget:?package=OutWit.Common.CommandLine&version=1.0.0
OutWit.Common.CommandLine
Overview
OutWit.Common.CommandLine is a lightweight library designed to simplify serialization and deserialization of command-line arguments in .NET applications. By leveraging attributes from the CommandLine
library, it enables seamless mapping of object properties to command-line options and vice versa.
Features
1. Command-Line Serialization
The library allows converting objects into command-line argument strings based on the OptionAttribute
.
Example
using OutWit.Common.CommandLine;
using CommandLine;
public class Options
{
[Option('n', "name", Required = true, HelpText = "The name of the user.")]
public string Name { get; set; } = string.Empty;
[Option('a', "age", HelpText = "The age of the user.")]
public int Age { get; set; }
[Option('v', "verbose", HelpText = "Enable verbose mode.")]
public bool Verbose { get; set; }
}
var options = new Options
{
Name = "John",
Age = 30,
Verbose = true
};
string commandLine = options.SerializeCommandLine();
Console.WriteLine(commandLine);
// Output: --name John --age 30 --verbose
2. Command-Line Deserialization
Easily parse command-line arguments into strongly typed objects.
Example
string[] args = { "--name", "John", "--age", "30", "--verbose" };
var options = args.DeserializeCommandLine<Options>();
Console.WriteLine(options.Name); // Output: John
Console.WriteLine(options.Age); // Output: 30
Console.WriteLine(options.Verbose); // Output: True
3. Attribute-Based Configuration
The library uses OptionAttribute
from the CommandLine
library to define mappings between object properties and command-line options. Supported configurations include:
- Short and long option names
- Required and optional properties
- Help text for documentation
Installation
Install the package via NuGet:
Install-Package OutWit.Common.CommandLine
API Reference
SerializeCommandLine
public static string SerializeCommandLine<T>(this T me)
- Description: Converts an object into a command-line argument string based on
OptionAttribute
annotations. - Returns: A
string
representing the serialized command-line arguments.
DeserializeCommandLine
From String
public static T DeserializeCommandLine<T>(this string me)
- Description: Parses a command-line argument string into an object of type
T
. - Returns: An instance of
T
populated with parsed values.
From String Array
public static T DeserializeCommandLine<T>(this string[] me)
- Description: Parses a string array of command-line arguments into an object of type
T
. - Returns: An instance of
T
populated with parsed values.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- CommandLineParser (>= 2.9.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on OutWit.Common.CommandLine:
Package | Downloads |
---|---|
OutWit.InterProcess
Inter Process Communicaton base logic |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 129 | 1/2/2025 |