-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Add Type.GetNullableUnderlyingType() virtual API
#126905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AaronRobinsonMSFT
wants to merge
24
commits into
dotnet:main
Choose a base branch
from
AaronRobinsonMSFT:fix/124216-nullable-getunderlyingtype
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
90ed195
Add Type.GetNullableUnderlyingType() virtual API
AaronRobinsonMSFT 2e7a9fb
Address review feedback for Type.GetNullableUnderlyingType()
AaronRobinsonMSFT 656890c
Merge remote-tracking branch 'upstream/main' into fix/124216-nullable…
AaronRobinsonMSFT 1aa46f5
Improve MLC tests: throwOnError and stronger assertions
AaronRobinsonMSFT e8a877d
Efficient GetNullableUnderlyingType() via MethodTable for CoreCLR/Nat…
AaronRobinsonMSFT 325f699
Add GetNullableUnderlyingType() overrides for Emit/Modified types; mo…
AaronRobinsonMSFT 5da1c09
Fix open-generic Nullable<> edge cases and preserve TypeBuilderInstan…
AaronRobinsonMSFT 8a39a7a
Remove unnecessary using directive for System.Runtime.InteropServices…
AaronRobinsonMSFT 9f9b085
Fix RoType.GetNullableUnderlyingType guard: use NET11_0_OR_GREATER no…
AaronRobinsonMSFT 4e99b77
Fix SignatureConstructedGenericType.GetNullableUnderlyingType to retu…
AaronRobinsonMSFT 6a03178
Apply suggestions from code review
AaronRobinsonMSFT 2153bf1
Apply suggestion from @jkotas
jkotas d7228ab
Update src/libraries/System.Private.CoreLib/src/System/Nullable.cs
jkotas 2a92fa3
Apply suggestion from @jkotas
jkotas 8c08626
Fix GetNullableUnderlyingType crashes and wrong results
AaronRobinsonMSFT 2de90fc
Apply jkotas review feedback: add GetNullableUnderlyingType overrides
AaronRobinsonMSFT 92e3faf
Treat Nullable<> generic type definition as nullable in Type.GetNulla…
AaronRobinsonMSFT 49353e3
Merge remote-tracking branch 'upstream/main' into fix/124216-nullable…
AaronRobinsonMSFT 85e3ec5
Address review feedback: fix Nullable<> over foreign generic parameter
AaronRobinsonMSFT 475eb35
Fix misleading comment on SignatureType.GetNullableUnderlyingType
AaronRobinsonMSFT 0e694d9
Fix CoreCLR assert when Nullable<T> is instantiated over a generic va…
AaronRobinsonMSFT bc3b14d
Address PR feedback: refactor NativeAOT override and add tests
AaronRobinsonMSFT f631afa
Override GetNullableUnderlyingType on RoModifiedType
AaronRobinsonMSFT 1c5764b
Override GetNullableUnderlyingType on SymbolType
AaronRobinsonMSFT 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
80 changes: 80 additions & 0 deletions
80
...ibraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderGetNullableUnderlyingType.cs
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Xunit; | ||
|
|
||
| namespace System.Reflection.Emit.Tests | ||
| { | ||
| public class TypeBuilderGetNullableUnderlyingType | ||
| { | ||
| [Fact] | ||
| public void TypeBuilder_ReturnsNull() | ||
| { | ||
| TypeBuilder tb = Helpers.DynamicType(TypeAttributes.Public); | ||
| Assert.Null(tb.GetNullableUnderlyingType()); | ||
| } | ||
|
AaronRobinsonMSFT marked this conversation as resolved.
|
||
|
|
||
| [Fact] | ||
| public void EnumBuilder_ReturnsNull() | ||
| { | ||
| EnumBuilder eb = Helpers.DynamicEnum(TypeAttributes.Public, typeof(int)); | ||
| Assert.Null(eb.GetNullableUnderlyingType()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GenericTypeParameterBuilder_ReturnsNull() | ||
| { | ||
| TypeBuilder tb = Helpers.DynamicType(TypeAttributes.Public); | ||
| GenericTypeParameterBuilder[] gps = tb.DefineGenericParameters("T"); | ||
| Assert.Null(gps[0].GetNullableUnderlyingType()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TypeBuilderInstantiation_ReturnsNull() | ||
| { | ||
| // A TypeBuilderInstantiation is produced when MakeGenericType is called on a | ||
| // generic TypeBuilder. The open generic definition is a TypeBuilder (never | ||
| // typeof(Nullable<>)), so the override always returns null in practice. | ||
| TypeBuilder tb = Helpers.DynamicType(TypeAttributes.Public); | ||
| tb.DefineGenericParameters("T"); | ||
| Type instantiation = tb.MakeGenericType(typeof(int)); | ||
| Assert.Null(instantiation.GetNullableUnderlyingType()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void SymbolType_Array_ReturnsNull() | ||
| { | ||
| TypeBuilder tb = Helpers.DynamicType(TypeAttributes.Public); | ||
| Type arrayType = tb.MakeArrayType(); | ||
| Assert.Null(arrayType.GetNullableUnderlyingType()); | ||
| Assert.Null(Nullable.GetUnderlyingType(arrayType)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void SymbolType_MultiDimArray_ReturnsNull() | ||
| { | ||
| TypeBuilder tb = Helpers.DynamicType(TypeAttributes.Public); | ||
| Type arrayType = tb.MakeArrayType(2); | ||
| Assert.Null(arrayType.GetNullableUnderlyingType()); | ||
| Assert.Null(Nullable.GetUnderlyingType(arrayType)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void SymbolType_Pointer_ReturnsNull() | ||
| { | ||
| TypeBuilder tb = Helpers.DynamicType(TypeAttributes.Public); | ||
| Type pointerType = tb.MakePointerType(); | ||
| Assert.Null(pointerType.GetNullableUnderlyingType()); | ||
| Assert.Null(Nullable.GetUnderlyingType(pointerType)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void SymbolType_ByRef_ReturnsNull() | ||
| { | ||
| TypeBuilder tb = Helpers.DynamicType(TypeAttributes.Public); | ||
| Type byRefType = tb.MakeByRefType(); | ||
| Assert.Null(byRefType.GetNullableUnderlyingType()); | ||
| Assert.Null(Nullable.GetUnderlyingType(byRefType)); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.