private Schema CreateObjectSchema(JsonObjectContract jsonContract) { Dictionary <string, Schema> dictionary = ((IEnumerable <JsonProperty>)jsonContract.get_Properties()).Where <JsonProperty>((Func <JsonProperty, bool>)(p => !p.get_Ignored())).Where <JsonProperty>((Func <JsonProperty, bool>)(p => { if (this._ignoreObsoleteProperties) { return(!p.IsObsolete()); } return(true); })).ToDictionary <JsonProperty, string, Schema>((Func <JsonProperty, string>)(prop => prop.get_PropertyName()), (Func <JsonProperty, Schema>)(prop => this.CreateInlineSchema(prop.get_PropertyType()).WithValidationProperties(prop))); List <string> list = ((IEnumerable <JsonProperty>)jsonContract.get_Properties()).Where <JsonProperty>((Func <JsonProperty, bool>)(prop => prop.IsRequired())).Select <JsonProperty, string>((Func <JsonProperty, string>)(propInfo => propInfo.get_PropertyName())).ToList <string>(); return(new Schema() { required = list.Any <string>() ? (IList <string>)list : (IList <string>)null, properties = (IDictionary <string, Schema>)dictionary, type = "object" }); }
public virtual void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { JsonObjectContract jsonObjectContract = (JsonObjectContract)serializer.get_ContractResolver().ResolveContract(value.GetType()); writer.WriteStartObject(); using (IEnumerator <JsonProperty> enumerator = ((Collection <JsonProperty>)jsonObjectContract.get_Properties()).GetEnumerator()) { while (((IEnumerator)enumerator).MoveNext()) { JsonProperty current = enumerator.Current; object obj = current.get_ValueProvider().GetValue(value); if (obj != null || serializer.get_NullValueHandling() != 1) { if (current.get_PropertyName() == "vendorExtensions") { IDictionary <string, object> source = (IDictionary <string, object>)obj; if (source.Any <KeyValuePair <string, object> >()) { foreach (KeyValuePair <string, object> keyValuePair in (IEnumerable <KeyValuePair <string, object> >)source) { writer.WritePropertyName(keyValuePair.Key); serializer.Serialize(writer, keyValuePair.Value); } } } else { writer.WritePropertyName(current.get_PropertyName()); serializer.Serialize(writer, obj); } } } } writer.WriteEndObject(); }