Beispiel #1
0
        TypeBuilder CreateTypeBuilder(DataType dt, TypeBuilder parent, TypeAttributes typeAttrs, Type typeBase)
        {
            var result = parent?.DefineNestedType(dt.CilTypeName(), dt.CilTypeAttributes(true) | typeAttrs, typeBase) ?? _module.DefineType(dt.CilTypeName(), dt.CilTypeAttributes(false) | typeAttrs, typeBase);
            var data   = new CilType(_backend, _essentials, _linker, result, dt);

            if (!dt.IsEnum && dt.IsFlattenedDefinition)
            {
                var flatParams     = dt.FlattenedParameters;
                var flatParamNames = new string[flatParams.Length];

                for (int i = 0, l = flatParamNames.Length; i < l; i++)
                {
                    flatParamNames[i] = flatParams[i].Name;
                }

                var resultParams = result.DefineGenericParameters(flatParamNames);

                for (int i = 0; i < resultParams.Length; i++)
                {
                    data.GenericParameters.Add(new CilMember <GenericTypeParameterBuilder, GenericParameterType>(resultParams[i], flatParams[i]));
                }

                if (dt.IsGenericDefinition)
                {
                    var dtParams = dt.GenericParameters;

                    for (int i = 0, l = dtParams.Length; i < l; i++)
                    {
                        _linker.AddType(dtParams[i], resultParams[resultParams.Length - dtParams.Length + i]);
                    }
                }
            }

            _linker.AddType(dt, result);
            Add(data);
            return(result);
        }