首页 > 解决方案 > CodeGeneration 到 Json 文件的构建时间类

问题描述

我想知道是否可以在构建 dotnet 核心期间创建一个流程来执行以下操作。

假设我有一个包含属性的 json 文件:

[
      {
          "name": "Jack",
          "age": "12",
          "issue": "some issue"
      },
      {
          "name": "Jhon",
          "age": "132",
          "issue": "some issue - 1"
      }
  ]

和一个匹配的类 Preson

public class Person
{
  public string Name {get;}
  public string Age {get;}
  public string Issue {get;}

  public Person(string age, string age, string issue)
  {
    ...
  } 
}

在构建时间或使用分析器时,我想创建一个这样的类

public static class Persons
{
    public static Person Jhon => return new Person(...);
}

任何想法 ?

标签: c#.net-corecode-generation

解决方案


推荐阅读