public PropertyWeaver(ModuleWeaver moduleWeaver, PropertyData propertyData, TypeNode typeNode, TypeSystem typeSystem)
 {
     this.moduleWeaver = moduleWeaver;
     this.propertyData = propertyData;
     this.typeNode     = typeNode;
     this.typeSystem   = typeSystem;
 }
Beispiel #2
0
 public void Process()
 {
     typeSystem = TypeProcessor.ModuleWeaver.TypeSystem;
     CreateDisposeBoolMethod();
     InjectIntoDispose();
     TypeProcessor.AddFinalizer(DisposeBoolMethod);
 }
 void InitialiseTypeSystem()
 {
     TypeSystem = new TypeSystem(TypeCache.FindType, ModuleDefinition);
     foreach (var weaver in weaverInstances)
     {
         weaver.Instance.TypeSystem = TypeSystem;
     }
 }
Beispiel #4
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();
    }