EmitCSharp.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. // #define USENEWTONSOFT
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using static System.FormattableString;
  8. namespace SharpGLTF.CodeGen
  9. {
  10. using SchemaReflection;
  11. /// <summary>
  12. /// Takes a <see cref="SchemaReflection.SchemaType.Context"/> and emits
  13. /// all its enums and classes as c# source code
  14. /// </summary>
  15. class CSharpEmitter
  16. {
  17. #region runtime names
  18. class _RuntimeType
  19. {
  20. internal _RuntimeType(SchemaType t) { _PersistentType = t; }
  21. private readonly SchemaType _PersistentType;
  22. public string RuntimeNamespace { get; set; }
  23. public string RuntimeName { get; set; }
  24. private readonly Dictionary<string, _RuntimeField> _Fields = new Dictionary<string, _RuntimeField>();
  25. private readonly Dictionary<string, _RuntimeEnum> _Enums = new Dictionary<string, _RuntimeEnum>();
  26. public _RuntimeField UseField(FieldInfo finfo)
  27. {
  28. var key = $"{finfo.PersistentName}";
  29. if (_Fields.TryGetValue(key, out _RuntimeField rfield)) return rfield;
  30. rfield = new _RuntimeField(finfo);
  31. _Fields[key] = rfield;
  32. return rfield;
  33. }
  34. public _RuntimeEnum UseEnum(string name)
  35. {
  36. var key = name;
  37. if (_Enums.TryGetValue(key, out _RuntimeEnum renum)) return renum;
  38. renum = new _RuntimeEnum(name);
  39. _Enums[key] = renum;
  40. return renum;
  41. }
  42. }
  43. class _RuntimeEnum
  44. {
  45. internal _RuntimeEnum(string name) { _Name = name; }
  46. private readonly string _Name;
  47. }
  48. class _RuntimeField
  49. {
  50. internal _RuntimeField(FieldInfo f) { _PersistentField = f; }
  51. private readonly FieldInfo _PersistentField;
  52. public string PrivateField { get; set; }
  53. public string PublicProperty { get; set; }
  54. public string CollectionContainer { get; set; }
  55. public string DictionaryContainer { get; set; }
  56. // MinVal, MaxVal, readonly, static
  57. // serialization sections
  58. // deserialization sections
  59. // validation sections
  60. // clone sections
  61. }
  62. private readonly Dictionary<string, _RuntimeType> _Types = new Dictionary<string, _RuntimeType>();
  63. private string _DefaultCollectionContainer = "TItem[]";
  64. #endregion
  65. #region setup & declaration
  66. private static string _SanitizeName(string name)
  67. {
  68. return name.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase);
  69. }
  70. private _RuntimeType _UseType(SchemaType stype)
  71. {
  72. var key = $"{stype.PersistentName}";
  73. if (_Types.TryGetValue(key, out _RuntimeType rtype)) return rtype;
  74. rtype = new _RuntimeType(stype)
  75. {
  76. RuntimeName = _SanitizeName(stype.PersistentName)
  77. };
  78. _Types[key] = rtype;
  79. return rtype;
  80. }
  81. private _RuntimeField _UseField(FieldInfo finfo) { return _UseType(finfo.DeclaringClass).UseField(finfo); }
  82. public void SetRuntimeName(SchemaType stype, string newName, string runtimeNamespace = null)
  83. {
  84. var t = _UseType(stype);
  85. t.RuntimeNamespace = runtimeNamespace;
  86. t.RuntimeName = newName;
  87. }
  88. public void SetRuntimeName(string persistentName, string runtimeName, string runtimeNamespace = null)
  89. {
  90. if (!_Types.TryGetValue(persistentName, out _RuntimeType t)) return;
  91. t.RuntimeNamespace = runtimeNamespace;
  92. t.RuntimeName = runtimeName;
  93. }
  94. public string GetRuntimeName(string persistentName)
  95. {
  96. return _Types[persistentName].RuntimeName;
  97. }
  98. public string GetRuntimeNamespace(string persistentName)
  99. {
  100. return _Types[persistentName].RuntimeNamespace ?? Constants.OutputNamespace;
  101. }
  102. public void SetFieldName(FieldInfo finfo, string name) { _UseField(finfo).PrivateField = name; }
  103. public string GetFieldRuntimeName(FieldInfo finfo) { return _UseField(finfo).PrivateField; }
  104. public void SetPropertyName(FieldInfo finfo, string name) { _UseField(finfo).PublicProperty = name; }
  105. public string GetPropertyName(FieldInfo finfo) { return _UseField(finfo).PublicProperty; }
  106. public void SetCollectionContainer(string container) { _DefaultCollectionContainer = container; }
  107. public void SetCollectionContainer(FieldInfo finfo, string container) { _UseField(finfo).CollectionContainer = container; }
  108. public void SetFieldToChildrenList(SchemaType.Context ctx, string persistentName, string fieldName)
  109. {
  110. var classType = ctx.FindClass(persistentName);
  111. if (classType == null) return;
  112. var field = classType.UseField(fieldName);
  113. var runtimeName = this.GetRuntimeName(persistentName);
  114. this.SetCollectionContainer(field, $"ChildrenList<TItem,{runtimeName}>");
  115. }
  116. public void SetFieldToChildrenDictionary(SchemaType.Context ctx, string persistentName, string fieldName)
  117. {
  118. var classType = ctx.FindClass(persistentName);
  119. if (classType == null) return;
  120. var field = classType.UseField(fieldName);
  121. var runtimeName = this.GetRuntimeName(persistentName);
  122. this.SetCollectionContainer(field, $"ChildrenDictionary<TItem,{runtimeName}>");
  123. }
  124. public void DeclareClass(ClassType type)
  125. {
  126. _UseType(type);
  127. foreach(var f in type.Fields)
  128. {
  129. var runtimeName = _SanitizeName(f.PersistentName).Replace("@","at", StringComparison.Ordinal);
  130. SetFieldName(f, $"_{runtimeName}");
  131. SetPropertyName(f, runtimeName);
  132. }
  133. }
  134. public void DeclareEnum(EnumType type)
  135. {
  136. _UseType(type);
  137. foreach (var f in type.Values)
  138. {
  139. // SetFieldName(f, $"_{runtimeName}");
  140. // SetPropertyName(f, runtimeName);
  141. }
  142. }
  143. public void DeclareContext(SchemaType.Context context)
  144. {
  145. foreach(var ctype in context.Classes)
  146. {
  147. DeclareClass(ctype);
  148. }
  149. foreach (var etype in context.Enumerations)
  150. {
  151. DeclareEnum(etype);
  152. }
  153. }
  154. internal string _GetRuntimeName(SchemaType type) { return _GetRuntimeName(type, null); }
  155. private string _GetRuntimeName(SchemaType type, _RuntimeField extra)
  156. {
  157. switch (type)
  158. {
  159. case null: throw new ArgumentNullException(nameof(type));
  160. case ObjectType anyType: return anyType.PersistentName;
  161. case StringType strType: return strType.PersistentName;
  162. case BlittableType blitType:
  163. {
  164. var tname = blitType.DataType.Name;
  165. return blitType.IsNullable ? $"{tname}?" : tname;
  166. }
  167. case ArrayType arrayType:
  168. {
  169. var container = extra?.CollectionContainer;
  170. if (string.IsNullOrWhiteSpace(container)) container = _DefaultCollectionContainer;
  171. return container.Replace("TItem", _GetRuntimeName(arrayType.ItemType), StringComparison.Ordinal);
  172. }
  173. case DictionaryType dictType:
  174. {
  175. var key = _GetRuntimeName(dictType.KeyType);
  176. var val = _GetRuntimeName(dictType.ValueType);
  177. var container = extra?.CollectionContainer ?? string.Empty;
  178. if (container.StartsWith("ChildrenDictionary<"))
  179. {
  180. if (key == "String") return container.Replace("TItem", val, StringComparison.Ordinal);
  181. }
  182. return $"Dictionary<{key},{val}>";
  183. }
  184. case EnumType enumType: return _UseType(enumType).RuntimeName;
  185. case ClassType classType: return _UseType(classType).RuntimeName;
  186. default: throw new NotImplementedException(type.PersistentName);
  187. }
  188. }
  189. private string _GetConstantRuntimeName(SchemaType type)
  190. {
  191. switch (type)
  192. {
  193. case StringType strType: return $"const {typeof(string).Name}";
  194. case BlittableType blitType:
  195. {
  196. var tname = blitType.DataType.Name;
  197. if (blitType.DataType == typeof(int)) return $"const {tname}";
  198. if (blitType.DataType == typeof(float)) return $"const {tname}";
  199. if (blitType.DataType == typeof(double)) return $"const {tname}";
  200. return $"static readonly {tname}";
  201. }
  202. case EnumType enumType: return $"const {_UseType(enumType).RuntimeName}";
  203. case ArrayType aType: return $"static readonly {_UseType(aType).RuntimeName}";
  204. default: throw new NotImplementedException();
  205. }
  206. }
  207. private Object _GetConstantRuntimeValue(SchemaType type, Object value)
  208. {
  209. if (value == null) throw new ArgumentNullException(nameof(value));
  210. switch (type)
  211. {
  212. case StringType _:
  213. return value is string
  214. ? value
  215. : Convert.ChangeType(value, typeof(string), System.Globalization.CultureInfo.InvariantCulture);
  216. case BlittableType btype:
  217. {
  218. if (btype.DataType == typeof(bool).GetTypeInfo())
  219. {
  220. if (value is bool) return value;
  221. var str = value as string;
  222. if (str.ToUpperInvariant() == "FALSE") return false;
  223. if (str.ToUpperInvariant() == "TRUE") return true;
  224. throw new NotImplementedException();
  225. }
  226. return value is string
  227. ? value
  228. : Convert.ChangeType(value, btype.DataType.AsType(), System.Globalization.CultureInfo.InvariantCulture);
  229. }
  230. case EnumType etype:
  231. {
  232. var etypeName = _GetRuntimeName(type);
  233. if (value is string) return $"{etypeName}.{value}";
  234. else return $"({etypeName}){value}";
  235. }
  236. case ArrayType aType:
  237. {
  238. var atypeName = _GetRuntimeName(type);
  239. return value.ToString();
  240. }
  241. default: throw new NotImplementedException();
  242. }
  243. }
  244. #endregion
  245. #region emit
  246. public string EmitContext(SchemaType.Context context)
  247. {
  248. var sb = new StringBuilder();
  249. sb.AppendLine("// <auto-generated/>");
  250. sb.AppendLine();
  251. sb.AppendLine("//------------------------------------------------------------------------------------------------");
  252. sb.AppendLine("// This file has been programatically generated; DON´T EDIT!");
  253. sb.AppendLine("//------------------------------------------------------------------------------------------------");
  254. sb.AppendLine();
  255. sb.AppendLine("#pragma warning disable SA1001");
  256. sb.AppendLine("#pragma warning disable SA1027");
  257. sb.AppendLine("#pragma warning disable SA1028");
  258. sb.AppendLine("#pragma warning disable SA1121");
  259. sb.AppendLine("#pragma warning disable SA1205");
  260. sb.AppendLine("#pragma warning disable SA1309");
  261. sb.AppendLine("#pragma warning disable SA1402");
  262. sb.AppendLine("#pragma warning disable SA1505");
  263. sb.AppendLine("#pragma warning disable SA1507");
  264. sb.AppendLine("#pragma warning disable SA1508");
  265. sb.AppendLine("#pragma warning disable SA1652");
  266. sb.AppendLine();
  267. sb.AppendLine("using System;");
  268. sb.AppendLine("using System.Collections.Generic;");
  269. sb.AppendLine("using System.Linq;");
  270. sb.AppendLine("using System.Text;");
  271. sb.AppendLine("using System.Numerics;");
  272. sb.AppendLine("using System.Text.Json;");
  273. string currentNamespace = null;
  274. void _setCurrentNamespace(string ns)
  275. {
  276. if (currentNamespace == ns) return;
  277. if (currentNamespace != null) sb.AppendLine("}");
  278. currentNamespace = ns;
  279. if (currentNamespace != null)
  280. {
  281. sb.AppendLine();
  282. sb.AppendLine($"namespace {currentNamespace}");
  283. sb.AppendLine("{");
  284. sb.AppendLine("using Collections;".Indent(1));
  285. sb.AppendLine();
  286. }
  287. }
  288. foreach (var etype in context.Enumerations)
  289. {
  290. _setCurrentNamespace(GetRuntimeNamespace(etype.PersistentName));
  291. var cout = EmitEnum(etype);
  292. sb.AppendLine(cout);
  293. sb.AppendLine();
  294. }
  295. foreach (var ctype in context.Classes)
  296. {
  297. if (ctype.IgnoredByEmitter) continue;
  298. _setCurrentNamespace(GetRuntimeNamespace(ctype.PersistentName));
  299. var cout = EmitClass(ctype);
  300. sb.AppendLine(cout);
  301. sb.AppendLine();
  302. }
  303. _setCurrentNamespace(null);
  304. return sb.ToString();
  305. }
  306. public string EmitEnum(EnumType type)
  307. {
  308. var sb = new StringBuilder();
  309. foreach (var l in type.Description.EmitSummary(0)) sb.EmitLine(1, l);
  310. sb.EmitLine(1, $"public enum {_GetRuntimeName(type)}");
  311. sb.EmitLine(1, "{");
  312. if (type.UseIntegers)
  313. {
  314. foreach (var kvp in type.Values)
  315. {
  316. var k = kvp.Key;
  317. sb.EmitLine(2, $"{k} = {kvp.Value},");
  318. }
  319. }
  320. else
  321. {
  322. foreach (var kvp in type.Values)
  323. {
  324. var k = kvp.Key;
  325. sb.EmitLine(2, $"{k},");
  326. }
  327. }
  328. sb.EmitLine(1, "}");
  329. return sb.ToString();
  330. }
  331. public string EmitClass(ClassType type)
  332. {
  333. var xclass = new CSharpClassEmitter(this)
  334. {
  335. ClassSummary = type.Description,
  336. ClassDeclaration = _GetClassDeclaration(type),
  337. HasBaseClass = type.BaseClass != null
  338. };
  339. xclass.AddFields(type);
  340. return String.Join("\r\n",xclass.EmitCode().Indent(1));
  341. }
  342. private string _GetClassDeclaration(ClassType type)
  343. {
  344. var classDecl = string.Empty;
  345. classDecl += "partial ";
  346. classDecl += "class ";
  347. classDecl += _GetRuntimeName(type);
  348. if (type.BaseClass != null) classDecl += $" : {_GetRuntimeName(type.BaseClass)}";
  349. return classDecl;
  350. }
  351. internal IEnumerable<string> _GetClassField(FieldInfo f)
  352. {
  353. var tdecl = _GetRuntimeName(f.FieldType, _UseField(f));
  354. var fname = GetFieldRuntimeName(f);
  355. string defval = string.Empty;
  356. if (f.DefaultValue != null)
  357. {
  358. var tconst = _GetConstantRuntimeName(f.FieldType);
  359. var vconst = _GetConstantRuntimeValue(f.FieldType, f.DefaultValue);
  360. // fix boolean value
  361. if (vconst is Boolean bconst) vconst = bconst ? "true" : "false";
  362. defval = $"{fname}Default";
  363. yield return Invariant($"private {tconst} {defval} = {vconst};");
  364. }
  365. if (f.ExclusiveMinimumValue != null)
  366. {
  367. var tconst = _GetConstantRuntimeName(f.FieldType);
  368. var vconst = _GetConstantRuntimeValue(f.FieldType, f.ExclusiveMinimumValue);
  369. yield return Invariant($"private {tconst} {fname}ExclusiveMinimum = {vconst};");
  370. }
  371. if (f.InclusiveMinimumValue != null)
  372. {
  373. var tconst = _GetConstantRuntimeName(f.FieldType);
  374. var vconst = _GetConstantRuntimeValue(f.FieldType, f.InclusiveMinimumValue);
  375. yield return Invariant($"private {tconst} {fname}Minimum = {vconst};");
  376. }
  377. if (f.InclusiveMaximumValue != null)
  378. {
  379. var tconst = _GetConstantRuntimeName(f.FieldType);
  380. var vconst = _GetConstantRuntimeValue(f.FieldType, f.InclusiveMaximumValue);
  381. yield return Invariant($"private {tconst} {fname}Maximum = {vconst};");
  382. }
  383. if (f.ExclusiveMaximumValue != null)
  384. {
  385. var tconst = _GetConstantRuntimeName(f.FieldType);
  386. var vconst = _GetConstantRuntimeValue(f.FieldType, f.ExclusiveMaximumValue);
  387. yield return Invariant($"private {tconst} {fname}ExclusiveMaximum = {vconst};");
  388. }
  389. if (f.MinItems > 0)
  390. {
  391. yield return $"private const int {fname}MinItems = {f.MinItems};";
  392. }
  393. if (f.MaxItems > 0 && f.MaxItems < int.MaxValue)
  394. {
  395. yield return $"private const int {fname}MaxItems = {f.MaxItems};";
  396. }
  397. if (f.FieldType is EnumType etype && etype.IsNullable) tdecl = tdecl + "?";
  398. yield return string.IsNullOrEmpty(defval) ? $"private {tdecl} {fname};" : $"private {tdecl} {fname} = {defval};";
  399. yield return string.Empty;
  400. }
  401. #endregion
  402. }
  403. /// <summary>
  404. /// Utility class to emit a <see cref="SchemaReflection.ClassType"/>
  405. /// as c# source code
  406. /// </summary>
  407. class CSharpClassEmitter
  408. {
  409. #region constructor
  410. public CSharpClassEmitter(CSharpEmitter emitter)
  411. {
  412. _Emitter = emitter;
  413. }
  414. #endregion
  415. #region data
  416. private readonly CSharpEmitter _Emitter;
  417. private readonly List<string> _Fields = new List<string>();
  418. private readonly List<string> _SerializerBody = new List<string>();
  419. private readonly List<string> _DeserializerSwitchBody = new List<string>();
  420. public string ClassSummary { get; set; }
  421. public string ClassDeclaration { get; set; }
  422. public bool HasBaseClass { get; set; }
  423. private const string _READERMODIFIER = "ref ";
  424. #endregion
  425. #region API
  426. public void AddFields(ClassType type)
  427. {
  428. foreach (var f in type.Fields)
  429. {
  430. var trname = _Emitter._GetRuntimeName(f.FieldType);
  431. var frname = _Emitter.GetFieldRuntimeName(f);
  432. _Fields.AddRange(_Emitter._GetClassField(f));
  433. if (f.FieldType is EnumType etype)
  434. {
  435. // emit serializer
  436. var smethod = etype.UseIntegers ? "SerializePropertyEnumValue" : "SerializePropertyEnumSymbol";
  437. smethod = $"{smethod}<{trname}>(writer, \"{f.PersistentName}\", {frname}";
  438. if (f.DefaultValue != null) smethod += $", {frname}Default";
  439. smethod += ");";
  440. this.AddFieldSerializerCase(smethod);
  441. // emit deserializer
  442. this.AddFieldDeserializerCase(f.PersistentName, $"{frname} = DeserializePropertyValue<{_Emitter._GetRuntimeName(etype)}>({_READERMODIFIER}reader);");
  443. continue;
  444. }
  445. this.AddFieldSerializerCase(_GetJSonSerializerMethod(f));
  446. this.AddFieldDeserializerCase(f.PersistentName, _GetJSonDeserializerMethod(f));
  447. }
  448. }
  449. private string _GetJSonSerializerMethod(FieldInfo f)
  450. {
  451. var pname = f.PersistentName;
  452. var fname = _Emitter.GetFieldRuntimeName(f);
  453. if (f.FieldType is ClassType ctype)
  454. {
  455. return $"SerializePropertyObject(writer, \"{pname}\", {fname});";
  456. }
  457. if (f.FieldType is ArrayType atype)
  458. {
  459. if (f.MinItems > 0) return $"SerializeProperty(writer, \"{pname}\", {fname}, {fname}MinItems);";
  460. return $"SerializeProperty(writer,\"{pname}\",{fname});";
  461. }
  462. if (f.DefaultValue != null) return $"SerializeProperty(writer, \"{pname}\", {fname}, {fname}Default);";
  463. return $"SerializeProperty(writer, \"{pname}\", {fname});";
  464. }
  465. private string _GetJSonDeserializerMethod(FieldInfo f)
  466. {
  467. var fname = _Emitter.GetFieldRuntimeName(f);
  468. if (f.FieldType is ArrayType atype)
  469. {
  470. var titem = _Emitter._GetRuntimeName(atype.ItemType);
  471. return $"DeserializePropertyList<{titem}>({_READERMODIFIER}reader, {fname});";
  472. }
  473. else if (f.FieldType is DictionaryType dtype)
  474. {
  475. var titem = _Emitter._GetRuntimeName(dtype.ValueType);
  476. return $"DeserializePropertyDictionary<{titem}>({_READERMODIFIER}reader, {fname});";
  477. }
  478. return $"{fname} = DeserializePropertyValue<{_Emitter._GetRuntimeName(f.FieldType)}>({_READERMODIFIER}reader);";
  479. }
  480. public void AddFieldSerializerCase(string line) { _SerializerBody.Add(line); }
  481. public void AddFieldDeserializerCase(string persistentName, string line)
  482. {
  483. _DeserializerSwitchBody.Add($"case \"{persistentName}\": {line} break;");
  484. }
  485. public IEnumerable<string> EmitCode()
  486. {
  487. #if USENEWTONSOFT
  488. var readerType = "JsonReader";
  489. var writerType = "JsonWriter";
  490. #else
  491. var readerType = "ref Utf8JsonReader";
  492. var writerType = "Utf8JsonWriter";
  493. #endif
  494. foreach (var l in ClassSummary.EmitSummary(0)) yield return l;
  495. yield return "#if NET6_0_OR_GREATER";
  496. yield return "[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)]";
  497. yield return "#endif";
  498. yield return "[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"SharpGLTF.CodeGen\", \"1.0.0.0\")]";
  499. yield return ClassDeclaration;
  500. yield return "{";
  501. yield return string.Empty;
  502. foreach (var l in _Fields.Indent(1)) yield return l;
  503. yield return string.Empty;
  504. // yield return "/// <inheritdoc />".Indent(1);
  505. yield return $"protected override void SerializeProperties({writerType} writer)".Indent(1);
  506. yield return "{".Indent(1);
  507. if (HasBaseClass) yield return "base.SerializeProperties(writer);".Indent(2);
  508. foreach (var l in _SerializerBody.Indent(2)) yield return l;
  509. yield return "}".Indent(1);
  510. yield return string.Empty;
  511. // yield return "/// <inheritdoc />".Indent(1);
  512. yield return $"protected override void DeserializeProperty(string jsonPropertyName, {readerType} reader)".Indent(1);
  513. yield return "{".Indent(1);
  514. yield return "switch (jsonPropertyName)".Indent(2);
  515. yield return "{".Indent(2);
  516. foreach (var l in _DeserializerSwitchBody.Indent(3)) yield return l;
  517. if (HasBaseClass) yield return $"default: base.DeserializeProperty(jsonPropertyName,{_READERMODIFIER}reader); break;".Indent(3);
  518. else yield return "default: throw new NotImplementedException();".Indent(3);
  519. yield return "}".Indent(2);
  520. yield return "}".Indent(1);
  521. yield return string.Empty;
  522. yield return "}";
  523. }
  524. #endregion
  525. }
  526. }