Пример #1
0
        private bool ShouldWeaveProperty(PropertyDefinition property)
        {
            CustomAttribute classLevelCacheAttribute =
                property.DeclaringType.CustomAttributes.SingleOrDefault(x => x.Constructor.DeclaringType.Name == CacheAttributeName);

            bool hasClassLevelCache    = classLevelCacheAttribute != null;
            bool hasPropertyLevelCache = property.ContainsAttribute(CacheAttributeName);
            bool hasNoCacheAttribute   = property.ContainsAttribute(NoCacheAttributeName);
            bool isCacheGetter         = property.Name == CacheGetterName;
            bool hasGetAccessor        = property.GetMethod != null;
            bool isAutoProperty        = hasGetAccessor && property.GetMethod.ContainsAttribute(References.CompilerGeneratedAttribute);

            if (hasNoCacheAttribute || isCacheGetter || isAutoProperty || !hasGetAccessor)
            {
                // Never weave Cache property, auto-properties, write-only properties and properties explicitly excluded
                return(false);
            }

            if (hasPropertyLevelCache)
            {
                // Always weave properties explicitly marked for cache
                return(true);
            }

            if (hasClassLevelCache && !CacheAttributeExcludesProperties(classLevelCacheAttribute))
            {
                // Otherwise weave if marked at class level
                return(PropertyCacheEnabledByDefault ||
                       CacheAttributeMembersExplicitly(classLevelCacheAttribute, Members.Properties));
            }

            return(false);
        }
Пример #2
0
        private static bool ShouldWeaveProperty(PropertyDefinition property)
        {
            CustomAttribute classLevelCacheAttribute = property.DeclaringType.GetCacheAttribute(CacheAttributeName);

            bool hasClassLevelCache    = classLevelCacheAttribute != null;
            bool hasPropertyLevelCache = property.ContainsAttribute(CacheAttributeName);
            bool hasNoCacheAttribute   = property.ContainsAttribute(NoCacheAttributeName);
            bool isCacheGetter         = property.Name == CacheGetterName;
            bool hasGetAccessor        = property.GetMethod != null;
            bool isAutoProperty        = hasGetAccessor && property.GetMethod.ContainsAttribute(CompilerGeneratedAttributeName);

            if (hasNoCacheAttribute || isCacheGetter || isAutoProperty || !hasGetAccessor)
            {
                // Never weave Cache property, auto-properties, write-only properties and properties explicitly excluded
                return(false);
            }

            if (hasPropertyLevelCache)
            {
                // Always weave properties explicitly marked for cache
                return(true);
            }

            if (hasClassLevelCache)
            {
                // Otherwise weave if marked at class level
                return(true);
            }

            return(false);
        }