Open deepakmhr opened 6 years ago
Here is class generation code:
var schema = JsonSchema4.FromSampleJson(jsonData); var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings() { Namespace = typeof(Program).Namespace, GenerateDataAnnotations = true, ClassStyle = CSharpClassStyle.Inpc, HandleReferences = true, SchemaType = SchemaType.JsonSchema }); var file = generator.GenerateFile("DataSetHelper");
Here is the generated property:
[Newtonsoft.Json.JsonProperty("Gender", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public string Gender { get { return _gender; } set { if (_gender != value) { _gender = value; RaisePropertyChanged(); } } }
But my requirement is to generate readonly properties, something like this:
[Newtonsoft.Json.JsonProperty("Gender", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] public string Gender { get { return _gender; } private set { if (_gender != value) { _gender = value; RaisePropertyChanged(); } } }
Is this library support such configuration? please help
I think there is no setting for that yet, but you could replace the whole Class.liquid template:
https://github.com/RSuter/NJsonSchema/wiki/Templates
Thanks @RSuter for the help.
Here is class generation code:
Here is the generated property:
But my requirement is to generate readonly properties, something like this:
Is this library support such configuration? please help