Skip to content

Commit

Permalink
Expand readme with cil export info
Browse files Browse the repository at this point in the history
  • Loading branch information
BastianBlokland committed Aug 7, 2019
1 parent 4615965 commit ab5d4a0
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
|----------|-------------|--------------|
| [![NuGet](https://img.shields.io/nuget/v/EnumGenerator.Cli.svg)](https://www.nuget.org/packages/EnumGenerator.Cli/) | [![NuGet](https://img.shields.io/nuget/v/EnumGenerator.GlobalTool.svg)](https://www.nuget.org/packages/EnumGenerator.GlobalTool/) | [![NuGet](https://img.shields.io/nuget/v/EnumGenerator.Core.svg)](https://www.nuget.org/packages/EnumGenerator.Core/) |

Dotnet cli tool for generating c# enums from json files.
Dotnet cli tool for generating c# / cil enums from json files.

## Description
If you have config in json files it can be nice to have a enum to reference in the code instead of
Expand Down
27 changes: 22 additions & 5 deletions example/Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<!-- Generate the enums before build -->
<Target Name="GenerateMonthsEnum" BeforeTargets="BeforeBuild">
<Target Name="GenerateMonthsEnumCSharp" BeforeTargets="BeforeBuild">
<Exec Command="dotnet enum-generator \
-i months.json \
-o Months.g.cs \
Expand All @@ -18,19 +18,36 @@
--comment 'Enum with all the months.'"/>
</Target>

<Target Name="GenerateExpensiveProductsEnum" BeforeTargets="BeforeBuild">
<Target Name="GenerateMonthsEnumCil" BeforeTargets="BeforeBuild">
<Exec Command="dotnet enum-generator \
-i months.json \
-o Months.g.il \
-t cil \
--entryname name \
--entryvalue number \
--namespace Example"/>
</Target>

<Target Name="GenerateExpensiveProductsEnumCSharp" BeforeTargets="BeforeBuild">
<Exec Command="dotnet enum-generator \
-i products.json \
-o ExpensiveProducts.g.cs \
--collection '..Products[?(@.Price >= 10)]' \
--entryname Name"/>
</Target>

<ItemGroup>
<Target Name="GenerateExpensiveProductsEnumCil" BeforeTargets="BeforeBuild">
<Exec Command="dotnet enum-generator \
-i products.json \
-o ExpensiveProducts.g.il \
-t cil \
--collection '..Products[?(@.Price >= 10)]' \
--entryname Name"/>
</Target>

<ItemGroup>
<!-- Tools -->
<DotNetCliToolReference Include="EnumGenerator.Cli" Version="*" />

<DotNetCliToolReference Include="EnumGenerator.Cli" Version="3.2.*" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions example/ExpensiveProducts.g.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Generated by: EnumGenerator.Core - 3.0.1187.0
// Generated by: EnumGenerator.Core - 3.2.1193.0
// </auto-generated>
//------------------------------------------------------------------------------

using System.CodeDom.Compiler;

[GeneratedCode("EnumGenerator.Core", "3.0.1187.0")]
[GeneratedCode("EnumGenerator.Core", "3.2.1193.0")]
public enum ExpensiveProducts
{
Drill = 0,
Expand Down
21 changes: 21 additions & 0 deletions example/ExpensiveProducts.g.il
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Generated by: EnumGenerator.Core - 3.2.1193.0
// </auto-generated>
//------------------------------------------------------------------------------

.assembly extern mscorlib { }

.module ExpensiveProducts.dll
.assembly ExpensiveProducts
{
.ver 1:0:0:0
}

.class public sealed ExpensiveProducts extends [mscorlib]System.Enum
{
.field public specialname rtspecialname int32 value__

.field public static literal valuetype ExpensiveProducts Drill = int32(0)
.field public static literal valuetype ExpensiveProducts Hammer = int32(1)
}
4 changes: 2 additions & 2 deletions example/Months.g.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Generated by: EnumGenerator.Core - 3.0.1187.0
// Generated by: EnumGenerator.Core - 3.2.1193.0
// </auto-generated>
//------------------------------------------------------------------------------

Expand All @@ -11,7 +11,7 @@ namespace Example
/// <summary>
/// Enum with all the months.
/// </summary>
[GeneratedCode("EnumGenerator.Core", "3.0.1187.0")]
[GeneratedCode("EnumGenerator.Core", "3.2.1193.0")]
public enum Months
{
/// <summary>
Expand Down
31 changes: 31 additions & 0 deletions example/Months.g.il
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Generated by: EnumGenerator.Core - 3.2.1193.0
// </auto-generated>
//------------------------------------------------------------------------------

.assembly extern mscorlib { }

.module Months.dll
.assembly Months
{
.ver 1:0:0:0
}

.class public sealed Example.Months extends [mscorlib]System.Enum
{
.field public specialname rtspecialname int32 value__

.field public static literal valuetype Example.Months January = int32(1)
.field public static literal valuetype Example.Months February = int32(2)
.field public static literal valuetype Example.Months March = int32(3)
.field public static literal valuetype Example.Months April = int32(4)
.field public static literal valuetype Example.Months May = int32(5)
.field public static literal valuetype Example.Months June = int32(6)
.field public static literal valuetype Example.Months July = int32(7)
.field public static literal valuetype Example.Months August = int32(8)
.field public static literal valuetype Example.Months September = int32(9)
.field public static literal valuetype Example.Months October = int32(10)
.field public static literal valuetype Example.Months November = int32(11)
.field public static literal valuetype Example.Months December = int32(12)
}
4 changes: 3 additions & 1 deletion src/EnumGenerator.Cli/readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# **EnumGenerator** Cli tool.

Can be used to generate c# enum files from json files.
Can be used to generate c# / cil enum files from json files.

## Installation

Expand All @@ -21,6 +21,8 @@ There two ways to invoke the tool:
</Target>
```

To generate a cil file use the `-t cil` argument.

## Help
For additional info on the arguments run `dotnet enum-generator --help`

Expand Down
12 changes: 9 additions & 3 deletions src/EnumGenerator.Core/readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# **EnumGenerator** Core library.

Library that can be used to generate c# enum files based on json files.
Library that can be used to generate c# / cil enum files based on json files.

Can be used for more complex integration into a build pipeline, for simple use-cases consider one of the pre-made tools:
* [**EnumGenerator.Cli**](https://www.nuget.org/packages/EnumGenerator.Cli/)
Expand Down Expand Up @@ -40,9 +40,15 @@ var inputJson = File.ReadAllText("input.json");
var enumDefinition = context.MapEnum(inputJson, "TestEnum");
```

4. Export the enum:
4. Export the csharp enum:
```c#
var csharp = enumDefinition.Export();
var csharp = enumDefinition.ExportCSharp();
```
or

4. Export the cil enum:
```c#
var cil = enumDefinition.ExportCil(assemblyName: "TestEnum");
```

## Help
Expand Down
4 changes: 3 additions & 1 deletion src/EnumGenerator.GlobalTool/readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# **EnumGenerator** Global tool.

Can be used to generate c# enum files from json files.
Can be used to generate c# / cil enum files from json files.

## Installation

Expand All @@ -15,6 +15,8 @@ Invoke the tool using the `enum-generator` alias
enum-generator -i example.enum -o example.g.cs
```

To generate a cil file use the `-t cil` argument.

## Help
For additional info on the arguments run `enum-generator --help`

Expand Down

0 comments on commit ab5d4a0

Please sign in to comment.