private static bool CheckCacheTypeMethods(BaseModuleWeaver weaver, TypeDefinition cacheType) { weaver.LogInfo(string.Format("Checking CacheType methods ({0}, {1}, {2}).", CacheTypeContainsMethodName, CacheTypeStoreMethodName, CacheTypeRetrieveMethodName)); if (CacheTypeGetContainsMethod(cacheType, CacheTypeContainsMethodName) == null) { weaver.LogWarning(string.Format("Method {0} missing in {1}.", CacheTypeContainsMethodName, cacheType.FullName)); return(false); } if (CacheTypeGetStoreMethod(cacheType, CacheTypeStoreMethodName) == null) { weaver.LogWarning(string.Format("Method {0} missing in {1}.", CacheTypeStoreMethodName, cacheType.FullName)); return(false); } if (CacheTypeGetRetrieveMethod(cacheType, CacheTypeRetrieveMethodName) == null) { weaver.LogWarning(string.Format("Method {0} missing in {1}.", CacheTypeRetrieveMethodName, cacheType.FullName)); return(false); } weaver.LogInfo(string.Format("CacheInterface methods found.")); return(true); }
public static void Weave(BaseModuleWeaver weaver, IEnumerable <Tuple <PropertyDefinition, CustomAttribute> > properties) { foreach (Tuple <PropertyDefinition, CustomAttribute> propertyTuple in properties) { PropertyDefinition property = propertyTuple.Item1; CustomAttribute attribute = propertyTuple.Item2; // Get-Only Property, weave like normal methods if (property.SetMethod == null) { WeaveMethod(weaver, property.GetMethod, attribute); } else { MethodDefinition propertyGet = GetCacheGetter(property.SetMethod); if (!IsPropertySetterValidForWeaving(weaver, propertyGet, property.SetMethod)) { continue; } weaver.LogInfo(string.Format("Weaving property {0}::{1}.", property.DeclaringType.Name, property.Name)); WeaveMethod(weaver, property.GetMethod, attribute, propertyGet); WeavePropertySetter(weaver, property.SetMethod, propertyGet); } } }
public static MethodsForWeaving GetWeaveMethods(BaseModuleWeaver weaver) { weaver.LogInfo(string.Format("Searching for Methods and Properties in assembly ({0}).", weaver.ModuleDefinition.Name)); MethodsForWeaving result = new MethodsForWeaving(); foreach (TypeDefinition type in weaver.ModuleDefinition.Types) { foreach (MethodDefinition method in type.Methods) { if (ShouldWeaveMethod(method)) { // Store Cache attribute, method attribute takes precedence over class attributes CustomAttribute attribute = method.CustomAttributes.SingleOrDefault(x => x.Constructor.DeclaringType.Name == CacheAttributeName) ?? method.DeclaringType.CustomAttributes.SingleOrDefault( x => x.Constructor.DeclaringType.Name == CacheAttributeName); result.Add(method, attribute); } method.RemoveCacheAttribute(CacheAttributeName); method.RemoveCacheAttribute(NoCacheAttributeName); } //TODO:for now we don't support property cache //foreach (PropertyDefinition property in type.Properties) //{ // if (ShouldWeaveProperty(property)) // { // // Store Cache attribute, property attribute takes precedence over class attributes // CustomAttribute attribute = // property.CustomAttributes.SingleOrDefault(x => x.Constructor.DeclaringType.Name == CacheAttributeName) ?? // property.DeclaringType.CustomAttributes.SingleOrDefault( // x => x.Constructor.DeclaringType.Name == CacheAttributeName); // result.Add(property, attribute); // } // property.RemoveCacheAttribute(CacheAttributeName); // property.RemoveCacheAttribute(NoCacheAttributeName); //} type.RemoveCacheAttribute(CacheAttributeName); type.RemoveCacheAttribute(NoCacheAttributeName); } return(result); }
public static void WeaveMethod(BaseModuleWeaver weaver, MethodDefinition methodDefinition, CustomAttribute attribute) { MethodDefinition propertyGet = GetCacheGetter(methodDefinition); if (!IsMethodValidForWeaving(weaver, propertyGet, methodDefinition)) { return; } if (methodDefinition.ReturnType == methodDefinition.Module.TypeSystem.Void) { weaver.LogWarning(string.Format("Method {0} returns void. Skip weaving of method {0}.", methodDefinition.Name)); return; } weaver.LogInfo(string.Format("Weaving method {0}::{1}.", methodDefinition.DeclaringType.Name, methodDefinition.Name)); WeaveMethod(weaver, methodDefinition, attribute, propertyGet); }
public void Execute(ModuleDefinition module, bool optimize = false) { _weaver.LogInfo($"AopModuleWeaver execute for {module}"); ProcessModule(module, optimize); }