Cli tool | Global tool | Core library |
---|---|---|
Dotnet cli tool for generating c# / f# / vb / cil enums from json files.
If you have config in json files it can be nice to have a enum to reference in the code instead of having to hard code values, this tool allows you to generate that enum.
There are 4 different ways to use the generator:
Usecase | Project | Documentation |
---|---|---|
Build integration | Cli | Cli Readme |
Command line | GlobalTool | GlobalTool Readme |
Manual library integration | Core | Core Readme |
Unity3D package | UnityPackage | UnityPackage Readme |
To be able to handle many different file structures the generator takes in a number of JsonPath entries:
Argument | Usage |
---|---|
collection | Path to the main collection in the json |
entryname | Path to the string name of a single entry in the above collection |
entryvalue | Path to the number value of a single entry in the above collection |
entrycomment | Path to the string comment of a single entry in the above collection |
Note: If no entryvalue
is provided the index in the collection will be used as the value.
Here's a couple structure examples:
-
Outer array
json:
[ { "name": "A", "value": 1 }, { "name": "B", "value": 2 }, ]
options:
collection = "[*]" entryname = "name" entryvalue = "value"
-
Inner array
json:
{ "entries": [ "A", "B" ] }
options:
collection = "entries[*]" entryname = "$"
-
Inner object
json:
{ "entries": [ { "info": { "name": "A" }, "value": 10 }, { "info": { "name": "B" }, "value": 20 } ] }
options:
collection = "entries[*]" entryname = "info.name" entryvalue = "value"
-
Deep search
json:
{ "collection1": { "entries": [ { "name": "A" }, { "name": "B" } ] }, "collection2": { "entries": [ { "name": "C" }, { "name": "D" } ] } }
options:
collection = "..entries[*]" entryname = "name" entryvalue = "value"
-
Filtering
json:
[ { "name": "A", "value": 1, "active": false }, { "name": "B", "value": 2, "active": true }, { "name": "C", "value": 3, "active": true }, { "name": "D", "value": 4, "active": false } ]
options:
collection = "[?(@.active == true)]" entryname = "name" entryvalue = "value"
Note: Enable verbose
logging to get more output about what the mapper is doing.
An example can be found in the example directory.