Permalink
Browse files

Improved code

  • Loading branch information...
RSuter committed Dec 6, 2017
1 parent 64c9a43 commit dd2665e2f79dcbbab6509620114fa592c0d8b755
Showing with 12 additions and 10 deletions.
  1. +12 −10 src/NJsonSchema.CodeGeneration.CSharp/CSharpTypeResolver.cs
@@ -63,14 +63,11 @@ public override string Resolve(JsonSchema4 schema, bool isNullable, string typeN
return "byte[]";
if (schema.IsDictionary)
{
var valueType = ResolveDictionaryValueType(schema, "object", Settings.SchemaType);
return string.Format(Settings.DictionaryType + "<string, {0}>", valueType);
}
return ResolveDictionary(schema);
return GetOrGenerateTypeName(schema, typeNameHint);
}
private string ResolveString(JsonSchema4 schema, bool isNullable, string typeNameHint)
{
if (schema.Format == JsonFormatStrings.Date)
@@ -130,14 +127,19 @@ private static string ResolveNumber(JsonSchema4 schema, bool isNullable)
private string ResolveArrayOrTuple(JsonSchema4 schema)
{
var property = schema;
if (property.Item != null)
return string.Format(Settings.ArrayType + "<{0}>", Resolve(property.Item, false, null));
if (schema.Item != null)
return string.Format(Settings.ArrayType + "<{0}>", Resolve(schema.Item, false, null));
if (property.Items != null && property.Items.Count > 0)
return string.Format("System.Tuple<" + string.Join(", ", property.Items.Select(i => Resolve(i.ActualSchema, false, null)) + ">"));
if (schema.Items != null && schema.Items.Count > 0)
return string.Format("System.Tuple<" + string.Join(", ", schema.Items.Select(i => Resolve(i.ActualSchema, false, null)) + ">"));
return Settings.ArrayType + "<object>";
}
private string ResolveDictionary(JsonSchema4 schema)
{
var valueType = ResolveDictionaryValueType(schema, "object", Settings.SchemaType);
return string.Format(Settings.DictionaryType + "<string, {0}>", valueType);
}
}
}

0 comments on commit dd2665e

Please sign in to comment.