Exemple #1
0
		public MetricsReader(string fileName)
		{
			loader = new CecilLoader(true) { IncludeInternalMembers = true };
			namespaceMappings = new Dictionary<string, NamespaceNode>();
			typeMappings = new Dictionary<ITypeDefinition, TypeNode>();
			methodMappings = new Dictionary<IMethod, MethodNode>();
			fieldMappings = new Dictionary<IField, FieldNode>();
			cecilMappings = new Dictionary<MemberReference, IEntity>();
			
			compilation = new SimpleCompilation(loader.LoadAssemblyFile(fileName));
			
			// TODO load referenced assemblies into compilation.
			
			Assembly = new AssemblyNode(compilation.MainAssembly.AssemblyName);
			assemblyDefinition = loader.GetCecilObject(compilation.MainAssembly.UnresolvedAssembly);
			
			foreach (var type in compilation.MainAssembly.GetAllTypeDefinitions()) {
				ReadType(type);
				
				foreach (IMethod method in type.Methods) {
					ReadMethod(method);
				}
				
				foreach (IProperty property in type.Properties) {
					if (property.CanGet)
						ReadMethod(property.Getter);
					if (property.CanSet)
						ReadMethod(property.Setter);
				}
				
				foreach (IField field in type.Fields) {
					ReadField(field);
				}
			}
			
			foreach (var method in methodMappings.Values) {
				ReadInstructions(method, method.Method, loader.GetCecilObject((IUnresolvedMethod)method.Method.UnresolvedMember));
			}
			
			Assembly.namespaces = namespaceMappings.Values;
		}