public AddUpdatedNodesHelper(Lazy <IMethodAnnotations> methodAnnotations, Lazy <IResourceNodeFactory> resourceNodeFactory, IDocumentTreeView documentTreeView, ModuleDocumentNode modNode, ModuleImporter importer) { asmNode = modNode.TreeNode.Parent?.Data as AssemblyDocumentNode; this.modNode = modNode; var dict = new Dictionary <string, List <TypeDef> >(StringComparer.Ordinal); foreach (var t in importer.NewNonNestedTypes) { var ns = (t.TargetType.Namespace ?? UTF8String.Empty).String; if (!dict.TryGetValue(ns, out var list)) { dict[ns] = list = new List <TypeDef>(); } list.Add(t.TargetType); } newTypeNodeCreators = dict.Values.Select(a => new TypeNodeCreator(modNode, a)).ToArray(); existingTypeNodeUpdaters = importer.MergedNonNestedTypes.Select(a => new ExistingTypeNodeUpdater(methodAnnotations, modNode, a)).ToArray(); if (!importer.MergedNonNestedTypes.All(a => a.TargetType.Module == modNode.Document.ModuleDef)) { throw new InvalidOperationException(); } newAssemblyDeclSecurities = importer.NewAssemblyDeclSecurities; newAssemblyCustomAttributes = importer.NewAssemblyCustomAttributes; newModuleCustomAttributes = importer.NewModuleCustomAttributes; newAssemblyVersion = importer.NewAssemblyVersion; if (newAssemblyDeclSecurities != null) { origAssemblyDeclSecurities = modNode.Document.AssemblyDef?.DeclSecurities.ToArray(); } if (newAssemblyCustomAttributes != null) { origAssemblyCustomAttributes = modNode.Document.AssemblyDef?.CustomAttributes.ToArray(); } if (newModuleCustomAttributes != null) { origModuleCustomAttributes = modNode.Document.ModuleDef.CustomAttributes.ToArray(); } if (newAssemblyVersion != null) { origAssemblyVersion = modNode.Document.AssemblyDef?.Version; } if (importer.NewResources.Length != 0) { var module = modNode.Document.ModuleDef; var rsrcListNode = GetResourceListTreeNode(modNode); Debug.Assert(rsrcListNode != null); if (rsrcListNode != null) { var newNodes = new ResourceNode[importer.NewResources.Length]; var treeNodeGroup = documentTreeView.DocumentTreeNodeGroups.GetGroup(DocumentTreeNodeGroupType.ResourceTreeNodeGroup); for (int i = 0; i < newNodes.Length; i++) { newNodes[i] = (ResourceNode)documentTreeView.TreeView.Create(resourceNodeFactory.Value.Create(module, importer.NewResources[i], treeNodeGroup)).Data; } resourceNodeCreator = new ResourceNodeCreator(rsrcListNode, newNodes); } } }
public AddUpdatedNodesHelper(Lazy<IMethodAnnotations> methodAnnotations, Lazy<IResourceNodeFactory> resourceNodeFactory, IDocumentTreeView documentTreeView, ModuleDocumentNode modNode, ModuleImporter importer) { this.modNode = modNode; var dict = new Dictionary<string, List<TypeDef>>(StringComparer.Ordinal); foreach (var t in importer.NewNonNestedTypes) { List<TypeDef> list; var ns = (t.TargetType.Namespace ?? UTF8String.Empty).String; if (!dict.TryGetValue(ns, out list)) dict[ns] = list = new List<TypeDef>(); list.Add(t.TargetType); } newTypeNodeCreators = dict.Values.Select(a => new TypeNodeCreator(modNode, a)).ToArray(); existingTypeNodeUpdaters = importer.MergedNonNestedTypes.Select(a => new ExistingTypeNodeUpdater(methodAnnotations, modNode, a)).ToArray(); if (!importer.MergedNonNestedTypes.All(a => a.TargetType.Module == modNode.Document.ModuleDef)) throw new InvalidOperationException(); newAssemblyDeclSecurities = importer.NewAssemblyDeclSecurities; newAssemblyCustomAttributes = importer.NewAssemblyCustomAttributes; newModuleCustomAttributes = importer.NewModuleCustomAttributes; if (newAssemblyDeclSecurities != null) origAssemblyDeclSecurities = modNode.Document.AssemblyDef?.DeclSecurities.ToArray(); if (newAssemblyCustomAttributes != null) origAssemblyCustomAttributes = modNode.Document.AssemblyDef?.CustomAttributes.ToArray(); if (newModuleCustomAttributes != null) origModuleCustomAttributes = modNode.Document.ModuleDef.CustomAttributes.ToArray(); if (importer.NewResources.Length != 0) { var module = modNode.Document.ModuleDef; var rsrcListNode = GetResourceListTreeNode(modNode); Debug.Assert(rsrcListNode != null); if (rsrcListNode != null) { var newNodes = new ResourceNode[importer.NewResources.Length]; var treeNodeGroup = documentTreeView.DocumentTreeNodeGroups.GetGroup(DocumentTreeNodeGroupType.ResourceTreeNodeGroup); for (int i = 0; i < newNodes.Length; i++) newNodes[i] = (ResourceNode)documentTreeView.TreeView.Create(resourceNodeFactory.Value.Create(module, importer.NewResources[i], treeNodeGroup)).Data; resourceNodeCreator = new ResourceNodeCreator(rsrcListNode, newNodes); } } }