Skip to content

Commit 19b3caf

Browse files
committed
Dynamically get exclusion properties of complex types.
1 parent 37d686a commit 19b3caf

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/readme.graph.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ directive:
426426
- from: source-file-csharp
427427
where: $
428428
transform: >
429-
if (!$documentPath.match(/generated%5Capi%5CModels%5CMicrosoftGraph\w*\d*.json.cs/gm))
429+
if (!$documentPath.match(/generated%5Capi%5CModels%5C\w*MicrosoftGraph\w*\d*.json.cs/gm))
430430
{
431431
return $;
432432
} else {
@@ -439,6 +439,18 @@ directive:
439439
// Pass exclusion properties to base classes during serialization.
440440
let baseClassInitializerRegex = /(new\s*Microsoft.Graph.PowerShell.Models.MicrosoftGraph\w*\(\s*json\s*,\s*new\s*global::System.Collections.Generic.HashSet<string>\()(\){\W.*}\);)/gm
441441
$ = $.replace(baseClassInitializerRegex, '$1(exclusions ?? new System.Collections.Generic.HashSet<string>())$2');
442+
443+
// Fix additional properties deserialization in Complex Types.
444+
let complexTypeHintRegex = /(\s*)(Microsoft\.Graph\.PowerShell\.Runtime\.JsonSerializable\.FromJson)/gm
445+
if($.match(complexTypeHintRegex)) {
446+
let classNameRegex = /partial\s*class\s*(\w*)\s*{/gm
447+
let match = classNameRegex.exec($);
448+
let interfaceName = "I" + match[1] + "Internal";
449+
450+
let getExclusionsDynamically = '\n$1if (exclusions == null) { exclusions = new System.Collections.Generic.HashSet<string>(global::System.StringComparer.OrdinalIgnoreCase); var properties = typeof('+interfaceName+').GetProperties(); foreach (var property in properties) { exclusions.Add(property.Name);}}'
451+
$ = $.replace(complexTypeHintRegex, getExclusionsDynamically + '\n$1$2');
452+
}
453+
442454
return $;
443455
}
444456
# Modify generated .cs model classes.
@@ -570,7 +582,7 @@ directive:
570582
} else {
571583
// Changes excludes hashset to a case-insensitive hashset.
572584
let fromJsonRegex = /(\s*FromJson<\w*>\s*\(JsonObject\s*json\s*,\s*System\.Collections\.Generic\.IDictionary.*)(\s*)({)/gm
573-
$ = $.replace(fromJsonRegex, '$1$2$1\n$2 if (excludes != null){ excludes = new System.Collections.Generic.HashSet<string>(excludes, global::System.StringComparer.OrdinalIgnoreCase);}');
585+
$ = $.replace(fromJsonRegex, '$1$2$3\n$2 if (excludes != null){ excludes = new System.Collections.Generic.HashSet<string>(excludes, global::System.StringComparer.OrdinalIgnoreCase);}');
574586
return $;
575587
}
576588

0 commit comments

Comments
 (0)