ArgumentsLib 1.0.0

Suggested Alternatives

ArgumentReader

Additional Details

Relaunched the project with a new name.

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package ArgumentsLib --version 1.0.0
                    
NuGet\Install-Package ArgumentsLib -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ArgumentsLib" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ArgumentsLib" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ArgumentsLib" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ArgumentsLib --version 1.0.0
                    
#r "nuget: ArgumentsLib, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ArgumentsLib@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ArgumentsLib&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ArgumentsLib&version=1.0.0
                    
Install as a Cake Tool

Version: 1.0 Release Build Status License: GPL v3

Argument Reader

Description:

With Argument Reader command line arguments can be passed into a .net core application. The standard project assist 4 types of arguments:

  • Boolean
  • Strings (*)
  • Integers (#)
  • Doubles (##)

Own argument types can be build with own classes. They need to inherit from the ArgumentMarshalerLib. Libraries are loading dynamically on startup. It is not necessary to recompile the complete solution.


Structure

Arguments parameter = new Arguments("Path to Marshaler Libraries", "Schema", "Argument Array");

Available Marshalers (Standard)

  • BooleanMarshalerLib.dll
  • StringMarshalerLib.dll
  • IntegerMarshalerLib.dll
  • DoubleMarshalerLib.dll

Schema

  1. Parameter name
  2. Marshaler type

Example

Arguments parameter = new Arguments("...", "enabled,text*,number#,comma##", "...");
bool enabled = parameter.GetValue<bool>("enabled");
string text = parameter.GetValue<string>("text");
int number = parameter.GetValue<int>("number");
double comma = parameter.GetValue<double>("comma");

Parse Arguments

Boolean:

Arguments.exe -a
static void Main(string[] args)
{
Arguments parameter = new Arguments(@".\Marshaler", "a,b*", args);
bool a = parameter.GetValue<bool>("a"); // True
bool b = parameter.GetValue<bool>("b"); // False
// ...
}

String:

Arguments.exe -a "This is a Text"
static void Main(string[] args)
{
Arguments parameter = new Arguments(@".\Marshaler", "a*", args);
string a = parameter.GetValue<string>("a"); // This is a Text
// ...
}

Integer:

Arguments.exe -a 1234
static void Main(string[] args)
{
Arguments parameter = new Arguments(@".\Marshaler", "a#", args);
int a = parameter.GetValue<int>("a"); // 1234
// ...
}

Double:

Arguments.exe -a 1234,4321
static void Main(string[] args)
{
Arguments parameter = new Arguments(@".\Marshaler", "a##", args);
double a = parameter.GetValue<double>("a"); // 1234,4321
// ...
}

Build your own Marshaler

  1. Create a new VisualStudio .NET Standard Classlibrary (??MarshalerLib)
  2. Link a new project reference to ArgumentMarshalerLib.dll (in this repository)
  3. Write Marshaler (See example code below)
  4. Copy the TestMarshalerLib.dll to the Marshaler directory in your project
  5. Implement the ? in your schema (e.g. "mymarshaler?")
using System;
using ArgumentMarshalerLib;

namespace TestMarshalerLib
{
    public class TestMarshalerLib : ArgumentMarshaler
    {
        // Only schemas allowed that are not used (string.Empty, *, #, ## are already used from standard marshalers)
        public override string Schema => "?";

        public override void Set(Iterator<string> currentArgument)
        {
            try
            {
                // If implementation should use an argument behind the command (e.g. -a "??"),
                // it is necessary to move the Iterator to the next position.
                Value = currentArgument.Next();
            }
            catch (ArgumentOutOfRangeException)
            {
                throw new TestMarshalerException(ErrorCode.MISSING);
            }

            // If no argument behind the command is used just add your value
            Value = "This is my personal marshaler";
        }

        public class TestMarshalerException : ArgumentsException
        {
            public TestMarshalerException() { }

            public TestMarshalerException(ErrorCode errorCode) : base(errorCode) { }

            public override string ErrorMessage()
            {
                switch (ErrorCode)
                {
                    case ErrorCode.MISSING:
                        return $"Could not find test parameter for -{ErrorArgumentId}";
                    default:
                        return string.Empty;
                }
            }
        }

    }
}

References

The original Argument Marshaler was written in Java and published by Robert C. Martin in his book Clean Code. This project adapt his implementations and extends it dynamically.

Product 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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated