MyIO.ParseJsonAsClass.SourceGenerator 0.0.1

dotnet add package MyIO.ParseJsonAsClass.SourceGenerator --version 0.0.1                
NuGet\Install-Package MyIO.ParseJsonAsClass.SourceGenerator -Version 0.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MyIO.ParseJsonAsClass.SourceGenerator" Version="0.0.1">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MyIO.ParseJsonAsClass.SourceGenerator --version 0.0.1                
#r "nuget: MyIO.ParseJsonAsClass.SourceGenerator, 0.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MyIO.ParseJsonAsClass.SourceGenerator as a Cake Addin
#addin nuget:?package=MyIO.ParseJsonAsClass.SourceGenerator&version=0.0.1

// Install MyIO.ParseJsonAsClass.SourceGenerator as a Cake Tool
#tool nuget:?package=MyIO.ParseJsonAsClass.SourceGenerator&version=0.0.1                

使用 Source generator 实现类似于 Visual Studio 菜单“编辑”>"选择性粘贴">"将 JSON 粘贴为类"的功能,将 JSON 字符串转换为 C# 类。

Use the Source generator to implement functionality similar to the Visual Studio menu "Edit" > "Paste Special" > "Paste JSON as Class" to convert JSON strings to C# classes.

如何使用 How to use

  1. 在项目中安装 NuGet 包

Install the NuGet package in the project

dotnet add package MyIO.ParseJsonAsClass.SourceGenerator
  1. 在项目中添加一个 JSON 文件

Add a JSON file in the project

{
  "code": 200,
  "msg": "ok",
  "obj":{"a":1,"subObj":{"a":1}},
  "data": [
    "1","2"
  ],
  "arrar": [
    {"a":1.0},
    {"a":null}
  ]
}
  1. 在项目中添加一个 C# 文件

Add a C# file in the project


using MyIO;
namespace ConsoleApp1
{
    [ParseJsonAsClass("sample.txt")]
    internal partial class Class1
    { 
    }
}

sample.txt 是上一步中添加的 JSON 文件的名称。

sample.txt is the name of the JSON file added in the previous step.

  1. 编译项目

Build the project

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.1 280 9/29/2022