PageRenderTime 134ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/src/LinFu.AOP/BaseReflectionVisitor.cs

http://linfu.googlecode.com/
C# | 315 lines | 260 code | 43 blank | 12 comment | 0 complexity | 0dedab159018b61df2a57913a86b8b37 MD5 | raw file
Possible License(s): LGPL-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Mono.Cecil;
  6. #pragma warning disable 1591
  7. namespace LinFu.AOP.Cecil
  8. {
  9. public abstract class BaseReflectionVisitor : IReflectionVisitor, IReflectionStructureVisitor
  10. {
  11. public virtual void TerminateModuleDefinition(ModuleDefinition module)
  12. {
  13. VisitTypeDefinitionCollection(module.Types);
  14. }
  15. public virtual void VisitConstructor(MethodDefinition ctor)
  16. {
  17. }
  18. public virtual void VisitCustomAttribute(CustomAttribute customAttr)
  19. {
  20. }
  21. public virtual void VisitEventDefinition(EventDefinition evt)
  22. {
  23. }
  24. public virtual void VisitExternType(TypeReference externType)
  25. {
  26. }
  27. public virtual void VisitFieldDefinition(FieldDefinition field)
  28. {
  29. }
  30. public virtual void VisitGenericParameter(GenericParameter genparam)
  31. {
  32. }
  33. public virtual void VisitInterface(TypeReference interf)
  34. {
  35. }
  36. public virtual void VisitMarshalSpec(MarshalSpec marshalSpec)
  37. {
  38. }
  39. public virtual void VisitMemberReference(MemberReference member)
  40. {
  41. }
  42. public virtual void VisitModuleDefinition(ModuleDefinition module)
  43. {
  44. VisitCustomAttributeCollection(module.CustomAttributes);
  45. VisitResourceCollection(module.Resources);
  46. VisitAssemblyNameReferenceCollection(module.AssemblyReferences);
  47. VisitModuleReferenceCollection(module.ModuleReferences);
  48. VisitMemberReferenceCollection(module.MemberReferences);
  49. VisitTypeReferenceCollection(module.TypeReferences);
  50. VisitExternTypeCollection(module.ExternTypes);
  51. TerminateModuleDefinition(module);
  52. }
  53. public virtual void VisitNestedTypeCollection(NestedTypeCollection nestedTypes)
  54. {
  55. foreach (TypeDefinition nestedType in nestedTypes)
  56. {
  57. VisitNestedType(nestedType);
  58. }
  59. }
  60. public virtual void VisitOverride(MethodReference ov)
  61. {
  62. }
  63. public virtual void VisitSecurityDeclaration(SecurityDeclaration secDecl)
  64. {
  65. }
  66. public virtual void VisitPInvokeInfo(PInvokeInfo pinvk)
  67. {
  68. }
  69. public virtual void VisitParameterDefinition(ParameterDefinition parameter)
  70. {
  71. }
  72. public virtual void VisitPropertyDefinition(PropertyDefinition property)
  73. {
  74. }
  75. public virtual void VisitNestedType(TypeDefinition nestedType)
  76. {
  77. }
  78. public virtual void VisitTypeReference(TypeReference type)
  79. {
  80. }
  81. public virtual void TerminateAssemblyDefinition(AssemblyDefinition asm)
  82. {
  83. }
  84. public virtual void VisitAssemblyDefinition(AssemblyDefinition asm)
  85. {
  86. VisitCustomAttributeCollection(asm.CustomAttributes);
  87. VisitModuleDefinitionCollection(asm.Modules);
  88. VisitSecurityDeclarationCollection(asm.SecurityDeclarations);
  89. TerminateAssemblyDefinition(asm);
  90. }
  91. public virtual void VisitAssemblyLinkedResource(AssemblyLinkedResource res)
  92. {
  93. }
  94. public virtual void VisitAssemblyNameDefinition(AssemblyNameDefinition name)
  95. {
  96. }
  97. public virtual void VisitAssemblyNameReference(AssemblyNameReference name)
  98. {
  99. }
  100. public virtual void VisitEmbeddedResource(EmbeddedResource res)
  101. {
  102. }
  103. public virtual void VisitLinkedResource(LinkedResource res)
  104. {
  105. }
  106. public virtual void VisitModuleReference(ModuleReference module)
  107. {
  108. }
  109. #region Collection Visitors
  110. public virtual void VisitTypeDefinition(TypeDefinition type)
  111. {
  112. // Visit the interfaces
  113. VisitInterfaceCollection(type.Interfaces);
  114. // Visit the constructors
  115. VisitConstructorCollection(type.Constructors);
  116. // Visit the fields
  117. VisitFieldDefinitionCollection(type.Fields);
  118. // Visit the methods
  119. VisitMethodDefinitionCollection(type.Methods);
  120. // Visit the properties
  121. VisitPropertyDefinitionCollection(type.Properties);
  122. // Visit the events
  123. VisitEventDefinitionCollection(type.Events);
  124. // Visit the nested types
  125. VisitNestedTypeCollection(type.NestedTypes);
  126. // Visit the security declaration
  127. VisitSecurityDeclarationCollection(type.SecurityDeclarations);
  128. }
  129. public virtual void VisitConstructorCollection(ConstructorCollection ctors)
  130. {
  131. foreach (MethodDefinition ctor in ctors)
  132. {
  133. VisitConstructor(ctor);
  134. }
  135. }
  136. public virtual void VisitCustomAttributeCollection(CustomAttributeCollection customAttrs)
  137. {
  138. foreach (CustomAttribute ca in customAttrs)
  139. {
  140. VisitCustomAttribute(ca);
  141. }
  142. }
  143. public virtual void VisitEventDefinitionCollection(EventDefinitionCollection events)
  144. {
  145. foreach (EventDefinition eventDef in events)
  146. {
  147. VisitEventDefinition(eventDef);
  148. }
  149. }
  150. public virtual void VisitExternTypeCollection(ExternTypeCollection externs)
  151. {
  152. foreach (TypeReference type in externs)
  153. {
  154. VisitExternType(type);
  155. }
  156. }
  157. public virtual void VisitFieldDefinitionCollection(FieldDefinitionCollection fields)
  158. {
  159. foreach (FieldDefinition field in fields)
  160. {
  161. VisitFieldDefinition(field);
  162. }
  163. }
  164. public virtual void VisitGenericParameterCollection(GenericParameterCollection genparams)
  165. {
  166. foreach (GenericParameter param in genparams)
  167. {
  168. VisitGenericParameter(param);
  169. }
  170. }
  171. public virtual void VisitInterfaceCollection(InterfaceCollection interfaces)
  172. {
  173. foreach (TypeReference interfaceType in interfaces)
  174. {
  175. VisitInterface(interfaceType);
  176. }
  177. }
  178. public virtual void VisitMemberReferenceCollection(MemberReferenceCollection members)
  179. {
  180. foreach (MemberReference memberRef in members)
  181. {
  182. VisitMemberReference(memberRef);
  183. }
  184. }
  185. public virtual void VisitMethodDefinition(MethodDefinition method)
  186. {
  187. // Visit the parameters
  188. VisitParameterDefinitionCollection(method.Parameters);
  189. // Visit the generic parameters
  190. VisitGenericParameterCollection(method.GenericParameters);
  191. // Visit the method overrides
  192. VisitOverrideCollection(method.Overrides);
  193. // Visit the security declarations
  194. VisitSecurityDeclarationCollection(method.SecurityDeclarations);
  195. }
  196. public virtual void VisitMethodDefinitionCollection(MethodDefinitionCollection methods)
  197. {
  198. foreach (MethodDefinition method in methods)
  199. {
  200. VisitMethodDefinition(method);
  201. }
  202. }
  203. public virtual void VisitOverrideCollection(OverrideCollection overrides)
  204. {
  205. foreach (MethodReference method in overrides)
  206. {
  207. VisitOverride(method);
  208. }
  209. }
  210. public virtual void VisitParameterDefinitionCollection(ParameterDefinitionCollection parameters)
  211. {
  212. foreach (ParameterDefinition param in parameters)
  213. {
  214. VisitParameterDefinition(param);
  215. }
  216. }
  217. public virtual void VisitPropertyDefinitionCollection(PropertyDefinitionCollection properties)
  218. {
  219. foreach (PropertyDefinition property in properties)
  220. {
  221. VisitPropertyDefinition(property);
  222. }
  223. }
  224. public virtual void VisitSecurityDeclarationCollection(SecurityDeclarationCollection secDecls)
  225. {
  226. foreach (SecurityDeclaration securityDeclaration in secDecls)
  227. {
  228. VisitSecurityDeclaration(securityDeclaration);
  229. }
  230. }
  231. public virtual void VisitTypeDefinitionCollection(TypeDefinitionCollection types)
  232. {
  233. foreach (TypeDefinition typeDef in types)
  234. {
  235. VisitTypeDefinition(typeDef);
  236. }
  237. }
  238. public virtual void VisitTypeReferenceCollection(TypeReferenceCollection refs)
  239. {
  240. foreach (TypeReference type in refs)
  241. {
  242. VisitTypeReference(type);
  243. }
  244. }
  245. public virtual void VisitAssemblyNameReferenceCollection(AssemblyNameReferenceCollection names)
  246. {
  247. foreach (AssemblyNameReference nameRef in names)
  248. {
  249. VisitAssemblyNameReference(nameRef);
  250. }
  251. }
  252. public virtual void VisitModuleDefinitionCollection(ModuleDefinitionCollection modules)
  253. {
  254. foreach (ModuleDefinition module in modules)
  255. {
  256. VisitModuleDefinition(module);
  257. }
  258. }
  259. public virtual void VisitModuleReferenceCollection(ModuleReferenceCollection modules)
  260. {
  261. foreach (ModuleReference module in modules)
  262. {
  263. VisitModuleReference(module);
  264. }
  265. }
  266. public virtual void VisitResourceCollection(ResourceCollection resources)
  267. {
  268. }
  269. #endregion
  270. }
  271. }
  272. #pragma warning restore 1591