Show / Hide Table of Contents

MagnetArgs

"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.


Install

Choose the method of your convenience.

Package Manager:

PM> Install-Package MagnetArgs

.Net CLI:

> dotnet add package MagnetArgs

Basic Setup

Step 1. Define your classes

It's as simple as define a class, extend from IronOre and define the Chunk attribute in the properties you want to map.

You can define an alias for your arguments.

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; }
}

Step 2. Attract All

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"
};
var yourObject = new TypeObject();

Magnet.Attract(yourObject, inputArgs);

Step 3. Use

Example:

// Fully Mapped Object
Console.WriteLine(yourObject.StringValue);
Console.WriteLine(yourObject.IntegerValue);
Console.WriteLine(yourObject.DoubleValue);
...

Project References

  • Homepage
  • [Get Started]
  • [Documentation]
  • [API Documentation]
  • Nuget Package
  • Release Notes
  • Contributing Guidelines
  • License
  • Improve this Doc
In This Article
Back to top Generated by DocFX