diff --git a/src/readme.graph.md b/src/readme.graph.md index ad7c57c63eb..9e5c4dac1b9 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. @@ -538,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 $; }