From ddce4b838cb7c74ed0a40cbff62e4fe133369e9d Mon Sep 17 00:00:00 2001 From: Peter Ombwa Date: Wed, 26 Jul 2023 16:56:33 -0700 Subject: [PATCH 1/2] fix: Use case-insensitive dictionary when deserializing from dictionaries/OrderedHashtables. --- src/readme.graph.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/readme.graph.md b/src/readme.graph.md index ad7c57c63eb..5a404d15e3a 100644 --- a/src/readme.graph.md +++ b/src/readme.graph.md @@ -361,10 +361,18 @@ directive: { return $; } else { + // Add using namespaces to class. + let namespaceRegex = /(namespace.*.Models\n\{)/gm + $ = $.replace(namespaceRegex,'$1\n\tusing System.Linq;'); + // Change XmlDateTimeSerializationMode from Unspecified to Utc. let strToDateTimeRegex = /(XmlConvert\.ToDateTime\(.*,.*XmlDateTimeSerializationMode\.)Unspecified/gm $ = $.replace(strToDateTimeRegex, '$1Utc'); + // Use case-insensitive dictionary when deserializing from dictionaries/OrderedHashtables. + let deserializeFromDictionaryRegex = /(.*DeserializeFromDictionary\(.*IDictionary.*\n.*\{.*\n.*new.*\()content(\);)/gm + $ = $.replace(deserializeFromDictionaryRegex, '$1(content.Cast().ToDictionary(kvp => kvp.Key as string, kvp => kvp.Value, global::System.StringComparer.OrdinalIgnoreCase))$2'); + return $; } # Modify generated .cs model classes. From fdf14359b4e3ad88e45892d7e48656b0d241d1b1 Mon Sep 17 00:00:00 2001 From: Peter Ombwa Date: Thu, 27 Jul 2023 17:03:35 -0700 Subject: [PATCH 2/2] fix: Serialization of nested OrderedHashtables. --- src/readme.graph.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/readme.graph.md b/src/readme.graph.md index 5a404d15e3a..9e5c4dac1b9 100644 --- a/src/readme.graph.md +++ b/src/readme.graph.md @@ -546,10 +546,19 @@ directive: { return $; } else { + // Add using namespaces to class. + let namespaceRegex = /(namespace.*.Runtime\n\{)/gm + $ = $.replace(namespaceRegex,'$1\n\tusing System.Linq;'); + // Changes excludes hashset to a case-insensitive hashset. let fromJsonRegex = /(\s*FromJson<\w*>\s*\(JsonObject\s*json\s*,\s*System\.Collections\.Generic\.IDictionary.*)(\s*)({)/gm $ = $.replace(fromJsonRegex, '$1$2$3\n$2 if (excludes != null){ excludes = new System.Collections.Generic.HashSet(excludes, global::System.StringComparer.OrdinalIgnoreCase);}'); + // Serialize OrderedDictionary + let enumerableRegex = /(if.*\(value.*IEnumerable.*\))/gm + let orderedSerializerImpl = 'if (value is System.Collections.Specialized.OrderedDictionary ovalue) { return JsonSerializable.ToJson((ovalue?.Cast().ToDictionary(kvp => kvp.Key as string, kvp => kvp.Value, global::System.StringComparer.OrdinalIgnoreCase)), null);}'; + $ = $.replace(enumerableRegex, `${orderedSerializerImpl}\n\n$1`) + return $; }