问题描述
{
"properties": {
"ArrayTypeProperty": {
"type": "array","items": { "$ref": "#/deFinitions/types" }
}
},"deFinitions": {
"types": {
"properties": {
"material": {
"type": "string","enum": [
"beds","offscreen","wind","weather"
]
},"invisible": {
"type": "string","enum": [
"air","atmosphere"
]
},"music": {
"type": "string","enum": [
"rock","Metal","classic"
]
}
}
}
},"additionalProperties": false
}
var schemaJson = await JsonSchema.FromJsonAsync(m_schema);
var generator = new CSharpGenerator(schemaJson);
var file = generator.GenerateFile("MyClass");
这将生成以下类:
//----------------------
// <auto-generated>
// Generated using the njsonSchema v10.1.24.0 (Newtonsoft.Json v12.0.0.0) (http://njsonSchema.org)
// </auto-generated>
//----------------------
namespace MyNamespace
{
#pragma warning disable // disable all warnings
[System.CodeDom.Compiler.GeneratedCode("njsonSchema","10.1.24.0 (Newtonsoft.Json v12.0.0.0)")]
public partial class Types
{
[Newtonsoft.Json.JsonProperty("material",required = Newtonsoft.Json.required.disallowNull,NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public TypesMaterial Material { get; set; }
[Newtonsoft.Json.JsonProperty("invisible",NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public TypesInvisible Invisible { get; set; }
[Newtonsoft.Json.JsonProperty("music",NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public TypesMusic Music { get; set; }
private System.Collections.Generic.IDictionary<string,object> _additionalProperties = new System.Collections.Generic.Dictionary<string,object>();
[Newtonsoft.Json.JsonExtensionData]
public System.Collections.Generic.IDictionary<string,object> AdditionalProperties
{
get { return _additionalProperties; }
set { _additionalProperties = value; }
}
}
[System.CodeDom.Compiler.GeneratedCode("njsonSchema","10.1.24.0 (Newtonsoft.Json v12.0.0.0)")]
public partial class MyClass
{
[Newtonsoft.Json.JsonProperty("ArrayTypeProperty",NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.ICollection<Types> ArrayTypeProperty { get; set; }
}
[System.CodeDom.Compiler.GeneratedCode("njsonSchema","10.1.24.0 (Newtonsoft.Json v12.0.0.0)")]
public enum TypesMaterial
{
[System.Runtime.Serialization.EnumMember(Value = @"beds")]
beds = 0,[System.Runtime.Serialization.EnumMember(Value = @"offscreen")]
Offscreen = 1,[System.Runtime.Serialization.EnumMember(Value = @"wind")]
Wind = 2,[System.Runtime.Serialization.EnumMember(Value = @"weather")]
Weather = 3,}
[System.CodeDom.Compiler.GeneratedCode("njsonSchema","10.1.24.0 (Newtonsoft.Json v12.0.0.0)")]
public enum TypesInvisible
{
[System.Runtime.Serialization.EnumMember(Value = @"air")]
Air = 0,[System.Runtime.Serialization.EnumMember(Value = @"atmosphere")]
Atmosphere = 1,"10.1.24.0 (Newtonsoft.Json v12.0.0.0)")]
public enum TypesMusic
{
[System.Runtime.Serialization.EnumMember(Value = @"rock")]
Rock = 0,[System.Runtime.Serialization.EnumMember(Value = @"Metal")]
Metal = 1,[System.Runtime.Serialization.EnumMember(Value = @"classic")]
Classic = 2,}
}
现在,我想向“ MyClass”的“ ArrayTypeProperty”中添加自定义属性“ MyCustomAttribute”,以便生成的类如下所示:
[System.CodeDom.Compiler.GeneratedCode("njsonSchema",NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[MyCustom]
public System.Collections.Generic.ICollection<Types> ArrayTypeProperty { get; set; }
}
有人可以帮助我了解我是否可以使用njsonSchema实现此行为,如果可以,怎么办?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)