JsonProperty
A description of a JSON property of a JSON object.
using Newtonsoft.Json;
namespace NJsonSchema
{
public class JsonProperty : JsonSchema4
{
private JsonSchema4 _parentSchema;
[JsonIgnore]
public string Name { get; set; }
public override JsonSchema4 ParentSchema {
get {
return _parentSchema;
}
internal set {
bool num = _parentSchema == null;
_parentSchema = value;
if (num && InitialIsRequired)
IsRequired = InitialIsRequired;
}
}
[JsonIgnore]
public bool IsRequired {
get {
return ParentSchema.RequiredProperties.Contains(Name);
}
set {
if (ParentSchema == null)
InitialIsRequired = value;
else if (value) {
if (!ParentSchema.RequiredProperties.Contains(Name))
ParentSchema.RequiredProperties.Add(Name);
} else if (ParentSchema.RequiredProperties.Contains(Name)) {
ParentSchema.RequiredProperties.Remove(Name);
}
}
}
[JsonIgnore]
internal bool InitialIsRequired { get; set; }
internal static JsonProperty FromJsonSchema(string name, JsonSchema4 type)
{
JsonProperty jsonProperty = JsonConvert.DeserializeObject<JsonProperty>(JsonConvert.SerializeObject(type));
jsonProperty.Name = name;
return jsonProperty;
}
}
}