0
NJsonSchema를 사용하여 C# 클래스를 생성하려고하지만 "anonymous_"배열에있는 개체의 클래스 이름을 지정하고 있습니다.컬렉션 속성 이름에 따라 컬렉션에있는 개체의 C# 클래스 이름을 생성합니다.
예를 들어,이 JSON 스키마는
"Identifiers": { "type": "array", "items": { "type": "object", "properties": { "ID": { "type": "string" }, "IDType": { "type": "string" } }, "required": [ "ID", "IDType" ] }가에 따라 콜렉션에 객체의 이름을 NJsonSchema을 강제 할 수있는 방법이 있는지 궁금이 C#을 속성과 클래스
[Newtonsoft.Json.JsonProperty("Identifiers", Required = Newtonsoft.Json.Required.Always)] [System.ComponentModel.DataAnnotations.Required] public System.Collections.ObjectModel.ObservableCollection<Anonymous> Identifiers { get; set; } = new System.Collections.ObjectModel.ObservableCollection<Anonymous>();
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "9.3.0.0")] public partial class Anonymous { [Newtonsoft.Json.JsonProperty("ID", Required = Newtonsoft.Json.Required.Always)] [System.ComponentModel.DataAnnotations.Required] public string ID { get; set; } [Newtonsoft.Json.JsonProperty("IDType", Required = Newtonsoft.Json.Required.Always)] [System.ComponentModel.DataAnnotations.Required] public string IDType { get; set; } public string ToJson() { return Newtonsoft.Json.JsonConvert.SerializeObject(this); } public static Anonymous FromJson(string data) { return Newtonsoft.Json.JsonConvert.DeserializeObject<Anonymous>(data); } }
를 생성 니펫을 컬렉션 이름의 특수화 된 버전 (예 :이 경우 anonymous
클래스의 이름을 Identifier
과 같은 이름으로 지정하려는 경우 클래스 des 컬렉션에 Identifiers
라고하는 관료 개체가 있음). 이 사용자 지정 TypeNameGenerator 사용하려고했지만 컬렉션 이름을 Generate
함수에 제공되지 않습니다. 스키마를 수정할 수있는 경우