コード例 #1
0
        private MethodsForWeaving SelectMethods()
        {
            LogInfo(string.Format("Searching for Methods and Properties in assembly ({0}).", ModuleDefinition.Name));

            MethodsForWeaving result = new MethodsForWeaving();

            foreach (TypeDefinition type in ModuleDefinition.Types)
            {
                foreach (MethodDefinition method in type.Methods)
                {
                    if (ShouldWeaveMethod(method))
                    {
                        result.Add(method);
                    }

                    method.RemoveAttribute(CacheAttributeName);
                    method.RemoveAttribute(NoCacheAttributeName);
                }

                foreach (PropertyDefinition property in type.Properties)
                {
                    if (ShouldWeaveProperty(property))
                    {
                        result.Add(property);
                    }

                    property.RemoveAttribute(CacheAttributeName);
                    property.RemoveAttribute(NoCacheAttributeName);
                }

                type.RemoveAttribute(CacheAttributeName);
            }

            return(result);
        }
コード例 #2
0
ファイル: ModuleWeaver.cs プロジェクト: xavier393/MethodCache
        private MethodsForWeaving SelectMethods()
        {
            LogInfo(string.Format("Searching for Methods and Properties in assembly ({0}).", ModuleDefinition.Name));

            MethodsForWeaving result = new MethodsForWeaving();

            foreach (TypeDefinition type in 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.RemoveAttribute(CacheAttributeName);
                    method.RemoveAttribute(NoCacheAttributeName);
                }

                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.RemoveAttribute(CacheAttributeName);
                    property.RemoveAttribute(NoCacheAttributeName);
                }

                type.RemoveAttribute(CacheAttributeName);
            }

            return(result);
        }
コード例 #3
0
        private MethodsForWeaving SelectMethods()
        {
            LogInfo(string.Format("Searching for Methods and Properties in assembly ({0}).", ModuleDefinition.Name));

            MethodsForWeaving result = new MethodsForWeaving();

            foreach (TypeDefinition type in ModuleDefinition.Types)
            {
                foreach (MethodDefinition method in type.Methods)
                {
                    if (ShouldWeaveMethod(method))
                    {
                        result.Add(method);
                    }

                    method.RemoveAttribute(CacheAttributeName);
                    method.RemoveAttribute(NoCacheAttributeName);
                }

                foreach (PropertyDefinition property in type.Properties)
                {
                    if (ShouldWeaveProperty(property))
                    {
                        result.Add(property);
                    }

                    property.RemoveAttribute(CacheAttributeName);
                    property.RemoveAttribute(NoCacheAttributeName);
                }

                type.RemoveAttribute(CacheAttributeName);
            }

            return result;
        }