예제 #1
0
        private bool ShouldWeaveMethod(MethodDefinition method)
        {
            CustomAttribute classLevelCacheAttribute =
                method.DeclaringType.CustomAttributes.SingleOrDefault(x => x.Constructor.DeclaringType.Name == CacheAttributeName);

            bool hasClassLevelCache = classLevelCacheAttribute != null &&
                !CacheAttributeExcludesMethods(classLevelCacheAttribute);
            bool hasMethodLevelCache = method.ContainsAttribute(CacheAttributeName);
            bool hasNoCacheAttribute = method.ContainsAttribute(NoCacheAttributeName);
            bool isSpecialName = method.IsSpecialName || method.IsGetter || method.IsSetter || method.IsConstructor;
            bool isCompilerGenerated = method.ContainsAttribute(ModuleDefinition.ImportType<CompilerGeneratedAttribute>());

            if (hasNoCacheAttribute || isSpecialName || isCompilerGenerated)
            {
                // Never weave property accessors, special methods and compiler generated methods
                return false;
            }

            if (hasMethodLevelCache)
            {
                // Always weave methods explicitly marked for cache
                return true;
            }

            if (hasClassLevelCache && !CacheAttributeExcludesMethods(classLevelCacheAttribute))
            {
                // Otherwise weave if marked at class level
                return MethodCacheEnabledByDefault || CacheAttributeMembersExplicitly(classLevelCacheAttribute, Members.Methods);
            }

            return false;
        }
예제 #2
0
 private static bool ValidMethod(ModuleDefinition moduleDefinition, string excludeAttributeName, MethodDefinition x)
 {
     return !x.ContainsAttribute(excludeAttributeName)
            &&
            x.HasBody
            &&
            (
                (
                     !x.IsSpecialName
                     ||
                     x.IsConstructor
                )
                &&
                !x.IsGetter
                &&
                !x.IsSetter
                &&
                !x.ContainsAttribute(moduleDefinition.ImportType<CompilerGeneratedAttribute>())
            );
 }