GMA.ArgumentsMarshalerLib
1.0.0
dotnet add package GMA.ArgumentsMarshalerLib --version 1.0.0
NuGet\Install-Package GMA.ArgumentsMarshalerLib -Version 1.0.0
<PackageReference Include="GMA.ArgumentsMarshalerLib" Version="1.0.0" />
paket add GMA.ArgumentsMarshalerLib --version 1.0.0
#r "nuget: GMA.ArgumentsMarshalerLib, 1.0.0"
// Install GMA.ArgumentsMarshalerLib as a Cake Addin
#addin nuget:?package=GMA.ArgumentsMarshalerLib&version=1.0.0
// Install GMA.ArgumentsMarshalerLib as a Cake Tool
#tool nuget:?package=GMA.ArgumentsMarshalerLib&version=1.0.0
ArgumentReader
Description
With Argument Reader command line argumets can be passed into a .net core application. The standard project assist 4 types of argumnets:
- Boolean
- Strings (*)
- Integer (#)
- Doubles (##)
Own argument tyoes can be build with own classes. They need to inherit form the ArgumentMarshalerLib. Libraries are loading dynamicaly on startup. It is not necessary to recompile the complete solution.
Structure
Arguments paramenter = new Arguments("Path to Marshaler Liraries", "Schema", "Arugment Array")
Available Marshalers (Standards)
Schema
- Parameter name
- Marshaler type
Example
Arguments parameter = new Arguments("...", "enabled, text*, number#, decimal##")
enabled b = parameter.GetValue<bool>("enabled") // false
text b = parameter.GetValue<string>("text") // false
number b = parameter.GetValue<int>("number") // false
decimal b = parameter.GetValue<double>("decimal") // false
Boolean:
Arguments.exe -a -b
static void Main(string[] args)
{
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)
{
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)
{
parameter = new Arguments(@".\Marshaler", "a#", args);
int a = parameter.GetValue<int>("a") // 1234
//...
}
Double:
Arguments.exe -a 123,456
static void Main(string[] args)
{
parameter = new Arguments(@".\Marshaler", "a##", args);
double a = parameter.GetValue<double>("a") // 123,456
//...
}
Build your own Marshaler
- Create a new VisualStudio .net Standard Class (??MarshalerLib)
- Link a new projekt reference to ArgumentMarshalerLib.dll (in this repository)
- Write Marshaler (See example code below)
- Copy the TestMarshalerLib.dll to the Marshaler directory in your project
- Implement the ? in your schema (e.g "mymarshaler?")
public class TestMarshalerLib : ArgumentMarshalerLib.ArgumentMarshaler
{
// Only schemas allowed that are not used (string.empty, *, #, ## are already used form standard marshalers)
public override string Schema => "?";
public override void Set(Iterator<string> currentArgument)
{
try
{
// If implementation should be use an argument behind the command (e.g -a ??),
// it is neccassary to move the Iterator to the nex position
Value = currentArgument.Next();
}
catch (ArgumentOutOfRangeException)
{
throw new TestgMarshalerException(ErrorCode.MISSING);
}
// If no argument behind the command is used just add your value
Value = "This is my personal marshaler";
}
public class TestgMarshalerException : ArgumentMarshalerLib.ArgumentsException
{
public TestgMarshalerException() { }
public TestgMarshalerException(ErrorCode errorCode) : base(errorCode) { }
public override string ErrorMessage()
{
switch (ErrorCode)
{
case ErrorCode.MISSING:
return $"Could not find string parameter for -{ErrorArgumentId}";
default:
return string.Empty;
}
}
}
}
Reference
The original Argument Marshaler was written in Java and published by Robert c. Martin in his book Clean Code. This project adapt his implementation and extends it dynamically.
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. |
.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
- No dependencies.
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 |
---|