Beispiel #1
0
    private void DecorateDirectlyAttributed(EntryExitDecorator.Fody.MethodDecorator decorator, TypeDefinition idecorator)
    {
        var res = ModuleDefinition.Types.SelectMany(GetAllTypes).Select(t => GetTypes(idecorator, t)).Where(x => x != null).ToList();
        // if it's not the class the directly implements the interface and if it's the most derived class from it, grab it
        var markerTypeDefinitions = res.Where(t => (t.Item1 != t.Item2 && res.Any(p => p.Item1 == t.Item2) && res.All(p => p.Item1.BaseType != t.Item1))).ToList();

        if (!markerTypeDefinitions.Any())
        {
            if (LogError != null)
            {
                LogError("Could not find any subclass of IEntryExitDecorator");
            }
            //throw new WeavingException("Could not find any method decorator attribute");
        }

        foreach (var tuple in markerTypeDefinitions)
        {
            var methods = this.FindClassMethods(tuple.Item1);
            var entry   = tuple.Item2.Methods.First(IsOnEntryMethod);
            var exit    = tuple.Item2.Methods.First(IsOnExitMethod);
            foreach (var x in methods)
            {
                decorator.Decorate(x.TypeDefinition, x.MethodDefinition, entry, exit);
            }
        }
    }
Beispiel #2
0
    public void Execute()
    {
        this.LogInfo    = s => { };
        this.LogWarning = s => { };

        var            decorator  = new EntryExitDecorator.Fody.MethodDecorator(this.ModuleDefinition);
        TypeDefinition idecorator = null;

        foreach (var x in this.ModuleDefinition.AssemblyReferences)
        {
            var def = AssemblyResolver.Resolve(x);
            if (def != null && def.Name.Name == "EntryExitDecoratorInterfaces")
            {
                idecorator = def.MainModule.Types.First(t => t.Name == "IEntryExitDecorator");
            }
        }

        if (idecorator == null)
        {
            LogError("Could not find IEntryExitDecorator");
        }
        this.DecorateDirectlyAttributed(decorator, idecorator);
    }