Esempio n. 1
0
		public ReadOnlyCollection<AssemblyNode> Analyze()
		{
			IUnresolvedAssembly[] loadedAssemblies = LoadAssemblies().ToArray();
			compilation = new SimpleCompilation(loadedAssemblies.First(), loadedAssemblies.Skip(1));
			
			assemblyMappings = new Dictionary<IAssembly, AssemblyNode>();
			namespaceMappings = new Dictionary<string, NamespaceNode>();
			typeMappings = new Dictionary<ITypeDefinition, TypeNode>();
			fieldMappings = new Dictionary<IField, FieldNode>();
			methodMappings = new Dictionary<IMethod, MethodNode>();
			propertyMappings = new Dictionary<IProperty, PropertyNode>();
			eventMappings = new Dictionary<IEvent, EventNode>();
			cecilMappings = new Dictionary<MemberReference, IEntity>();
			
			// first we have to read all types so every method, field or property has a container
			foreach (var type in compilation.GetAllTypeDefinitions()) {
				var tn = ReadType(type);
				
				foreach (var field in type.Fields) {
					var node = new FieldNode(field);
					fieldMappings.Add(field, node);
					var cecilObj = loader.GetCecilObject((IUnresolvedField)field.UnresolvedMember);
					if (cecilObj != null)
						cecilMappings[cecilObj] = field;
					tn.AddChild(node);
				}
				
				foreach (var method in type.Methods) {
					var node = new MethodNode(method);
					methodMappings.Add(method, node);
					var cecilObj = loader.GetCecilObject((IUnresolvedMethod)method.UnresolvedMember);
					if (cecilObj != null)
						cecilMappings[cecilObj] = method;
					tn.AddChild(node);
				}
				
				foreach (var property in type.Properties) {
					var node = new PropertyNode(property);
					propertyMappings.Add(property, node);
					var cecilPropObj = loader.GetCecilObject((IUnresolvedProperty)property.UnresolvedMember);
					if (cecilPropObj != null)
						cecilMappings[cecilPropObj] = property;
					if (property.CanGet) {
						var cecilMethodObj = loader.GetCecilObject((IUnresolvedMethod)property.Getter.UnresolvedMember);
						if (cecilMethodObj != null)
							cecilMappings[cecilMethodObj] = property;
					}
					if (property.CanSet) {
						var cecilMethodObj = loader.GetCecilObject((IUnresolvedMethod)property.Setter.UnresolvedMember);
						if (cecilMethodObj != null)
							cecilMappings[cecilMethodObj] = property;
					}
					tn.AddChild(node);
				}
				
				foreach (var @event in type.Events) {
					var node = new EventNode(@event);
					eventMappings.Add(@event, node);
					var cecilObj = loader.GetCecilObject((IUnresolvedEvent)@event.UnresolvedMember);
					if (cecilObj != null)
						cecilMappings[cecilObj] = @event;
					if (@event.CanAdd) {
						var cecilMethodObj = loader.GetCecilObject((IUnresolvedMethod)@event.AddAccessor.UnresolvedMember);
						if (cecilMethodObj != null)
							cecilMappings[cecilMethodObj] = @event;
					}
					if (@event.CanInvoke) {
						var cecilMethodObj = loader.GetCecilObject((IUnresolvedMethod)@event.InvokeAccessor.UnresolvedMember);
						if (cecilMethodObj != null)
							cecilMappings[cecilMethodObj] = @event;
					}
					if (@event.CanRemove) {
						var cecilMethodObj = loader.GetCecilObject((IUnresolvedMethod)@event.RemoveAccessor.UnresolvedMember);
						if (cecilMethodObj != null)
							cecilMappings[cecilMethodObj] = @event;
					}
					tn.AddChild(node);
				}
			}
			
			ILAnalyzer analyzer = new ILAnalyzer(loadedAssemblies.Select(asm => loader.GetCecilObject(asm)).ToArray(), this);
			int count = typeMappings.Count + methodMappings.Count + fieldMappings.Count + propertyMappings.Count;
			int i  = 0;
			
			foreach (var element in typeMappings) {
				ReportProgress(++i / (double)count);
				AddRelationshipsForTypes(element.Key.DirectBaseTypes, element.Value);
				AddRelationshipsForAttributes(element.Key.Attributes, element.Value);
				CreateEdges(element.Value);
			}
			
			foreach (var element in methodMappings) {
				ReportProgress(++i / (double)count);
				var cecilObj = loader.GetCecilObject((IUnresolvedMethod)element.Key.UnresolvedMember);
				if (cecilObj != null)
					analyzer.Analyze(cecilObj.Body, element.Value);
				var node = element.Value;
				var method = element.Key;
				AddRelationshipsForType(node, method.ReturnType);
				AddRelationshipsForAttributes(method.Attributes, node);
				AddRelationshipsForAttributes(method.ReturnTypeAttributes, node);
				AddRelationshipsForTypeParameters(method.TypeParameters, node);
				foreach (var param in method.Parameters) {
					AddRelationshipsForType(node, param.Type);
					AddRelationshipsForAttributes(param.Attributes, node);
				}
				CreateEdges(element.Value);
			}
			
			foreach (var element in fieldMappings) {
				ReportProgress(++i / (double)count);
				var node = element.Value;
				var field = element.Key;
				AddRelationshipsForType(node, field.Type);
				AddRelationshipsForAttributes(field.Attributes, node);
				CreateEdges(element.Value);
			}
			
			foreach (var element in propertyMappings) {
				ReportProgress(++i / (double)count);
				var node = element.Value;
				var property = element.Key;
				if (property.CanGet) {
					var cecilObj = loader.GetCecilObject((IUnresolvedMethod)element.Key.Getter.UnresolvedMember);
					if (cecilObj != null)
						analyzer.Analyze(cecilObj.Body, node);
				}
				if (property.CanSet) {
					var cecilObj = loader.GetCecilObject((IUnresolvedMethod)element.Key.Setter.UnresolvedMember);
					if (cecilObj != null)
						analyzer.Analyze(cecilObj.Body, node);
				}
				AddRelationshipsForType(node, property.ReturnType);
				AddRelationshipsForAttributes(property.Attributes, node);
				CreateEdges(element.Value);
			}
			
			foreach (var element in eventMappings) {
				ReportProgress(++i / (double)count);
				var node = element.Value;
				var @event = element.Key;
				if (@event.CanAdd) {
					var cecilObj = loader.GetCecilObject((IUnresolvedMethod)@event.AddAccessor.UnresolvedMember);
					if (cecilObj != null)
						analyzer.Analyze(cecilObj.Body, node);
				}
				if (@event.CanInvoke) {
					var cecilObj = loader.GetCecilObject((IUnresolvedMethod)@event.InvokeAccessor.UnresolvedMember);
					if (cecilObj != null)
						analyzer.Analyze(cecilObj.Body, node);
				}
				if (@event.CanRemove) {
					var cecilObj = loader.GetCecilObject((IUnresolvedMethod)@event.RemoveAccessor.UnresolvedMember);
					if (cecilObj != null)
						analyzer.Analyze(cecilObj.Body, node);
				}
				AddRelationshipsForType(node, @event.ReturnType);
				AddRelationshipsForAttributes(@event.Attributes, node);
				CreateEdges(element.Value);
			}
			
			return new ReadOnlyCollection<AssemblyNode>(assemblyMappings.Values.ToList());
		}
Esempio n. 2
0
		public static BitmapSource GetIcon(MethodNode method)
		{
//			if (method.Method.IsPrivate)
//				return PrivateMethod;
//			if (method.Method.IsProtected)
//				return ProtectedMethod;

//			if (method.IsGetter || method.IsSetter)
//			{
//				if (method.IsPublic)
//					return PropertyMethod;
//				if (method.IsPrivate)
//					return PrivatePropertyMethod;
//				if (method.IsProtected)
//					return ProtectedPropertyMethod;
//			}

			return MethodNode;
		}