-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcore-json-dto-deserializer-uml-partial-template.hbs
More file actions
108 lines (100 loc) · 4.91 KB
/
Copy pathcore-json-dto-deserializer-uml-partial-template.hbs
File metadata and controls
108 lines (100 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
if (reader.ValueTextEquals("{{ property.Name }}"u8))
{
{{ property.Name }}Seen = true;
reader.Read();
{{#if (Property.QueryIsReferenceProperty property)}}
{{#if (Property.QueryIsEnumerable property)}}
Utf8JsonReaderHelper.ExpectArrayStart(ref reader);
while (reader.Read() && reader.TokenType != JsonTokenType.EndArray)
{
if (Utf8JsonReaderHelper.TryReadReferenceIdentifier(ref reader, out var {{ property.Name }}Value))
{
dtoInstance.{{Property.WritePropertyName property}}.Add({{ property.Name }}Value);
}
}
{{ else }}
if (reader.TokenType == JsonTokenType.Null)
{
{{#if (Property.QueryIsNullable property) }}
dtoInstance.{{Property.WritePropertyName property}} = null;
{{else}}
dtoInstance.{{Property.WritePropertyName property}} = Guid.Empty;
if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug("the {{ classContext.Name }}.{{Property.WritePropertyName property}} property was not found in the Json. The value is set to Guid.Empty");
}
{{/if}}
}
else if (Utf8JsonReaderHelper.TryReadReferenceIdentifier(ref reader, out var {{ property.Name }}Value))
{
dtoInstance.{{Property.WritePropertyName property}} = {{ property.Name }}Value;
}
{{/if}}
{{ else }}
{{#if (Property.QueryIsEnumerable property)}}
Utf8JsonReaderHelper.ExpectArrayStart(ref reader);
while (reader.Read() && reader.TokenType != JsonTokenType.EndArray)
{
{{#if (Property.QueryIsBool property )}}
dtoInstance.{{Property.WritePropertyName property}}.Add(reader.GetBoolean());
{{else if (Property.QueryIsEnum property )}}
throw new NotImplementedException("Enumerable Enum - {{ classContext.Name }}.{{property.Name}} is not yet supported");
{{else if (Property.QueryIsNumeric property )}}
{{#if (Property.QueryIsInteger property) }}
dtoInstance.{{Property.WritePropertyName property}}.Add(reader.GetInt32());
{{else if (Property.QueryIsDouble property) }}
dtoInstance.{{Property.WritePropertyName property}}.Add(reader.GetDouble());
{{ else }}
throw new NotImplementedException("Enumerable Double - {{ classContext.Name }}.{{property.Name}} is not yet supported");
{{/if}}
{{else}}
var {{ property.Name }}Value = reader.GetString();
if ({{ property.Name }}Value != null)
{
dtoInstance.{{Property.WritePropertyName property}}.Add({{ property.Name }}Value);
}
{{/if}}
}
{{ else if (Property.QueryIsNullable property) }}
{{#if (Property.QueryIsBool property )}}
dtoInstance.{{Property.WritePropertyName property}} = reader.GetBoolean();
{{else if (Property.QueryIsEnum property )}}
dtoInstance.{{Property.WritePropertyName property}} = {{ property.Type.Name }}DeSerializer.DeserializeNullable(reader.GetString());
{{else if (Property.QueryIsNumeric property )}}
{{#if (Property.QueryIsInteger property) }}
dtoInstance.{{Property.WritePropertyName property}} = reader.GetInt32();
{{else if (Property.QueryIsDouble property) }}
dtoInstance.{{Property.WritePropertyName property}} = reader.GetDouble();
{{ else }}
new NotImplementedException("nullable - {{ classContext.Name }}.{{property.Name}} is not yet supported");
{{/if}}
{{else}}
dtoInstance.{{Property.WritePropertyName property}} = reader.GetString();
{{/if}}
{{ else if (Property.QueryIsScalar property) }}
{{#if (Property.QueryIsBool property )}}
if (reader.TokenType != JsonTokenType.Null)
{
dtoInstance.{{Property.WritePropertyName property}} = reader.GetBoolean();
}
{{else if (Property.QueryIsEnum property )}}
dtoInstance.{{Property.WritePropertyName property}} = {{ property.Type.Name }}DeSerializer.Deserialize(reader.GetString());
{{else if (Property.QueryIsNumeric property )}}
{{#if (Property.QueryIsInteger property) }}
dtoInstance.{{Property.WritePropertyName property}} = reader.GetInt32();
{{else if (Property.QueryIsDouble property) }}
dtoInstance.{{Property.WritePropertyName property}} = reader.GetDouble();
{{ else }}
new NotImplementedException("Scalar - {{ classContext.Name }}.{{property.Name}} is not yet supported");
{{/if}}
{{else}}
var {{ property.Name }}Value = reader.GetString();
if ({{ property.Name }}Value != null)
{
dtoInstance.{{Property.WritePropertyName property}} = {{ property.Name }}Value;
}
{{/if}}
{{/if}}
{{/if}}
continue;
}