Question: I'm programming a game in C# and I'm using a SoA pattern for performance-critical components.

Here's an example:

```
public class ComponentData
{
    public int[] Ints;
    public float[] Floats;
}

```

Ideally, I'd want other programmers to only specify this data (as above) and be done with it. However, some operations have to be done for each array, like allocating, copying, growing, etc. Right now I'm using an abstract class with abstract methods to implement those, like so:

```
public class ComponentData : BaseData
{
    public int[] Ints;
    public float[] Floats;

    protected override void Allocate(int size)
    {
        Ints = new int[size];
        Floats = new float[size];
    }

    protected override void Copy(int source, int destination)
    {
        Ints[destination] = Ints[source];
        Floats[destination] = Floats[source];
    }

    // And so on...
}

```

This requires the programmer to add all of this boilerplate code everytime she writes a new component, and every time she adds a new array.

I tried figuring it out by using templates, and while this works for the AoS pattern, it doesn't do much good for SoA (having `Data : BaseData<int, float>` would be extremely vague).

So I'd like to hear ideas for automatically "injecting" these arrays somewhere to reduce the extreme amount of boilerplate code.

Answer: 
The idea was the following:

```
public abstract class ComponentData : BaseData
{
    public Collection<Array> ArraysRegister { get; private set; }

    public int[] Ints;

    public float[] Floats;

    public ComponentData()
    {
      ArraysRegister = new Collection<Array>();
      ArraysRegister.Add(this.Ints);
      ArraysRegister.Add(this.Floats);
      /* whatever you need in base class*/
    }

    protected void Copy(int source, int destination)
    {
      for (int i = 0; i < ArraysRegister.Count; i++)
      {
        ArraysRegister[i][destination] = ArraysRegister[i][source];
      }
    }
    /* All the other methods */
}

public class SomeComponentData : ComponentData
{
    // In child class you only have to define property...
    public decimal[] Decimals;

    public SomeComponentData()
    {
      // ... and add it to Register
      ArraysRegister.Add(this.Decimals);
    }
    // And no need to modify all the base methods
}

```

It is not perfect however (something has to be done with allocation), but at least implementing child class you don't have to override all the methods of base class that deal with arrays. Is it worth doing or not depends on how much similar methods you have.
I would suggest defining a collection of all arrays used by class and then making all the necessary operations upon all of them in cycle.