cjhowe
cjhowe
CC#
Created by cjhowe on 4/12/2024 in #help
Is it possible to use `Span` with a type erased `System.Array` created with `Array.CreateInstance`?
I am working on a C# ECS which stores its components in an archetype which contains an array of arrays. The outer arrays represent the various component types of the ECS (velocity, position), and the inner arrays represent all of the components of that type in the archetype (position 1 with x = 1, position 2 with y = 5). I want to be able to move components between arrays while avoiding copying in cases where it's unnecessary, even when the type is a value type. Ideally, I would be able to get references to items in this array, which I can pass into methods which expect that reference (these will probably be generic). Right now I'm pretty much always using Array.Copy, which doesn't allow me to get references to the array. Is there a way to obtain Spans or references from a type erased Array?
73 replies