@@ -8,6 +8,7 @@ namespace SpatialFocus.MethodCache.Fody
88 using System . Linq ;
99 using global ::Fody ;
1010 using Mono . Cecil ;
11+ using SpatialFocus . MethodCache . Fody . Extensions ;
1112
1213 public partial class ModuleWeaver : BaseModuleWeaver
1314 {
@@ -17,35 +18,34 @@ public override void Execute()
1718 {
1819 References references = Fody . References . Init ( this ) ;
1920
20- // TODO: Extract to method
21- var elementsToCache = ModuleDefinition . Types . Select ( type =>
21+ foreach ( WeavingCandidate weavingCandidate in ModuleDefinition . GetWeavingCandidates ( references ) )
22+ {
23+ if ( weavingCandidate . ClassDefinition . HasCacheAttribute ( references ) && ! weavingCandidate . MethodDefinitions . Any ( x => x . IsEligibleForWeaving ( references ) ) )
2224 {
23- if ( type . HasCacheAttribute ( references ) )
24- {
25- return new { Type = type , Methods = type . Methods . ToList ( ) } ;
26- }
27-
28- return new { Type = type , Methods = type . Methods . Where ( method => method . HasCacheAttribute ( references ) ) . ToList ( ) , } ;
29- } )
30- . Where ( x => x . Methods . Any ( ) )
31- . ToList ( ) ;
25+ WriteWarning ( $ "Class { weavingCandidate . ClassDefinition . Resolve ( ) . FullName } contains [Cache] attribute but does not contain eligible methods for caching") ;
26+ continue ;
27+ }
3228
33- foreach ( var elementToCache in elementsToCache )
34- {
35- if ( ! elementToCache . Type . IsEligibleForWeaving ( references ) )
29+ if ( ! weavingCandidate . ClassDefinition . IsEligibleForWeaving ( references ) )
3630 {
37- // TODO: Create warning
31+ WriteWarning ( $ "Class { weavingCandidate . ClassDefinition . Name } contains [Cache] attribute but does not contain a single non-inherited property implementing IMemoryCache interface" ) ;
3832 continue ;
3933 }
4034
41- ClassWeavingContext classWeavingContext = new ClassWeavingContext ( elementToCache . Type , references ) ;
35+ ClassWeavingContext classWeavingContext = new ClassWeavingContext ( weavingCandidate . ClassDefinition , references ) ;
4236 classWeavingContext . CacheGetterMethod = MemoryCache . GetCacheGetterMethod ( classWeavingContext ) ;
4337
44- foreach ( MethodDefinition methodDefinition in elementToCache . Methods )
38+ foreach ( MethodDefinition methodDefinition in weavingCandidate . MethodDefinitions )
4539 {
4640 if ( ! methodDefinition . IsEligibleForWeaving ( references ) )
4741 {
48- // TODO: Create warning if marked explicit for weaving
42+ // Show warning if test was marked explicitly
43+ if ( methodDefinition . HasCacheAttribute ( references ) )
44+ {
45+ WriteWarning ( $ "Method { methodDefinition . FullName } contains [Cache] attribute but is not eligible for weaving") ;
46+ break ;
47+ }
48+
4949 continue ;
5050 }
5151
0 commit comments