TypeDefinition getArrayType(long size)
        {
            createOurType();

            TypeDefinition arrayType;

            if (sizeToArrayType.TryGetValue(size, out arrayType))
            {
                return(arrayType);
            }

            if (valueType == null)
            {
                valueType = DotNetUtils.findOrCreateTypeReference(module, module.TypeSystem.Corlib as AssemblyNameReference, "System", "ValueType", false);
            }
            var attrs = TypeAttributes.NestedPrivate | TypeAttributes.ExplicitLayout |
                        TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.AnsiClass;

            arrayType = new TypeDefinition("", string.Format("__StaticArrayInitTypeSize={0}", size), attrs, valueType);
            arrayType.MetadataToken = DotNetUtils.nextTypeDefToken();
            ourType.NestedTypes.Add(arrayType);
            sizeToArrayType[size] = arrayType;
            arrayType.ClassSize   = (int)size;
            arrayType.PackingSize = 1;
            arrayType.IsValueType = true;
            return(arrayType);
        }
 MethodReference createInitializeArrayMethod()
 {
     if (initializeArrayMethod == null)
     {
         var runtimeHelpersType = DotNetUtils.findOrCreateTypeReference(module, module.TypeSystem.Corlib as AssemblyNameReference, "System.Runtime.CompilerServices", "RuntimeHelpers", false);
         initializeArrayMethod = new MethodReference("InitializeArray", module.TypeSystem.Void, runtimeHelpersType);
         var systemArrayType        = DotNetUtils.findOrCreateTypeReference(module, module.TypeSystem.Corlib as AssemblyNameReference, "System", "Array", false);
         var runtimeFieldHandleType = DotNetUtils.findOrCreateTypeReference(module, module.TypeSystem.Corlib as AssemblyNameReference, "System", "RuntimeFieldHandle", true);
         initializeArrayMethod.Parameters.Add(new ParameterDefinition(systemArrayType));
         initializeArrayMethod.Parameters.Add(new ParameterDefinition(runtimeFieldHandleType));
     }
     return(initializeArrayMethod);
 }