コード例 #1
0
		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();
		}
コード例 #2
0
		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;
		}
コード例 #3
0
		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;
		}
コード例 #4
0
		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;
		}
コード例 #5
0
		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;
		}
コード例 #6
0
		public NamespaceNodeCreator(string ns, ModuleDocumentNode modNode) {
			this.modNode = modNode;
			nsNode = modNode.FindNode(ns);
			if (nsNode == null) {
				nsNode = modNode.Create(ns);
				nsNodeCreated = true;
			}
		}
コード例 #7
0
		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;
		}
コード例 #8
0
		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);
		}
コード例 #9
0
		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;
		}
コード例 #10
0
		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);
		}
コード例 #11
0
ファイル: TreeViewUpdater.cs プロジェクト: manojdjoshi/dnSpy
		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;
		}
コード例 #12
0
ファイル: TypeNodeCreator.cs プロジェクト: manojdjoshi/dnSpy
		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();
		}
コード例 #13
0
		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);
				}
			}
		}
コード例 #14
0
ファイル: ModuleCommands.cs プロジェクト: manojdjoshi/dnSpy
		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);
		}
コード例 #15
0
ファイル: AddClassCommands.cs プロジェクト: manojdjoshi/dnSpy
		AddClassCommand(Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer)
			: base(addUpdatedNodesHelperProvider, modNode, importer) {
		}
コード例 #16
0
		public PropertyNodeCreator(ModuleDocumentNode modNode, TypeNode ownerNode, PropertyDef property) {
			this.ownerNode = ownerNode;
			propNode = modNode.Context.DocumentTreeView.Create(property);
		}
コード例 #17
0
ファイル: ClassLoader.cs プロジェクト: manojdjoshi/dnSpy
			public ModuleState(CorModuleDefFile corModuleDefFile, ModuleDocumentNode moduleNode, HashSet<uint> modifiedTypes, HashSet<uint> loadClassHash) {
				CorModuleDefFile = corModuleDefFile;
				ModuleNode = moduleNode;
				ModifiedTypes = modifiedTypes;
				LoadClassHash = loadClassHash;
			}
コード例 #18
0
		static ResourcesFolderNode GetResourceListTreeNode(ModuleDocumentNode modNode) {
			modNode.TreeNode.EnsureChildrenLoaded();
			return modNode.TreeNode.DataChildren.OfType<ResourcesFolderNode>().FirstOrDefault();
		}
コード例 #19
0
		public AddUpdatedNodesHelper Create(ModuleDocumentNode modNode, ModuleImporter importer) =>
			new AddUpdatedNodesHelper(methodAnnotations, resourceNodeFactory, documentTreeView, modNode, importer);
コード例 #20
0
ファイル: ModuleCommands.cs プロジェクト: manojdjoshi/dnSpy
		AddExistingNetModuleToAssemblyCommand(IUndoCommandService undoCommandService, DsDocumentNode asmNode, ModuleDocumentNode modNode)
			: base(undoCommandService, asmNode, modNode, false) {
		}
コード例 #21
0
ファイル: Commands.cs プロジェクト: manojdjoshi/dnSpy
		EditMethodBodyCodeCommand(Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer)
			: base(addUpdatedNodesHelperProvider, modNode, importer) {
		}
コード例 #22
0
ファイル: ModuleCommands.cs プロジェクト: manojdjoshi/dnSpy
		ModuleSettingsCommand(ModuleDocumentNode modNode, ModuleOptions newOptions) {
			this.modNode = modNode;
			this.newOptions = newOptions;
			origOptions = new ModuleOptions(modNode.Document.ModuleDef);
		}
コード例 #23
0
		protected EditCodeCommandBase(Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer) {
			addUpdatedNodesHelper = addUpdatedNodesHelperProvider.Value.Create(modNode, importer);
		}
コード例 #24
0
		public MethodNodeCreator(ModuleDocumentNode modNode, TypeNode ownerNode, MethodDef method) {
			this.ownerNode = ownerNode;
			methodNode = modNode.Context.DocumentTreeView.Create(method);
		}
コード例 #25
0
ファイル: TreeViewUpdater.cs プロジェクト: manojdjoshi/dnSpy
		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;
		}
コード例 #26
0
ファイル: TreeViewUpdater.cs プロジェクト: manojdjoshi/dnSpy
		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;
		}
コード例 #27
0
ファイル: ModuleCommands.cs プロジェクト: manojdjoshi/dnSpy
		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;
		}
コード例 #28
0
		MergeWithAssemblyCommand(Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer)
			: base(addUpdatedNodesHelperProvider, modNode, importer) {
		}
コード例 #29
0
		public ReferencesFolderNodeImpl(ITreeNodeGroup treeNodeGroup, ModuleDocumentNode moduleNode) {
			Debug.Assert(moduleNode.Document.ModuleDef != null);
			TreeNodeGroup = treeNodeGroup;
			this.moduleNode = moduleNode;
		}
コード例 #30
0
ファイル: ModuleCommands.cs プロジェクト: manojdjoshi/dnSpy
		AddNewNetModuleToAssemblyCommand(IUndoCommandService undoCommandService, DsDocumentNode asmNode, ModuleDocumentNode modNode)
			: base(undoCommandService, asmNode, modNode, true) {
		}