Example #1
0
        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);
                }
            }
        }
Example #2
0
        AssemblySettingsCommand(AssemblyDocumentNode asmNode, AssemblyOptions newOptions)
        {
            this.asmNode    = asmNode;
            this.newOptions = newOptions;
            origOptions     = new AssemblyOptions(asmNode.Document.AssemblyDef);

            if (newOptions.Name != origOptions.Name)
            {
                assemblyRefInfos = RefFinder.FindAssemblyRefsToThisModule(asmNode.Document.ModuleDef).Where(a => AssemblyNameComparer.NameAndPublicKeyTokenOnly.Equals(a, asmNode.Document.AssemblyDef)).Select(a => new AssemblyRefInfo(a)).ToArray();
            }
        }
Example #3
0
 protected AddNetModuleToAssemblyCommand(IUndoCommandService undoCommandService, DsDocumentNode asmNode, ModuleDocumentNode modNode, bool modNodeWasCreated)
 {
     this.undoCommandService = undoCommandService;
     if (!(asmNode is AssemblyDocumentNode))
     {
         asmNode = (AssemblyDocumentNode)asmNode.TreeNode.Parent.Data;
     }
     this.asmNode           = (AssemblyDocumentNode)asmNode;
     this.modNode           = modNode;
     this.modNodeWasCreated = modNodeWasCreated;
 }
Example #4
0
        void SearchAssemblyInternal(AssemblyDocumentNode asmNode)
        {
            if (asmNode == null)
            {
                return;
            }
            var asm = asmNode.Document.AssemblyDef;

            Debug.Assert(asm != null);
            if (asm == null)
            {
                return;
            }
            var res = options.Filter.GetResult(asm);

            if (res.FilterType == FilterType.Hide)
            {
                return;
            }
            CheckCustomAttributes(asmNode.Document, asm, null);

            if (res.IsMatch && (IsMatch(asm.FullName, asmNode.Document) || IsMatch(asm.Name, null)))
            {
                options.OnMatch(new SearchResult {
                    Context                = options.Context,
                    Object                 = asm,
                    NameObject             = asm,
                    ObjectImageReference   = options.DotNetImageService.GetImageReference(asmNode.Document.ModuleDef),
                    LocationObject         = null,
                    LocationImageReference = new ImageReference(),
                    Document               = asmNode.Document,
                });
            }

            if (asmNode.TreeNode.LazyLoading)
            {
                options.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => {
                    asmNode.TreeNode.EnsureChildrenLoaded();
                }));
            }
            var modChildren = asmNode.TreeNode.DataChildren.OfType <ModuleDocumentNode>().ToArray();

            foreach (var node in asmNode.TreeNode.DataChildren)
            {
                options.CancellationToken.ThrowIfCancellationRequested();
                var modNode = node as ModuleDocumentNode;
                if (modNode != null)
                {
                    SearchModule(modNode.Document);
                }
            }
        }
Example #5
0
 RemoveNetModuleFromAssemblyCommand(Lazy <IUndoCommandService> undoCommandService, ModuleDocumentNode modNode)
 {
     this.undoCommandService = undoCommandService;
     asmNode = (AssemblyDocumentNode)modNode.TreeNode.Parent.Data;
     Debug.Assert(asmNode != null);
     this.modNode = modNode;
     removeIndex  = asmNode.TreeNode.DataChildren.ToList().IndexOf(modNode);
     Debug.Assert(removeIndex > 0);
     Debug.Assert(asmNode.Document.AssemblyDef != null &&
                  asmNode.Document.AssemblyDef.Modules.IndexOf(modNode.Document.ModuleDef) == removeIndex);
     removeIndexDocument = asmNode.Document.Children.IndexOf(modNode.Document);
     Debug.Assert(removeIndexDocument >= 0);
 }