Mono.CSharp.Constructor.Emit C# (CSharp) Method

Emit() public method

public Emit ( ) : void
return void
        public override void Emit()
        {
            if (Parent.PartialContainer.IsComImport) {
                if (!IsDefault ()) {
                    Report.Error (669, Location, "`{0}': A class with the ComImport attribute cannot have a user-defined constructor",
                        Parent.GetSignatureForError ());
                }

                // Set as internal implementation and reset block data
                // to ensure no IL is generated
                ConstructorBuilder.SetImplementationFlags (MethodImplAttributes.InternalCall);
                block = null;
            }

            if ((ModFlags & Modifiers.DEBUGGER_HIDDEN) != 0)
                Module.PredefinedAttributes.DebuggerHidden.EmitAttribute (ConstructorBuilder);

            if (OptAttributes != null)
                OptAttributes.Emit ();

            base.Emit ();

            //
            // If we use a "this (...)" constructor initializer, then
            // do not emit field initializers, they are initialized in the other constructor
            //
            bool emit_field_initializers = ((ModFlags & Modifiers.STATIC) != 0) ||
                !(Initializer is ConstructorThisInitializer);

            BlockContext bc = new BlockContext (this, block, TypeManager.void_type);
            bc.Set (ResolveContext.Options.ConstructorScope);

            if (emit_field_initializers)
                Parent.PartialContainer.ResolveFieldInitializers (bc);

            if (block != null) {
                // If this is a non-static `struct' constructor and doesn't have any
                // initializer, it must initialize all of the struct's fields.
                if ((Parent.PartialContainer.Kind == MemberKind.Struct) &&
                    ((ModFlags & Modifiers.STATIC) == 0) && (Initializer == null))
                    block.AddThisVariable (bc, Parent, Location);

                if (block != null && (ModFlags & Modifiers.STATIC) == 0){
                    if (Parent.PartialContainer.Kind == MemberKind.Class && Initializer == null)
                        Initializer = new GeneratedBaseInitializer (Location);

                    if (Initializer != null) {
                        block.AddScopeStatement (new StatementExpression (Initializer));
                    }
                }
            }

            parameters.ApplyAttributes (this, ConstructorBuilder);

            SourceMethod source = SourceMethod.Create (Parent, ConstructorBuilder, block);

            if (block != null) {
                if (block.Resolve (null, bc, this)) {
                    EmitContext ec = new EmitContext (this, ConstructorBuilder.GetILGenerator (), bc.ReturnType);
                    ec.With (EmitContext.Options.ConstructorScope, true);

                    if (!ec.HasReturnLabel && bc.HasReturnLabel) {
                        ec.ReturnLabel = bc.ReturnLabel;
                        ec.HasReturnLabel = true;
                    }

                    block.Emit (ec);
                }
            }

            if (source != null)
                source.CloseMethod ();

            //            if (declarative_security != null) {
            //                foreach (var de in declarative_security) {
            //#if STATIC
            //                    ConstructorBuilder.__AddDeclarativeSecurity (de);
            //#else
            //                    ConstructorBuilder.AddDeclarativeSecurity (de.Key, de.Value);
            //#endif
            //                }
            //            }

            block = null;
        }