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

Emit() public method

public Emit ( ) : void
return void
        public override void Emit()
        {
            var base_type = Parent.PartialContainer.BaseType;
            if (base_type != null && Block != null) {
                var base_dtor = MemberCache.FindMember (base_type,
                    new MemberFilter (MetadataName, 0, MemberKind.Destructor, null, null), BindingRestriction.InstanceOnly) as MethodSpec;

                if (base_dtor == null)
                    throw new NotImplementedException ();

                MethodGroupExpr method_expr = MethodGroupExpr.CreatePredefined (base_dtor, base_type, Location);
                method_expr.InstanceExpression = new BaseThis (base_type, Location);

                var try_block = new ExplicitBlock (block, block.StartLocation, block.EndLocation);
                var finaly_block = new ExplicitBlock (block, Location, Location);

                //
                // 0-size arguments to avoid CS0250 error
                // TODO: Should use AddScopeStatement or something else which emits correct
                // debugger scope
                //
                finaly_block.AddStatement (new StatementExpression (new Invocation (method_expr, new Arguments (0))));

                var tf = new TryFinally (try_block, finaly_block, Location);
                block.WrapIntoDestructor (tf, try_block);
            }

            base.Emit ();
        }