Beispiel #1
0
        private void DefineFieldsAndMethods(TypeBuilder typeBuilder, Cci.ITypeDefinition typeDef)
        {
            // Ref.Emit quirk: 
            // We need to define methods (at least generic methods with type parameter constrains) before constructors.
            // Unfortunately ConstructorBuilder gets a token for the underlying method builder,
            // which might trigger baking of generic parameters of other method builders! 

            // methods
            foreach (Cci.IMethodDefinition methodDef in typeDef.GetMethods(_context))
            {
                if (!methodDef.IsConstructor)
                {
                    DefineMethod(typeBuilder, methodDef);
                }
            }

            // constructors
            foreach (Cci.IMethodDefinition methodDef in typeDef.GetMethods(_context))
            {
                if (methodDef.IsConstructor)
                {
                    DefineConstructor(typeBuilder, methodDef);
                }
            }

            // fields
            foreach (Cci.IFieldDefinition fieldDef in typeDef.GetFields(_context))
            {
                Debug.Assert(fieldDef.IsStatic || !typeDef.IsEnum || fieldDef.Name == WellKnownMemberNames.EnumBackingFieldName);
                DefineField(typeBuilder, fieldDef);
            }
        }