[InlineArray] is not particularly array-like #8177
-
The new One of the most common array operations, if not the most common, is iteration: either going over every element with a Would it be possible to apply some of the same compiler magic to create a fake |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 18 replies
-
InlineArray is intended to be the hidden backing storage, that is not used directly. Instead, you can just wrap it freely as a span, and then get all the niceties of that higher level abstraction. |
Beta Was this translation helpful? Give feedback.
-
This should be possible with extensions in c#13 |
Beta Was this translation helpful? Give feedback.
-
I know it’s a broken record (heh), but source generators can help you here. Have one detect |
Beta Was this translation helpful? Give feedback.
-
Honestly the only answer here should be to just cast it to a Everything else feels unnecessarily complicated to me. Extensions are not a good solution because it's not possible to write a single extension that can cover all inline array types. Source generators can technically get the job done, but they feel seriously overkill too. Given that the compiler knows at all times how long the inline array type is, it feels a little silly that it's not more trivial to just have the compiler emit a |
Beta Was this translation helpful? Give feedback.
Honestly the only answer here should be to just cast it to a
Span<T>
and then get theLength
. It jumps through a few hoops but at least the runtime seems perfectly capable of folding everything and just returning the constant value.Everything else feels unnecessarily complicated to me. Extensions are not a good solution because it's not possible to write a single extension that can cover all inline array types. Source generators can technically get the job done, but they feel seriously overkill too. Given that the compiler knows at all times how long the inline array type is, it feels a little silly that it's not more trivial to just have the compiler emit a
Length
const or the like on t…