private Schema CreateDictionarySchema(JsonDictionaryContract dictionaryContract, Queue <Type> referencedTypes) { var keyType = dictionaryContract.DictionaryKeyType ?? typeof(object); var valueType = dictionaryContract.DictionaryValueType ?? typeof(object); if (keyType.GetTypeInfo().IsEnum) { return(new Schema { Type = "object", Properties = Enum.GetNames(keyType).ToDictionary( (name) => dictionaryContract.DictionaryKeyResolver(name), (name) => CreateSchema(valueType, referencedTypes) ) }); } else { return(new Schema { Type = "object", AdditionalProperties = CreateSchema(valueType, referencedTypes) }); } }
private Schema CreateDictionarySchema(JsonDictionaryContract dictionaryContract) { var keyType = dictionaryContract.DictionaryKeyType ?? typeof(object); var valueType = dictionaryContract.DictionaryValueType ?? typeof(object); if (keyType.IsEnum) { return(new Schema { type = "object", properties = Enum.GetNames(keyType).ToDictionary( (name) => dictionaryContract.DictionaryKeyResolver(name), (name) => CreateInlineSchema(valueType) ) }); } else { return(new Schema { type = "object", additionalProperties = CreateInlineSchema(valueType) }); } }
// Token: 0x060009A9 RID: 2473 RVA: 0x00038134 File Offset: 0x00036334 private void method_37(JsonWriter jsonWriter_0, IDictionary idictionary_0, JsonDictionaryContract jsonDictionaryContract_0, JsonProperty jsonProperty_0, JsonContainerContract jsonContainerContract_0, JsonProperty jsonProperty_1) { Interface1 @interface; object obj = ((@interface = (idictionary_0 as Interface1)) != null) ? @interface.UnderlyingDictionary : idictionary_0; this.method_17(jsonWriter_0, jsonDictionaryContract_0, obj); this.list_0.Add(obj); this.method_21(jsonWriter_0, obj, jsonDictionaryContract_0, jsonProperty_0, jsonContainerContract_0, jsonProperty_1); if (jsonDictionaryContract_0.EwhtYgWttB() == null) { jsonDictionaryContract_0.method_5(this.jsonSerializer_0.icontractResolver_0.ResolveContract(jsonDictionaryContract_0.DictionaryValueType ?? typeof(object))); } if (jsonDictionaryContract_0.method_7() == null) { jsonDictionaryContract_0.method_8(this.jsonSerializer_0.icontractResolver_0.ResolveContract(jsonDictionaryContract_0.DictionaryKeyType ?? typeof(object))); } int top = jsonWriter_0.Top; using (IDictionaryEnumerator enumerator = idictionary_0.GetEnumerator()) { while (enumerator.MoveNext()) { DictionaryEntry entry = enumerator.Entry; bool escape; string text = this.method_38(jsonWriter_0, entry.Key, jsonDictionaryContract_0.method_7(), out escape); text = ((jsonDictionaryContract_0.DictionaryKeyResolver != null) ? jsonDictionaryContract_0.DictionaryKeyResolver(text) : text); try { object value = entry.Value; JsonContract jsonContract_ = jsonDictionaryContract_0.method_6() ?? this.method_7(value); if (this.method_11(value, null, jsonContract_, jsonDictionaryContract_0, jsonProperty_0)) { jsonWriter_0.WritePropertyName(text, escape); this.method_14(jsonWriter_0, value); } else if (this.method_13(jsonWriter_0, value, null, jsonContract_, jsonDictionaryContract_0, jsonProperty_0)) { jsonWriter_0.WritePropertyName(text, escape); this.method_9(jsonWriter_0, value, jsonContract_, null, jsonDictionaryContract_0, jsonProperty_0); } } catch (Exception exception_) { if (!base.method_4(obj, jsonDictionaryContract_0, text, null, jsonWriter_0.xEuXaafal7(), exception_)) { throw; } this.method_39(jsonWriter_0, top); } } } jsonWriter_0.WriteEndObject(); this.list_0.RemoveAt(this.list_0.Count - 1); this.method_18(jsonWriter_0, jsonDictionaryContract_0, obj); }
private Schema CreateDictionarySchema(string paramName, JsonDictionaryContract dictionaryContract, Queue <Type> referencedTypes) { var keyType = dictionaryContract.DictionaryKeyType ?? typeof(object); var valueType = dictionaryContract.DictionaryValueType ?? typeof(object); if (keyType.GetTypeInfo().IsEnum) { return(new Schema { Type = "object", Properties = Enum.GetNames(keyType).ToDictionary( name => dictionaryContract.DictionaryKeyResolver(name), name => CreateSchema(valueType, referencedTypes) ) }); } if (!string.IsNullOrEmpty(paramName)) { return(new Schema { Type = "object", Properties = new Dictionary <string, Schema> { { paramName, CreateSchema(valueType, referencedTypes) } } }); } return(new Schema { Type = "object", AdditionalProperties = CreateSchema(valueType, referencedTypes) }); }
private Schema CreateDictionarySchema( JsonDictionaryContract dictionaryContract, Queue <Type> referencedTypes) { Type type1 = dictionaryContract.DictionaryKeyType; if ((object)type1 == null) { type1 = typeof(object); } Type type2 = type1; Type type3 = dictionaryContract.DictionaryValueType; if ((object)type3 == null) { type3 = typeof(object); } Type valueType = type3; if (type2.GetTypeInfo().IsEnum) { return new Schema() { Type = "object", Properties = (IDictionary <string, Schema>)((IEnumerable <string>)Enum.GetNames(type2)) .ToDictionary <string, string, Schema>( (Func <string, string>)(name => dictionaryContract.DictionaryKeyResolver(name)), (Func <string, Schema>)(name => this.CreateSchema(valueType, referencedTypes))) } } ; return(new Schema() { Type = "object", AdditionalProperties = this.CreateSchema(valueType, referencedTypes) }); }
JToken VisitDictionary( [NotNull] JsonDictionaryContract jsonDictionaryContract, [CanBeNull] JObject jObject, [CanBeNull] IDictionary value) { if (value is null || jObject is null) { return(null); } if (!_halRepository.TryGetTransformer(jsonDictionaryContract.UnderlyingType, out var transformer)) { // note(cosborn) No setup, no transformation. return(jObject); } var dictionaryValueContract = SerializerSettings.ContractResolver.ResolveContract(jsonDictionaryContract.DictionaryValueType); foreach (var key in value.Keys) { var jKey = jsonDictionaryContract.DictionaryKeyResolver(key.ToString()); var jValue = jObject[jKey]; switch ((dictionaryValueContract, jValue.Type)) { case var tuple when tuple.dictionaryValueContract is JsonObjectContract joc && tuple.Type == JTokenType.Object: jObject[jKey] = new JProperty(jKey, VisitObject(joc, (JObject)jObject[jKey], value[key])); break; case var tuple when tuple.dictionaryValueContract is JsonArrayContract jac && tuple.Type == JTokenType.Array: jObject[jKey] = new JProperty(jKey, VisitArray(jac, (JArray)jObject[jKey], (IEnumerable)value[key])); break; case var tuple when tuple.dictionaryValueContract is JsonDictionaryContract jdc && tuple.Type == JTokenType.Object: jObject[jKey] = new JProperty(jKey, VisitDictionary(jdc, (JObject)jObject[jKey], (IDictionary)value[key])); break; // todo(cosborn) Dynamic? Something else? } } var links = transformer.GenerateLinks(value); var populatedLinks = links.Where(kvp => kvp.Value.Count != 0).ToImmutableDictionary(); if (populatedLinks.Count != 0) { jObject[LinksKey] = JObject.FromObject(populatedLinks, CreateJsonSerializer()); } var embeds = ImmutableList <JProperty> .Empty; var embedPairs = from embedInstruction in transformer.Embeds let nativeKey = embedInstruction.Index.ToString() let embedKey = jsonDictionaryContract.DictionaryKeyResolver(nativeKey) let index = embedKey ?? embedInstruction.Index let embedValue = embedInstruction.GetEmbedValue(value) let jEmbedValue = embedValue is null ? JValue.CreateNull() : Visit(embedValue, embedInstruction.Type) let jProperty = new JProperty(embedInstruction.Relation, jEmbedValue) select(index, jProperty); foreach (var(index, jProperty) in embedPairs) { embeds = embeds.Add(jProperty); /* note(cosborn) * Remember, indexing the JToken will give us a value within * a JProperty. We can't remove the value from the property * (what would that mean?), so we move up one level to remove * the entire property from the parent object. */ jObject[index]?.Parent.Remove(); } if (embeds.Count != 0) { jObject[EmbeddedKey] = new JObject(embeds); } return(jObject); }