Пример #1
0
    public void Process()
    {
        typeSystem = ModuleWeaver.ModuleDefinition.TypeSystem;
        var disposeManagedMethod = TargetType.Methods
                                   .FirstOrDefault(x => !x.IsStatic && x.IsMatch("DisposeManaged"));
        var disposeUnmanagedMethod = TargetType.Methods
                                     .FirstOrDefault(x => !x.IsStatic && x.IsMatch("DisposeUnmanaged"));

        if (disposeUnmanagedMethod != null && disposeManagedMethod == null)
        {
            disposeManagedMethod = CreateDisposeManagedIfNecessary();
        }

        var error = TargetType.FieldExists("disposeSignaled") |
                    TargetType.FieldExists("disposed") |
                    TargetType.MethodExists("ThrowIfDisposed");

        if (error)
        {
            return;
        }

        CreateSignaledField();
        CreateDisposedField();
        CreateThrowIfDisposed();

        if (disposeUnmanagedMethod == null && disposeManagedMethod == null)
        {
            var methodProcessor = new SimpleDisposeProcessor
            {
                TypeProcessor = this
            };
            methodProcessor.Process();
        }
        else if (disposeUnmanagedMethod == null)
        {
            var methodProcessor = new OnlyManagedProcessor
            {
                TypeProcessor        = this,
                DisposeManagedMethod = disposeManagedMethod.GetGeneric()
            };
            methodProcessor.Process();
        }
        else if (disposeManagedMethod == null)
        {
            var methodProcessor = new OnlyUnmanagedProcessor
            {
                TypeProcessor          = this,
                DisposeUnmanagedMethod = disposeUnmanagedMethod.GetGeneric()
            };
            methodProcessor.Process();
        }
        else
        {
            var methodProcessor = new ManagedAndUnmanagedProcessor
            {
                TypeProcessor          = this,
                DisposeUnmanagedMethod = disposeUnmanagedMethod.GetGeneric(),
                DisposeManagedMethod   = disposeManagedMethod.GetGeneric()
            };
            methodProcessor.Process();
        }
        AddGuards();
    }
Пример #2
0
    public void Process()
    {
        typeSystem = ModuleWeaver.TypeSystem;
        var disposeManagedMethod = TargetType.Methods
                                   .FirstOrDefault(x => !x.IsStatic && x.IsMatch("DisposeManaged"));
        var disposeUnmanagedMethod = TargetType.Methods
                                     .FirstOrDefault(x => !x.IsStatic && x.IsMatch("DisposeUnmanaged"));

        if (disposeUnmanagedMethod != null && disposeManagedMethod == null)
        {
            disposeManagedMethod = CreateDisposeManagedIfNecessary();
        }

        if (TargetType.FieldExists("disposeSignaled"))
        {
            ModuleWeaver.LogError($"Type `{TargetType.FullName}` contains a `disposeSignaled` field. Either remove this field or add a `[Janitor.SkipWeaving]` attribute to the type.");
            return;
        }

        if (TargetType.FieldExists("disposed"))
        {
            ModuleWeaver.LogError($"Type `{TargetType.FullName}` contains a `disposed` field. Either remove this field or add a `[Janitor.SkipWeaving]` attribute to the type.");
            return;
        }

        if (TargetType.MethodExists("ThrowIfDisposed"))
        {
            ModuleWeaver.LogError($"Type `{TargetType.FullName}` contains a `ThrowIfDisposed` method. Either remove this method or add a `[Janitor.SkipWeaving]` attribute to the type.");
            return;
        }

        CreateSignaledField();
        CreateDisposedField();
        CreateThrowIfDisposed();

        if (disposeUnmanagedMethod == null && disposeManagedMethod == null)
        {
            var methodProcessor = new SimpleDisposeProcessor
            {
                TypeProcessor = this
            };
            methodProcessor.Process();
        }
        else if (disposeUnmanagedMethod == null)
        {
            var methodProcessor = new OnlyManagedProcessor
            {
                TypeProcessor        = this,
                DisposeManagedMethod = disposeManagedMethod.GetGeneric()
            };
            methodProcessor.Process();
        }
        else if (disposeManagedMethod == null)
        {
            var methodProcessor = new OnlyUnmanagedProcessor
            {
                TypeProcessor          = this,
                DisposeUnmanagedMethod = disposeUnmanagedMethod.GetGeneric()
            };
            methodProcessor.Process();
        }
        else
        {
            var methodProcessor = new ManagedAndUnmanagedProcessor
            {
                TypeProcessor          = this,
                DisposeUnmanagedMethod = disposeUnmanagedMethod.GetGeneric(),
                DisposeManagedMethod   = disposeManagedMethod.GetGeneric()
            };
            methodProcessor.Process();
        }

        AddGuards();
    }
Пример #3
0
    public void Process()
    {
        typeSystem = ModuleWeaver.ModuleDefinition.TypeSystem;
        var disposeManagedMethod = TargetType.Methods
            .FirstOrDefault(x => !x.IsStatic && x.IsMatch("DisposeManaged"));
        var disposeUnmanagedMethod = TargetType.Methods
            .FirstOrDefault(x => !x.IsStatic && x.IsMatch("DisposeUnmanaged"));

        if (disposeUnmanagedMethod != null && disposeManagedMethod == null)
        {
            disposeManagedMethod = CreateDisposeManagedIfNecessary();
        }

        var error = TargetType.FieldExists("disposeSignaled") |
                    TargetType.FieldExists("disposed") |
                    TargetType.MethodExists("ThrowIfDisposed");
        if (error)
        {
            return;
        }

        CreateSignaledField();
        CreateDisposedField();
        CreateThrowIfDisposed();

        if (disposeUnmanagedMethod == null && disposeManagedMethod == null)
        {
            var methodProcessor = new SimpleDisposeProcessor
                                  {
                                      TypeProcessor = this
                                  };
            methodProcessor.Process();
        }
        else if (disposeUnmanagedMethod == null)
        {
            var methodProcessor = new OnlyManagedProcessor
                                  {
                                      TypeProcessor = this,
                                      DisposeManagedMethod = disposeManagedMethod.GetGeneric()
                                  };
            methodProcessor.Process();

        }
        else if (disposeManagedMethod == null)
        {
            var methodProcessor = new OnlyUnmanagedProcessor
                                  {
                                      TypeProcessor = this,
                                      DisposeUnmanagedMethod = disposeUnmanagedMethod.GetGeneric()
                                  };
            methodProcessor.Process();
        }
        else
        {
            var methodProcessor = new ManagedAndUnmanagedProcessor
                                  {
                                      TypeProcessor = this,
                                      DisposeUnmanagedMethod = disposeUnmanagedMethod.GetGeneric(),
                                      DisposeManagedMethod = disposeManagedMethod.GetGeneric()
                                  };
            methodProcessor.Process();
        }
        AddGuards();
    }