Generics for reducing redundancies I have a routine that can be potentially reduced.

internal ArrayBufferObject GetAccessorArray()
{
    ColladaDocument colladaDocument = GetColladaDocument();
    ColladaArray colladaArray = colladaDocument.GetSpecialElement&lt;ColladaArray&gt;(Source);
    ArrayBufferObject bufferObject;

    if (IsSimpleParamsConfiguration() == false)
        throw new NotSupportedException("complex accessor params not supported");

    string simpleParamsType = Params[0].Type;

    if (simpleParamsType == ArrayTypeFloat) {
        uint cursorOffset = Offset;

        ArrayBufferObject&lt;float&gt; arrayBufferObject = new ArrayBufferObject&lt;float&gt;(BufferObject.Hint.StaticCpuDraw);

        for (uint i = 0; i &lt; Count; i++) {
            foreach (ColladaParam param in Params) {
                if (param.Name != null)
                    arrayBufferObject[cursorOffset - Offset] = (float) colladaArray[cursorOffset];
                cursorOffset++;
            }
            cursorOffset += Stride - (uint)Params.Count;
        }

        bufferObject = arrayBufferObject;

    } else if (simpleParamsType == ArrayTypeInt) {
        uint cursorOffset = Offset;

        ArrayBufferObject&lt;int&gt; arrayBufferObject = new ArrayBufferObject&lt;int&gt;(BufferObject.Hint.StaticCpuDraw);

        for (uint i = 0; i &lt; Count; i++) {
            foreach (ColladaParam param in Params) {
                if (param.Name != null)
                    arrayBufferObject[cursorOffset - Offset] = (int) colladaArray[cursorOffset];
                cursorOffset++;
            }
            cursorOffset += Stride - (uint)Params.Count;
        }

        bufferObject = arrayBufferObject;
    } else
        throw new NotSupportedException(String.Format("simple accessor params type {0} not supported", simpleParamsType));

    return (bufferObject);
}


As you can see, there are two if branches that are the same. Essentially they create a generic class using float and int type.

The class ArrayBufferObject is the base of ArrayBufferObject&lt;T&gt;, but only the latter implements an indexer (strongly typed). It is implemented as following:

public T this[uint index]
{
    get
    {
        if ((MemoryBuffer == null) || (MemoryBuffer.AlignedBuffer == IntPtr.Zero))
            throw new InvalidOperationException("not defined");
        if (index &gt;= ItemCount)
            throw new ArgumentException("index out of bounds", "index");

        return ((T) Marshal.PtrToStructure(new IntPtr(MemoryBuffer.AlignedBuffer.ToInt64() + (index * mItemSize)), typeof(T)));
    }
    set
    {
        if ((MemoryBuffer == null) || (MemoryBuffer.AlignedBuffer == IntPtr.Zero))
            throw new InvalidOperationException("not defined");
        if (index &gt;= ItemCount)
            throw new ArgumentException("index out of bounds", "index");

        Marshal.StructureToPtr(value, new IntPtr(MemoryBuffer.AlignedBuffer.ToInt64() + (index * mItemSize)), false);
    }
}


The source of the assigned item comes from a ColladaArray class, that is an abstract class wrapping an array of values. To resolve the data accessor I've defined in it a generic numeric accessor like the following:

/// &lt;summary&gt;
/// Access this array.
/// &lt;/summary&gt;
/// &lt;param name="i"&gt;
/// The index of the element to be accessed.
/// &lt;/param&gt;
/// &lt;returns&gt;
/// It returns an equivalent &lt;see cref="System.Double"/&gt; of the value accessed.
/// &lt;/returns&gt;
public virtual double this[uint i] { get { throw new NotSupportedException("array accessor not implemented"); } }


Which is implemented in each derived class returning the real array value casted to double (all arrays contains numeric data... hopefully).



How would you suggest to remove the GetAccessorArray routine redundancies? Help! Soon it will grow up with all possible numeric types!
Presumably you could pull those sections out into a generic method. 

private ArrayBufferObject CreateArrayBuffer&lt;T&gt;(ColladaArray colladaArray)
{
     uint cursorOffset = Offset;

     ArrayBufferObject&lt;T&gt; arrayBufferObject = new ArrayBufferObject&lt;T&gt;(BufferObject.Hint.StaticCpuDraw);

     for (uint i = 0; i &lt; Count; i++)
     {
         foreach (ColladaParam param in Params)
         {
             if (param.Name != null)
                 arrayBufferObject[cursorOffset - Offset] = (T)Convert.ChangeType(colladaArray[cursorOffset], typeof(T));
             cursorOffset++;
         }
         cursorOffset += Stride - (uint)Params.Count;
     }

     return arrayBufferObject;
}


And then replace those sections with a call to that method.

if (simpleParamsType == ArrayTypeFloat)
    return CreateArrayBuffer&lt;float&gt;(colladaArray);
else if (simpleParamsType == ArrayTypeInt)
    return CreateArrayBuffer&lt;int&gt;(colladaArray);
else
    throw new NotSupportedException(String.Format("simple accessor params type {0} not supported", simpleParamsType));


Depending on the types that you're converting to and from, the call to Convert.ChangeType() may have to be changed to something else, but it should be sufficient for the standard numeric types. For more information on type conversion, see this.