public ExistingTypeNodeUpdater(Lazy<IMethodAnnotations> methodAnnotations, ModuleDocumentNode modNode, MergedImportedType type) { targetType = type.TargetType; ownerModule = targetType.Module; origTypeDefOptions = new TypeDefOptions(targetType); newTypeDefOptions = type.NewTypeDefOptions; typeNode = modNode.Context.DocumentTreeView.FindNode(targetType); if (typeNode == null) throw new InvalidOperationException(); nestedTypes1 = type.NewOrExistingNestedTypes.OfType<MergedImportedType>().Select(a => new ExistingTypeNodeUpdater(methodAnnotations, modNode, a)).ToArray(); nestedTypes2 = type.NewOrExistingNestedTypes.OfType<NewImportedType>().Select(a => new NestedTypeNodeCreator(modNode, typeNode, a.TargetType)).ToArray(); if (nestedTypes1.Length + nestedTypes2.Length != type.NewOrExistingNestedTypes.Count) throw new InvalidOperationException(); fields = type.NewFields.Select(a => new FieldNodeCreator(modNode, typeNode, a)).ToArray(); var specialMethods = GetSpecialMethods(type); methods = type.NewMethods.Where(a => !specialMethods.Contains(a)).Select(a => new MethodNodeCreator(modNode, typeNode, a)).ToArray(); events = type.NewEvents.Select(a => new EventNodeCreator(modNode, typeNode, a)).ToArray(); properties = type.NewProperties.Select(a => new PropertyNodeCreator(modNode, typeNode, a)).ToArray(); editedFields = type.EditedFields.Select(a => new EditedFieldUpdater(modNode, a.OriginalField, a.FieldDefOptions)).ToArray(); editedMethods = type.EditedMethods.Select(a => new EditedMethodUpdater(methodAnnotations, modNode, a.OriginalMethod, a.NewBody, a.MethodDefOptions)).ToArray(); editedProperties = type.EditedProperties.Select(a => new EditedPropertyUpdater(modNode, a.OriginalProperty, a.PropertyDefOptions)).ToArray(); editedEvents = type.EditedEvents.Select(a => new EditedEventUpdater(modNode, a.OriginalEvent, a.EventDefOptions)).ToArray(); deletedTypes = type.DeletedNestedTypes.Select(a => new DeletedTypeUpdater(modNode, a)).ToArray(); deletedFields = type.DeletedFields.Select(a => new DeletedFieldUpdater(modNode, a)).ToArray(); deletedMethods = type.DeletedMethods.Select(a => new DeletedMethodUpdater(modNode, a)).ToArray(); deletedProperties = type.DeletedProperties.Select(a => new DeletedPropertyUpdater(modNode, a)).ToArray(); deletedEvents = type.DeletedEvents.Select(a => new DeletedEventUpdater(modNode, a)).ToArray(); }
public DeletedEventUpdater(ModuleDocumentNode modNode, EventDef originalEvent) { ownerNode = modNode.Context.DocumentTreeView.FindNode(originalEvent); if (ownerNode == null) throw new InvalidOperationException(); parentNode = ownerNode.TreeNode.Parent.Data; ownerType = originalEvent.DeclaringType; @event = originalEvent; }
public EditedPropertyUpdater(ModuleDocumentNode modNode, PropertyDef originalProperty, PropertyDefOptions propertyDefOptions) { ownerNode = modNode.Context.DocumentTreeView.FindNode(originalProperty); if (ownerNode == null) throw new InvalidOperationException(); property = originalProperty; originalPropertyDefOptions = new PropertyDefOptions(originalProperty); newPropertyDefOptions = propertyDefOptions; }
public EditedEventUpdater(ModuleDocumentNode modNode, EventDef originalEvent, EventDefOptions eventDefOptions) { ownerNode = modNode.Context.DocumentTreeView.FindNode(originalEvent); if (ownerNode == null) throw new InvalidOperationException(); @event = originalEvent; originalEventDefOptions = new EventDefOptions(originalEvent); newEventDefOptions = eventDefOptions; }
public DeletedMethodUpdater(ModuleDocumentNode modNode, MethodDef originalMethod) { ownerNode = modNode.Context.DocumentTreeView.FindNode(originalMethod); if (ownerNode == null) throw new InvalidOperationException(); parentNode = ownerNode.TreeNode.Parent.Data; ownerType = originalMethod.DeclaringType; method = originalMethod; }
public NamespaceNodeCreator(string ns, ModuleDocumentNode modNode) { this.modNode = modNode; nsNode = modNode.FindNode(ns); if (nsNode == null) { nsNode = modNode.Create(ns); nsNodeCreated = true; } }
public DeletedPropertyUpdater(ModuleDocumentNode modNode, PropertyDef originalProperty) { ownerNode = modNode.Context.DocumentTreeView.FindNode(originalProperty); if (ownerNode == null) throw new InvalidOperationException(); parentNode = ownerNode.TreeNode.Parent.Data; ownerType = originalProperty.DeclaringType; property = originalProperty; }
public EditedMethodUpdater(Lazy<IMethodAnnotations> methodAnnotations, ModuleDocumentNode modNode, MethodDef originalMethod, Emit.MethodBody newBody, MethodDefOptions methodDefOptions) { this.methodAnnotations = methodAnnotations; ownerNode = modNode.Context.DocumentTreeView.FindNode(originalMethod); if (ownerNode == null) throw new InvalidOperationException(); method = originalMethod; originalMethodState = new MethodState(originalMethod, methodAnnotations.Value.IsBodyModified(method)); newMethodState = new MethodState(newBody, methodDefOptions, true); }
public DeletedTypeUpdater(ModuleDocumentNode modNode, TypeDef originalType) { ownerNode = modNode.Context.DocumentTreeView.FindNode(originalType); if (ownerNode == null) throw new InvalidOperationException(); parentNode = ownerNode.TreeNode.Parent.Data; ownerModule = originalType.Module; ownerType = originalType.DeclaringType; type = originalType; }
public NestedTypeNodeCreator(ModuleDocumentNode modNode, TypeNode ownerTypeNode, TypeDef nestedType) { if (modNode == null) throw new ArgumentNullException(nameof(modNode)); if (nestedType == null) throw new ArgumentNullException(nameof(nestedType)); if (nestedType.Module != null) throw new ArgumentException(); this.ownerTypeNode = ownerTypeNode; nestedTypeNode = modNode.Context.DocumentTreeView.CreateNested(nestedType); }
public TreeViewUpdater(IDocumentTabService documentTabService, CorModuleDefFile cmdf, ModuleDocumentNode node, HashSet<uint> modifiedTypes, HashSet<uint> loadedClassTokens) { Debug.Assert(node.Document == cmdf); this.documentTabService = documentTabService; CorModuleDefFile = cmdf; ModuleNode = node; this.modifiedTypes = new HashSet<uint>(modifiedTypes); this.loadedClassTokens = loadedClassTokens; checkedTypes = new HashSet<TypeDef>(); modNode = node; }
public TypeNodeCreator(ModuleDocumentNode modNode, List<TypeDef> types) { if (modNode == null) throw new ArgumentNullException(nameof(modNode)); if (types == null) throw new ArgumentNullException(nameof(types)); if (types.Count == 0) throw new ArgumentException(); var ns = (types[0].Namespace ?? UTF8String.Empty).String; foreach (var t in types) { var tns = (t.Namespace ?? UTF8String.Empty).String; if (tns != ns) throw new ArgumentException(); // Can't be a nested type, and can't be part of a module yet if (t.DeclaringType != null || t.Module != null) throw new ArgumentException(); } ownerList = modNode.Document.ModuleDef.Types; nsNodeCreator = new NamespaceNodeCreator(ns, modNode); typeNodes = types.Select(a => modNode.Context.DocumentTreeView.Create(a)).ToArray(); }
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); } } }
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); }
AddClassCommand(Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer) : base(addUpdatedNodesHelperProvider, modNode, importer) { }
public PropertyNodeCreator(ModuleDocumentNode modNode, TypeNode ownerNode, PropertyDef property) { this.ownerNode = ownerNode; propNode = modNode.Context.DocumentTreeView.Create(property); }
public ModuleState(CorModuleDefFile corModuleDefFile, ModuleDocumentNode moduleNode, HashSet<uint> modifiedTypes, HashSet<uint> loadClassHash) { CorModuleDefFile = corModuleDefFile; ModuleNode = moduleNode; ModifiedTypes = modifiedTypes; LoadClassHash = loadClassHash; }
static ResourcesFolderNode GetResourceListTreeNode(ModuleDocumentNode modNode) { modNode.TreeNode.EnsureChildrenLoaded(); return modNode.TreeNode.DataChildren.OfType<ResourcesFolderNode>().FirstOrDefault(); }
public AddUpdatedNodesHelper Create(ModuleDocumentNode modNode, ModuleImporter importer) => new AddUpdatedNodesHelper(methodAnnotations, resourceNodeFactory, documentTreeView, modNode, importer);
AddExistingNetModuleToAssemblyCommand(IUndoCommandService undoCommandService, DsDocumentNode asmNode, ModuleDocumentNode modNode) : base(undoCommandService, asmNode, modNode, false) { }
EditMethodBodyCodeCommand(Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer) : base(addUpdatedNodesHelperProvider, modNode, importer) { }
ModuleSettingsCommand(ModuleDocumentNode modNode, ModuleOptions newOptions) { this.modNode = modNode; this.newOptions = newOptions; origOptions = new ModuleOptions(modNode.Document.ModuleDef); }
protected EditCodeCommandBase(Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer) { addUpdatedNodesHelper = addUpdatedNodesHelperProvider.Value.Create(modNode, importer); }
public MethodNodeCreator(ModuleDocumentNode modNode, TypeNode ownerNode, MethodDef method) { this.ownerNode = ownerNode; methodNode = modNode.Context.DocumentTreeView.Create(method); }
static TypeNode GetOrCreateNonNestedTypeTreeNode(ModuleDocumentNode modNode, TypeDef type) { Debug.Assert(type != null && type.DeclaringType == null); modNode.TreeNode.EnsureChildrenLoaded(); TypeNode typeNode; var nsNode = GetOrCreateNamespaceNode(modNode, type.Namespace); typeNode = nsNode.TreeNode.DataChildren.OfType<TypeNode>().FirstOrDefault(a => a.TypeDef == type); if (typeNode != null) return typeNode; typeNode = nsNode.Create(type); nsNode.TreeNode.AddChild(typeNode.TreeNode); return typeNode; }
static NamespaceNode GetOrCreateNamespaceNode(ModuleDocumentNode modNode, string ns) { modNode.TreeNode.EnsureChildrenLoaded(); var nsNode = modNode.TreeNode.DataChildren.OfType<NamespaceNode>().FirstOrDefault(a => a.Name == ns); if (nsNode != null) return nsNode; nsNode = modNode.Create(ns); modNode.TreeNode.AddChild(nsNode.TreeNode); return nsNode; }
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; }
MergeWithAssemblyCommand(Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer) : base(addUpdatedNodesHelperProvider, modNode, importer) { }
public ReferencesFolderNodeImpl(ITreeNodeGroup treeNodeGroup, ModuleDocumentNode moduleNode) { Debug.Assert(moduleNode.Document.ModuleDef != null); TreeNodeGroup = treeNodeGroup; this.moduleNode = moduleNode; }
AddNewNetModuleToAssemblyCommand(IUndoCommandService undoCommandService, DsDocumentNode asmNode, ModuleDocumentNode modNode) : base(undoCommandService, asmNode, modNode, true) { }