-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Need api to determine if a type is "byref-like." #20673
Comments
This should wait for the design for byref-like types (e.g. dotnet/csharplang#264). I expect that the byref-like types will be explicitly marked by a custom attribute. So this property won't be inferred, but explicitly specified instead and this API will be essentially just a fetch of this custom attribute (or more efficient equivalent). |
This would be an API that should be used in Cc @JonHanna |
@MichalStrehovsky From taking a look at a disassembly of the version in the GAC it seems that that version is implementing |
These now have an approved attribute ( [EDIT] Fixed attribute name to |
We should align this with the attribute we approved earlier, which is named |
FYI: The API review discussion was recorded - see https://youtu.be/VppFZYG-9cA?t=5306 (4 min duration) |
* Expose IsByRefLike api. Api was approved today: Fixes https://github.com/dotnet/corefx/issues/17232 CoreRT/CoreCLR implementations were done some time ago (we needed them internally.) So this just exposes the api in the contract. * Also need to override on EnumBuilder and GenericTypeParameterBuilder * TypeFromCLSID not supported on Unix
@terrajobst The IsByRefLike property on |
@bergmeister Correct, the workaround is to check for presence of IsByRefLikeAttribute. The first class support for byref-like types is present in .NET Core only. |
Proposal for New API:
With Span<>, we're now introducing a mainstream type that has "by-ref-like" or "stack-only" restrictions. We also have TypedReference in this bucket, but Span<> takes this concept out of the "eccentric uncle in the closet" realm.
There is, however, no robust way to know if a type has these restrictions. Apis like Array.CreateInstance() need to guard against these types (dotnet/corert#3000) and could use a formalized way to catch these types. It's likely that checks like these could go viral into app code or higher level libraries that call apis like this.
The text was updated successfully, but these errors were encountered: