in src/Json.Schema.ToDotNet/PropertyInfoDictionary.cs [463:513]
private TypeSyntax MakeDictionaryType(
IList<KeyValuePair<string, PropertyInfo>> entries,
string propertyName,
DictionaryHint dictionaryHint,
JsonSchema dictionaryElementSchema)
{
string key = MakeDictionaryItemKeyName(propertyName);
string keyTypeName = dictionaryHint?.KeyTypeName ?? WellKnownTypeNames.String;
// An explicitly hinted value type takes precedence over what's declared in
// the schema.
TypeSyntax valueType;
if (dictionaryHint?.ValueTypeName != null)
{
valueType = SyntaxFactory.ParseTypeName(dictionaryHint.ValueTypeName);
entries.Add(new KeyValuePair<string, PropertyInfo>(
key,
new PropertyInfo(
description: string.Empty,
serializedName: null,
comparisonKind: dictionaryHint.ComparisonKind,
hashKind: dictionaryHint.HashKind,
initializationKind: dictionaryHint.InitializationKind,
type: valueType,
namespaceName: dictionaryHint.NamespaceName,
isRequired: true,
defaultValue: null,
isOfSchemaDefinedType: false,
arrayRank: 0,
declarationOrder: 0)));
}
else
{
AddPropertyInfoFromPropertySchema(entries, key, dictionaryElementSchema, isRequired: true);
PropertyInfo info = entries.Single(kvp => kvp.Key == key).Value;
valueType = info.Type;
}
// Create a dictionary of whatever this property is. If the property
// is an array, this will result in a dictionary of lists, and so on.
return SyntaxFactory.GenericName(
SyntaxFactory.Identifier("IDictionary"),
SyntaxFactory.TypeArgumentList(
SyntaxFactory.SeparatedList(
new TypeSyntax[]
{
SyntaxFactory.ParseTypeName(keyTypeName),
valueType
})));
}