[Proposal] - Provide support for extension methods which can accept unsafe pointer arguments #1521
Unanswered
The-Futurist
asked this question in
Language Ideas
Replies: 2 comments
-
In answer to your bump in the other thread, my best guess is that others (like me) saw this use case as so far outside our radar when we read it that we have nothing to say. |
Beta Was this translation helpful? Give feedback.
0 replies
-
@Korporal, for Otherwise, you can use reflection to query the size of the backing type and divide it by the size of the base type. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
There is currently no way to write extension methods that operate upon unsafe pointers. Nor is there any way to determine the length of an unsafe fixed buffer at runtime.
Introducing each of these will make it easier to write reusable code now that support for the
unmanaged
generic constraint has been introduced.The length of an unsafe fixed buffer is always a compile time constant yet the length is more or less inaccessible at runtime this means that designers must add members (e.g. constants) that define this length if consuming code needs to know these lengths as for example if converting between fixed buffer text arrays and .Net strings.
UPDATE: After some experimentation, there is a way to get at fixed buffer metadata that entails reflection of attributes of compiler generated classes. This is different today to what it was a few years ago (the attributes aren't the same in the current (7.3) version of the C# compiler as those in the past or so it seems from my experience, the current compiler no longer leverages the FixedBufferAttribute).
Having this as part of the C# language or .Net would be better than ad-hoc, heuristic mechanisms relying on this or that attribute class being reflected so does anyone have any ideas as to how to provide this going forward?
Beta Was this translation helpful? Give feedback.
All reactions