<commit_before>﻿using System;
using System.Collections.Generic;

using Mono.Cecil;

using System.Linq;

using MethodDecorator.Fody;

public class ModuleWeaver
{
    public ModuleDefinition ModuleDefinition { get; set; }
    public IAssemblyResolver AssemblyResolver { get; set; }
    public Action<string> LogInfo { get; set; }
    public Action<string> LogWarning { get; set; }

    public void Execute()
    {
        LogInfo = s => { };
        LogWarning = s => { };

        var markerTypeDefinitions = FindMarkerTypes();

        var decorator = new MethodDecorator.Fody.MethodDecorator(ModuleDefinition);

        var methods = FindAttributedMethods(markerTypeDefinitions);
        foreach (var method in methods)
            decorator.Decorate(method.Item1, method.Item2);
    }

    private IList<TypeDefinition> FindMarkerTypes()
    {
        var markerTypeDefinitions = (from type in ModuleDefinition.Types
                                     where type.FullName == "IMethodDecorator" || type.FullName == "MethodDecoratorAttribute"
                                     select type).ToList();

        if (!markerTypeDefinitions.Any())
            throw new WeavingException("Could not find type 'IMethodDecorator' or 'MethodDecoratorAttribute'");

        if (!markerTypeDefinitions.Any(HasCorrectMethods))
            throw new WeavingException("IMethodDecorator does not contain correct OnEntry, OnExit and OnException methods");
<commit_msg>added more descriptive error message if marker types are not in global namespace<commit_after>﻿using System;
using System.Collections.Generic;

using Mono.Cecil;

using System.Linq;

using MethodDecorator.Fody;

public class ModuleWeaver
{
    public ModuleDefinition ModuleDefinition { get; set; }
    public IAssemblyResolver AssemblyResolver { get; set; }
    public Action<string> LogInfo { get; set; }
    public Action<string> LogWarning { get; set; }

    public void Execute()
    {
        LogInfo = s => { };
        LogWarning = s => { };

        var markerTypeDefinitions = FindMarkerTypes();

        var decorator = new MethodDecorator.Fody.MethodDecorator(ModuleDefinition);

        var methods = FindAttributedMethods(markerTypeDefinitions);
        foreach (var method in methods)
            decorator.Decorate(method.Item1, method.Item2);
    }

    private IList<TypeDefinition> FindMarkerTypes()
    {
        var markerTypeDefinitions = (from type in ModuleDefinition.Types
                                     where type.FullName == "IMethodDecorator" || type.FullName == "MethodDecoratorAttribute"
                                     select type).ToList();

        if (!markerTypeDefinitions.Any())
        {
            var markerTypeDefinitionsAll = (from type in ModuleDefinition.Types
                                            where type.Name == "IMethodDecorator" || type.Name == "MethodDecoratorAttribute"
                                            select type).ToList();
            if(markerTypeDefinitionsAll.Any())
                throw new WeavingException("Could not find type 'IMethodDecorator' or 'MethodDecoratorAttribute' (must be in the global namespace)");
            throw new WeavingException("Could not find type 'IMethodDecorator' or 'MethodDecoratorAttribute'");
        }

        if (!markerTypeDefinitions.Any(HasCorrectMethods))
            throw new WeavingException("IMethodDecorator does not contain correct OnEntry, OnExit and OnException methods");

{'fraction_non_alphanumeric': 0.08357348703170028, 'fraction_numerical': 0.0011527377521613833, 'mean_word_length': 2.704375667022412, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '912520', 'n_tokens_mistral': 888, 'n_tokens_neox': 851, 'n_words': 237}