void CreateDisposeBoolMethod()
    {
        DisposeBoolMethod = new MethodDefinition("Dispose", MethodAttributes.HideBySig | MethodAttributes.Private, typeSystem.Void);
        var disposingParameter = new ParameterDefinition("disposing", ParameterAttributes.None, typeSystem.Boolean);

        DisposeBoolMethod.Parameters.Add(disposingParameter);

        var instructions = DisposeBoolMethod.Body.Instructions;

        instructions.Add(TypeProcessor.GetDisposeEscapeInstructions());

        var skipDisposeManaged = Instruction.Create(OpCodes.Nop);

        instructions.Add(
            Instruction.Create(OpCodes.Ldarg, disposingParameter),
            Instruction.Create(OpCodes.Brfalse, skipDisposeManaged),
            Instruction.Create(OpCodes.Ldarg_0),
            Instruction.Create(DisposeManagedMethod.GetCallingConvention(), DisposeManagedMethod),
            skipDisposeManaged,
            Instruction.Create(OpCodes.Ldarg_0),
            Instruction.Create(DisposeUnmanagedMethod.GetCallingConvention(), DisposeUnmanagedMethod)
            );

        instructions.Add(TypeProcessor.GetDisposedInstructions());
        instructions.Add(Instruction.Create(OpCodes.Ret));

        TypeProcessor.TargetType.Methods.Add(DisposeBoolMethod);
    }
Example #2
0
    public void Process()
    {
        var instructions = TypeProcessor.DisposeMethod.Body.Instructions;

        instructions.Clear();
        instructions.Add(TypeProcessor.GetDisposeEscapeInstructions());
        instructions.Add(
            Instruction.Create(OpCodes.Ldarg_0),
            Instruction.Create(DisposeManagedMethod.GetCallingConvention(), DisposeManagedMethod));
        instructions.Add(TypeProcessor.GetDisposedInstructions());
        instructions.Add(Instruction.Create(OpCodes.Ret));
    }
    void CreateDisposeBoolMethod()
    {
        var typeSystem = TypeProcessor.ModuleWeaver.ModuleDefinition.TypeSystem;

        disposeBoolMethod = new MethodDefinition("Dispose", MethodAttributes.HideBySig | MethodAttributes.Private, typeSystem.Void);
        var disposingParameter = new ParameterDefinition("disposing", ParameterAttributes.None, typeSystem.Boolean);

        disposeBoolMethod.Parameters.Add(disposingParameter);

        var instructions = disposeBoolMethod.Body.Instructions;

        instructions.Add(TypeProcessor.GetDisposeEscapeInstructions());

        instructions.Add(
            Instruction.Create(OpCodes.Ldarg_0),
            Instruction.Create(DisposeUnmanagedMethod.GetCallingConvention(), DisposeUnmanagedMethod));
        instructions.Add(TypeProcessor.GetDisposedInstructions());
        instructions.Add(Instruction.Create(OpCodes.Ret));

        TypeProcessor.TargetType.Methods.Add(disposeBoolMethod);
        TypeProcessor.AddFinalizer(disposeBoolMethod);
    }