This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Cache polymorphic properties #41753
Merged
Merged
Cache polymorphic properties #41753
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5d363fa
Cache polymorphic properties
svick 92b9b1e
Move RuntimePropertyCache to JsonClassInfo
svick 2f0cf17
Added test of RuntimePropertyCache using properties with different at…
svick 826bc61
Fixed typo
svick df45181
Use allocating overload of GetOrAdd on .Net Standard 2.0
svick e72ba56
Merge branch 'master' into json-object-property
svick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,5 +75,30 @@ public int this[int index] | |
|
||
public string NonIndexerProp { get; set; } | ||
} | ||
|
||
[Fact] | ||
public static void WritePolymorhicSimple() | ||
{ | ||
string json = JsonSerializer.Serialize(new { Prop = (object)new[] { 0 } }); | ||
Assert.Equal(@"{""Prop"":[0]}", json); | ||
} | ||
|
||
[Fact] | ||
public static void WritePolymorphicDifferentAttributes() | ||
{ | ||
string json = JsonSerializer.Serialize(new Polymorphic()); | ||
Assert.Equal(@"{""P1"":"""",""p_3"":""""}", json); | ||
} | ||
|
||
private class Polymorphic | ||
{ | ||
public object P1 => ""; | ||
|
||
[JsonIgnore] | ||
public object P2 => ""; | ||
|
||
[JsonPropertyName("p_3")] | ||
public object P3 => ""; | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add tests with different properties with the same |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify the generic explicitly?
Edit: Nevermind
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API isn't available on netstandard 2.0, which is why the build is failing.
Can you #if/def the code using BUILDING_INBOX_LIBRARY and in the else block, only use netstandard2.0 compatible APIs?