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(); }