-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add Enum generic overloads #33589
Add Enum generic overloads #33589
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
a95f38d
to
571ef84
Compare
src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/PlatformDetection.cs
Outdated
Show resolved
Hide resolved
571ef84
to
c814ad2
Compare
#else | ||
public static bool IsReflectionEmitSupported = true; | ||
public static bool IsReflectionEmitSupported => true; |
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.
Why did these change as part of this PR?
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.
Because I need to use ConditionalFact
, which only supports properties and not fields
=> (TEnum[])GetValues(typeof(TEnum)); | ||
|
||
public static bool IsDefined<TEnum>(TEnum value) where TEnum : struct, Enum | ||
=> IsDefined(typeof(TEnum), value); |
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.
What is the benefit of this method if it's just going to box the argument? Just being able to write Enum.IsDefined(value)
instead of Enum.IsDefined(typeof(MyEnum), value)
?
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 can be certainly implemented more efficiently. It just needs to do this:
runtime/src/libraries/System.Private.CoreLib/src/System/RuntimeType.cs
Lines 267 to 270 in 25ea6c4
ulong[] ulValues = Enum.InternalGetValues(this); | |
ulong ulValue = Enum.ToUInt64(value); | |
return Array.BinarySearch(ulValues, ulValue) >= 0; |
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 is true. I will investigate this tomorrow. Just rebasing now to make sure it all builds
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.
@stephentoub One benefit would be that the value and type cannot be accidentally mismatched.
18d04fb
to
fe1ba0a
Compare
b630618
to
284d3a3
Compare
@hughbe the Preview 7 cutoff is quickly approaching (July 15th). Please try to address feedback before then. Thanks |
Okay. Working on this now, sorry for the delay! |
284d3a3
to
75af538
Compare
I moved some stuff around because it was shared between mono/CoreCLR, and optimized the implementation of |
75af538
to
13eecb5
Compare
src/coreclr/src/System.Private.CoreLib/src/System/Enum.CoreCLR.cs
Outdated
Show resolved
Hide resolved
src/coreclr/src/System.Private.CoreLib/src/System/Enum.CoreCLR.cs
Outdated
Show resolved
Hide resolved
Jan, could you also check if there are any worthwile opportunities to optimise the generic functions. I could avoid a few checks like |
Agree. The reason for adding these APIs is syntax sugar, not performance. |
713bd57
to
730c01e
Compare
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.
Thank you!
Fixes #2364
Contributes to #20008
Maybe fixes #18063