PageRenderTime 143ms CodeModel.GetById 62ms app.highlight 10ms RepoModel.GetById 69ms app.codeStats 0ms

/src/LinFu.AOP/BaseReflectionVisitor.cs

http://github.com/philiplaureano/LinFu
C# | 216 lines | 159 code | 48 blank | 9 comment | 0 complexity | eb8ec16952587c239006c4dd896b4935 MD5 | raw file
  1using System.Collections.Generic;
  2using Mono.Cecil;
  3using Mono.Cecil.Rocks;
  4using LinFu.AOP.Interfaces;
  5
  6#pragma warning disable 1591
  7
  8namespace LinFu.AOP.Cecil
  9{
 10    public abstract class BaseReflectionVisitor 
 11    {
 12        public virtual void TerminateAssemblyDefinition(AssemblyDefinition asm)
 13        {
 14        }
 15
 16        public virtual void VisitAssemblyDefinition(AssemblyDefinition asm)
 17        {
 18            VisitCustomAttributeCollection(asm.CustomAttributes);
 19            VisitModuleDefinitionCollection(asm.Modules);
 20
 21            TerminateAssemblyDefinition(asm);
 22        }
 23
 24        public virtual void VisitAssemblyNameReferenceCollection(IEnumerable<AssemblyNameReference> names)
 25        {
 26            foreach (AssemblyNameReference nameRef in names) VisitAssemblyNameReference(nameRef);
 27        }
 28
 29        public virtual void VisitAssemblyNameReference(AssemblyNameReference nameRef)   
 30        {
 31        }
 32
 33        public virtual void VisitModuleDefinitionCollection(IEnumerable<ModuleDefinition> modules)
 34        {
 35            foreach (ModuleDefinition module in modules) VisitModuleDefinition(module);
 36        }
 37
 38        public virtual void VisitModuleReferenceCollection(IEnumerable<ModuleReference> modules)
 39        {
 40            foreach (ModuleReference module in modules) VisitModuleReference(module);
 41        }           
 42
 43        public virtual void VisitTypeDefinition(TypeDefinition type)
 44        {
 45            // Visit the interfaces
 46            VisitInterfaceCollection(type.Interfaces);
 47
 48            // Visit the constructors
 49            VisitConstructorCollection(type.GetConstructors());
 50
 51            // Visit the fields
 52            VisitFieldDefinitionCollection(type.Fields);
 53
 54            // Visit the methods
 55            VisitMethodDefinitionCollection(type.Methods);
 56
 57            // Visit the properties
 58            VisitPropertyDefinitionCollection(type.Properties);
 59
 60            // Visit the events
 61            VisitEventDefinitionCollection(type.Events);
 62        }
 63
 64        public virtual void VisitConstructorCollection(IEnumerable<MethodDefinition> ctors)
 65        {
 66            foreach (MethodDefinition ctor in ctors) VisitConstructor(ctor);
 67        }
 68
 69        public virtual void VisitCustomAttributeCollection(IEnumerable<CustomAttribute> customAttrs)
 70        {
 71            foreach (CustomAttribute ca in customAttrs) VisitCustomAttribute(ca);
 72        }
 73
 74        private void VisitCustomAttribute(CustomAttribute ca)
 75        {
 76            throw new System.NotImplementedException();
 77        }
 78    
 79        public virtual void VisitEventDefinitionCollection(IEnumerable<EventDefinition> events)
 80        {
 81            foreach (EventDefinition eventDef in events) VisitEventDefinition(eventDef);
 82        }        
 83
 84        public virtual void VisitFieldDefinitionCollection(IEnumerable<FieldDefinition> fields)
 85        {
 86            foreach (FieldDefinition field in fields) VisitFieldDefinition(field);
 87        }
 88
 89        public virtual void VisitGenericParameterCollection(IEnumerable<GenericParameter> genparams)
 90        {
 91            foreach (GenericParameter param in genparams) VisitGenericParameter(param);
 92        }
 93    
 94        
 95
 96        public virtual void VisitInterfaceCollection(IEnumerable<TypeReference> interfaces)
 97        {
 98            foreach (TypeReference interfaceType in interfaces) VisitInterface(interfaceType);
 99        }        
100
101        public virtual void VisitMemberReferenceCollection(IEnumerable<MemberReference> members)
102        {
103            foreach (MemberReference memberRef in members) VisitMemberReference(memberRef);
104        }        
105
106        public virtual void VisitMethodDefinition(MethodDefinition method)
107        {
108            // Visit the parameters
109            VisitParameterDefinitionCollection(method.Parameters);
110
111            // Visit the generic parameters
112            VisitGenericParameterCollection(method.GenericParameters);
113
114            // Visit the method overrides
115            VisitOverrideCollection(method.Overrides);
116        }
117
118        public virtual void VisitMethodDefinitionCollection(IEnumerable<MethodDefinition> methods)
119        {
120            foreach (MethodDefinition method in methods) 
121                VisitMethodDefinition(method);
122        }
123
124        public virtual void VisitOverrideCollection(IEnumerable<MethodReference> overrides)
125        {
126            foreach (MethodReference method in overrides) 
127                VisitOverride(method);
128        }        
129
130        public virtual void VisitParameterDefinitionCollection(IEnumerable<ParameterDefinition> parameters)
131        {
132            foreach (ParameterDefinition param in parameters) 
133                VisitParameterDefinition(param);
134        }
135
136        public virtual void VisitPropertyDefinitionCollection(IEnumerable<PropertyDefinition> properties)
137        {
138            foreach (PropertyDefinition property in properties) 
139                VisitPropertyDefinition(property);
140        }
141
142        public virtual void VisitTypeDefinitionCollection(IEnumerable<TypeDefinition> types)
143        {
144            foreach (TypeDefinition typeDef in types) 
145                VisitTypeDefinition(typeDef);
146        }
147
148        public virtual void VisitTypeReferenceCollection(IEnumerable<TypeReference> refs)
149        {
150            foreach (TypeReference type in refs) 
151                VisitTypeReference(type);
152        }
153
154
155        public virtual void TerminateModuleDefinition(ModuleDefinition module)
156        {
157            VisitTypeDefinitionCollection(module.Types);
158        }
159
160        public virtual void VisitConstructor(MethodDefinition ctor)
161        {
162        }
163
164        public virtual void VisitModuleDefinition(ModuleDefinition module)
165        {
166            VisitCustomAttributeCollection(module.CustomAttributes);
167            VisitAssemblyNameReferenceCollection(module.AssemblyReferences);
168            VisitModuleReferenceCollection(module.ModuleReferences);
169            VisitMemberReferenceCollection(module.GetMemberReferences());
170            VisitTypeReferenceCollection(module.GetTypeReferences());
171            TerminateModuleDefinition(module);
172        }
173
174        public virtual void VisitPropertyDefinition(PropertyDefinition property)
175        {
176        }
177
178        public virtual void VisitModuleReference(ModuleReference module)
179        {
180        }
181        
182        public virtual void VisitEventDefinition(EventDefinition eventDef)
183        {
184        }
185        
186        public virtual void VisitFieldDefinition(FieldDefinition field)
187        {
188        }
189        
190        public virtual void VisitGenericParameter(GenericParameter genericParameter)
191        {
192        }
193
194        public virtual void VisitInterface(TypeReference interfaceType)
195        {
196        }
197        
198        public virtual void VisitMemberReference(MemberReference memberRef)
199        {
200        }
201        
202        public virtual void VisitOverride(MethodReference method)
203        {
204        }
205        
206        public virtual void VisitParameterDefinition(ParameterDefinition parameterDefinition)
207        {            
208        }
209        
210        public virtual void VisitTypeReference(TypeReference type)
211        {
212        }
213    }
214}
215
216#pragma warning restore 1591