private List <AssemblyTreeViewModel> GroupAndCreateTree(String assemblyFileName) { AssemblyTreeViewModel root = null; List <AssemblyTreeViewModel> tree = new List <AssemblyTreeViewModel>(); var groupedTypes = from t in assembly.GetTypes() where DotNetObject.IsWantedForDiagramType(t) group t by t.Namespace into g select new { NameSpace = g.Key, Types = g }; foreach (var g in groupedTypes) { if (g.NameSpace != null) { AssemblyTreeViewModel sub = null; AssemblyTreeViewModel parentToAddTo = null; if (tree.Count == 0) { root = new AssemblyTreeViewModel(RepresentationType.AssemblyOrExe, String.Format("Assembly : {0}", assembly.GetName().Name), null, null); tree.Add(root); //Add the types AddTypes(g.Types, root); } else { string trimmedNamespace = g.NameSpace; if (g.NameSpace.Contains(".")) { trimmedNamespace = g.NameSpace.Substring(0, g.NameSpace.LastIndexOf(".")); } if (g.NameSpace.Equals(String.Empty)) { parentToAddTo = root; } else { parentToAddTo = FindCorrectTreeNodeToAddTo(root, trimmedNamespace); } if (parentToAddTo == null) { parentToAddTo = root; } sub = new AssemblyTreeViewModel( RepresentationType.Namespace, g.NameSpace, null, parentToAddTo); parentToAddTo.Children.Add(sub); //add the types AddTypes(g.Types, sub); } } } return(tree); }
private void AddTypes(IGrouping <String, Type> types, AssemblyTreeViewModel parent) { TypeReflector.RequiredBindings = SeperateAppDomainAssemblyLoader.requiredBindings; TypeReflector.ShowConstructorParameters = SeperateAppDomainAssemblyLoader.showConstructorParameters; TypeReflector.ShowFieldTypes = SeperateAppDomainAssemblyLoader.showFieldTypes; TypeReflector.ShowPropertyTypes = SeperateAppDomainAssemblyLoader.showPropertyTypes; TypeReflector.ShowInterfaces = SeperateAppDomainAssemblyLoader.showInterfaces; TypeReflector.ParseMethodBodyIL = SeperateAppDomainAssemblyLoader.parseMethodBodyIL; TypeReflector.ShowMethodArguments = SeperateAppDomainAssemblyLoader.showMethodArguments; TypeReflector.ShowMethodReturnValues = SeperateAppDomainAssemblyLoader.showMethodReturnValues; TypeReflector.ShowGetMethodForProperty = SeperateAppDomainAssemblyLoader.showGetMethodForProperty; TypeReflector.ShowSetMethodForProperty = SeperateAppDomainAssemblyLoader.showSetMethodForProperty; TypeReflector.ShowEvents = SeperateAppDomainAssemblyLoader.showEvents; TypeReflector.IncludeConstructorParametersAsAssociations = SeperateAppDomainAssemblyLoader.includeConstructorParametersAsAssociations; TypeReflector.IncludePropertyTypesAsAssociations = SeperateAppDomainAssemblyLoader.includePropertyTypesAsAssociations; TypeReflector.IncludeFieldTypesAsAssociations = SeperateAppDomainAssemblyLoader.includeFieldTypesAsAssociations; TypeReflector.IncludeMethodArgumentAsAssociations = SeperateAppDomainAssemblyLoader.includeMethodArgumentAsAssociations; //Load ILReaader Globals MethodBodyReader.LoadOpCodes(); foreach (var t in types) { TypeReflector typeReflector = new TypeReflector(t); typeReflector.ReflectOnType(); SerializableVertex vertex = new SerializableVertex( typeReflector.Name, typeReflector.ShortName, typeReflector.Constructors, typeReflector.Fields, typeReflector.Properties, typeReflector.Interfaces, typeReflector.Methods, typeReflector.Events, new List <string>(typeReflector.Associations), typeReflector.HasConstructors, typeReflector.HasFields, typeReflector.HasProperties, typeReflector.HasInterfaces, typeReflector.HasMethods, typeReflector.HasEvents); AssemblyTreeViewModel newNode = new AssemblyTreeViewModel(RepresentationType.Class, t.Name, vertex, parent); parent.Children.Add(newNode); } }
private void RecurseTreeLookingForSelected(AssemblyTreeViewModel parent, List <AssemblyTreeViewModel> selectedTreeValues) { if (parent.IsChecked == true && parent.NodeType == RepresentationType.Class) { if (!selectedTreeValues.Contains(parent)) { selectedTreeValues.Add(parent); } } foreach (AssemblyTreeViewModel child in parent.Children) { if (child.IsChecked == true && child.NodeType == RepresentationType.Class) { if (!selectedTreeValues.Contains(child)) { selectedTreeValues.Add(child); } } RecurseTreeLookingForSelected(child, selectedTreeValues); } }
private AssemblyTreeViewModel FindCorrectTreeNodeToAddTo( AssemblyTreeViewModel node, String @namespace) { var results = node.Children.Where(x => x.Name == @namespace); if (results.Count() > 0) { return(results.First()); } foreach (AssemblyTreeViewModel child in node.Children) { AssemblyTreeViewModel assemblyTreeViewModel = FindCorrectTreeNodeToAddTo(child, @namespace); if (assemblyTreeViewModel != null) { return(assemblyTreeViewModel); } } return(null); }
public AssemblyTreeViewModel(RepresentationType nodeType, string name, SerializableVertex vertex, AssemblyTreeViewModel parent) { this.NodeType = nodeType; this.Name = name; this.Vertex = vertex; this.Parent = parent; Children = new List <AssemblyTreeViewModel>(); Mediator.Instance.Register(this); }