private bool WeaveMethod(
            ModuleDefinition module,
            MethodDefinition method,
            List <AspectInfo> aspectInfos)
        {
            aspectInfos = AspectOrderer.Order(aspectInfos);
            var aspectInfosWithMethods = aspectInfos
                                         .Where(x => !x.SkipProperties || (!method.IsGetter && !method.IsSetter))
                                         .ToList();

            var methodWeaver = new MethodWeaver();

            methodWeaver.Weave(module, method, aspectInfosWithMethods);
            if (methodWeaver.WeaveCounter == 0)
            {
                return(false);
            }

            if (method.IsGetter || method.IsSetter)
            {
                TotalWeavedProperties++;
            }
            else
            {
                TotalWeavedMethods++;
            }

            return(true);
        }
        private bool WeaveMethod(
            ModuleDefinition module,
            MethodDefinition method,
            List <AspectInfo> aspectInfos,
            TypeReference type)
        {
            aspectInfos = AspectOrderer.Order(aspectInfos);
            aspectInfos.Reverse(); // last aspect has to be weaved in first

            using (var methodWeaver = new MethodWeaver())
            {
                foreach (var aspectInfo in aspectInfos)
                {
                    ////var log = string.Format("Weave OnMethodBoundaryAspect '{0}' in method '{1}' from class '{2}'",
                    ////    attributeTypeDefinition.Name,
                    ////    method.Name,
                    ////    method.DeclaringType.FullName);
                    ////LogWarning(log);

                    if (aspectInfo.SkipProperties && (method.IsGetter || method.IsSetter))
                    {
                        continue;
                    }

                    var aspectTypeDefinition = aspectInfo.AspectAttribute.AttributeType;

                    var overriddenAspectMethods = GetUsedAspectMethods(aspectTypeDefinition);
                    if (overriddenAspectMethods == AspectMethods.None)
                    {
                        continue;
                    }

                    methodWeaver.Weave(method, aspectInfo.AspectAttribute, overriddenAspectMethods, module, type, UnweavedAssembly);
                }

                if (methodWeaver.WeaveCounter == 0)
                {
                    return(false);
                }
            }

            if (method.IsGetter || method.IsSetter)
            {
                TotalWeavedPropertyMethods++;
            }
            else
            {
                TotalWeavedMethods++;
            }

            LastWeavedMethod = method;
            return(true);
        }
        private void Execute(ModuleDefinition module)
        {
            var assemblyMethodBoundaryAspects = module.Assembly.CustomAttributes;

            foreach (var type in module.Types)
            {
                var classMethodBoundaryAspects = type.CustomAttributes;

                var weavedAtLeastOneMethod = false;
                foreach (var method in type.Methods.Where(IsWeavableMethod))
                {
                    var methodMethodBoundaryAspects = method.CustomAttributes;

                    if (method.IsGetter || method.IsSetter)
                    {
                        var propertyNameParts = method.Name.Split(new[] { '_' });
                        var propertyName = string.Join("_", propertyNameParts.Skip(1));
                        var propertyDefinition = type.Properties.Single(x => x.Name == propertyName);
                        methodMethodBoundaryAspects = propertyDefinition.CustomAttributes;
                    }

                    var aspectInfos = assemblyMethodBoundaryAspects
                        .Concat(classMethodBoundaryAspects)
                        .Concat(methodMethodBoundaryAspects)
                        .Where(IsMethodBoundaryAspect)
                        .Select(x => new AspectInfo(x))
                        .ToList();

                    if (aspectInfos.Count == 0)
                        continue;

                    aspectInfos = AspectOrderer.Order(aspectInfos);
                    aspectInfos.Reverse(); // last aspect has to be weaved in first

                    using (var methodWeaver = new MethodWeaver())
                    {
                        foreach (var aspectInfo in aspectInfos)
                        {
                            ////var log = string.Format("Weave OnMethodBoundaryAspect '{0}' in method '{1}' from class '{2}'",
                            ////    attributeTypeDefinition.Name,
                            ////    method.Name,
                            ////    method.DeclaringType.FullName);
                            ////LogWarning(log);

                            if (aspectInfo.SkipProperties && (method.IsGetter || method.IsSetter))
                                continue;

                            var aspectTypeDefinition = aspectInfo.AspectAttribute.AttributeType;

                            var overriddenAspectMethods = GetUsedAspectMethods(aspectTypeDefinition);
                            if (overriddenAspectMethods == AspectMethods.None)
                                continue;

                            methodWeaver.Weave(method, aspectInfo.AspectAttribute, overriddenAspectMethods, module);
                        }

                        if (methodWeaver.WeaveCounter == 0)
                            continue;
                    }

                    weavedAtLeastOneMethod = true;

                    if (method.IsGetter || method.IsSetter)
                        TotalWeavedPropertyMethods++;
                    else
                        TotalWeavedMethods++;

                    LastWeavedMethod = method;
                }

                if (weavedAtLeastOneMethod)
                    TotalWeavedTypes++;
            }
        }
        private bool WeaveMethod(
            ModuleDefinition module, 
            MethodDefinition method,
            List<AspectInfo> aspectInfos)
        {
            aspectInfos = AspectOrderer.Order(aspectInfos);
            aspectInfos.Reverse(); // last aspect has to be weaved in first

            using (var methodWeaver = new MethodWeaver())
            {
                foreach (var aspectInfo in aspectInfos)
                {
                    ////var log = string.Format("Weave OnMethodBoundaryAspect '{0}' in method '{1}' from class '{2}'",
                    ////    attributeTypeDefinition.Name,
                    ////    method.Name,
                    ////    method.DeclaringType.FullName);
                    ////LogWarning(log);

                    if (aspectInfo.SkipProperties && (method.IsGetter || method.IsSetter))
                        continue;

                    var aspectTypeDefinition = aspectInfo.AspectAttribute.AttributeType;

                    var overriddenAspectMethods = GetUsedAspectMethods(aspectTypeDefinition);
                    if (overriddenAspectMethods == AspectMethods.None)
                        continue;

                    methodWeaver.Weave(method, aspectInfo.AspectAttribute, overriddenAspectMethods, module);
                }

                if (methodWeaver.WeaveCounter == 0)
                    return false;
            }

            if (method.IsGetter || method.IsSetter)
                TotalWeavedPropertyMethods++;
            else
                TotalWeavedMethods++;

            LastWeavedMethod = method;
            return true;
        }