Skip to content

Transform any json ( including appsettings ) into a class

License

Notifications You must be signed in to change notification settings

ignatandrei/RSCG_JSON2Class

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RSCG_JSON2Class

Transform any json ( including appsettings ) into a class

Usage

Install the nuget package into your project

<ItemGroup>
  <PackageReference Include="RSCG_JSON2Class" Version="2024.2.29.807" OutputItemType="Analyzer" ReferenceOutputAssembly="false"  />
</ItemGroup>
<PropertyGroup>
	<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
	<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>

Verify that the json file is set analyzer ( and , if you want to deserialize, copy to the output directory)

<ItemGroup>
  <None Remove="testData.json" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="testData.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</AdditionalFiles>
</ItemGroup>

Access from C# code

using System.Text.Json;
var testData = JsonSerializer.Deserialize<JSON2ClassConsole.SettingsJson.testData>(System.IO.File.ReadAllText("testData.json"));
ArgumentNullException.ThrowIfNull(testData);
Console.WriteLine(testData.Logging.LogLevel.Default);
Console.WriteLine(testData.DictData.Number_2);

About

Transform any json ( including appsettings ) into a class

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages