"Simple argument parser with magnetism"
MagnetArgs helps with the task of mapping arguments to objects. Accelerating the process of define option variables in console applications or map complex objects in a variety of scenarios.
Choose the method of your convenience.
Package Manager:
PM> Install-Package MagnetArgs
.Net CLI:
> dotnet add package MagnetArgs
It's as simple as define a class, decorating with the [Magnetizable] attribute and decorating the properties you want to map with the [Argument] attribute.
You can define an alias for your arguments, set mapping rules and add parsing functions as you need.
Example:
[Magnetizable]
class TypeObject
{
[Argument("string-value", Alias = "string")]
public string StringValue { get; set; }
[Argument("char-value", Alias = "char")]
public char CharValue { get; set; }
[Argument("integer-value", Alias = "int")]
public int IntegerValue { get; set; }
[Argument("long-value", Alias = "long")]
public long LongValue { get; set; }
[Argument("boolean-value", Alias = "bool")]
public bool BooleanValue { get; set; }
[Argument("float-value", Alias = "float")]
public float FloatValue { get; set; }
[Argument("double-value", Alias = "double")]
public double DoubleValue { get; set; }
[Argument("decimal-value", Alias = "decimal")]
public decimal DecimalValue { get; set; }
}
With an instance of your object, you can magnetize and attract values. Provide the object and arguments to <Magnet.Attract>. They will be assigned automatically.
Example:
var inputArgs = new string[] {
"-string", "This is an String",
"-char", "C",
"-int", "128",
"-long", "128",
"-bool", "true",
"-float", "12.8",
"-double", "12.8",
"-decimal", "12.8"
};
// Get object from arguments
var yourObject = Magnet.Attract<TypeObject>(inputArgs);
// OR Send an object as reference
var yourObject = new TypeObject();
Magnet.Attract(inputArgs, yourObject);
Example:
// Fully Mapped Object
Console.WriteLine(yourObject.StringValue);
Console.WriteLine(yourObject.IntegerValue);
Console.WriteLine(yourObject.DoubleValue);
...