Exemplo n.º 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();
		}
Exemplo n.º 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;
		}
Exemplo n.º 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;
		}
Exemplo n.º 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;
		}
Exemplo n.º 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;
		}
Exemplo n.º 6
0
		public NamespaceNodeCreator(string ns, ModuleDocumentNode modNode) {
			this.modNode = modNode;
			nsNode = modNode.FindNode(ns);
			if (nsNode == null) {
				nsNode = modNode.Create(ns);
				nsNodeCreated = true;
			}
		}
Exemplo n.º 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;
		}
Exemplo n.º 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);
		}
Exemplo n.º 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;
		}
Exemplo n.º 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);
		}
Exemplo n.º 11
0
		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;
		}
Exemplo n.º 12
0
		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();
		}
Exemplo n.º 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);
				}
			}
		}
Exemplo n.º 14
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);
		}
Exemplo n.º 15
0
		AddClassCommand(Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer)
			: base(addUpdatedNodesHelperProvider, modNode, importer) {
		}
Exemplo n.º 16
0
		public PropertyNodeCreator(ModuleDocumentNode modNode, TypeNode ownerNode, PropertyDef property) {
			this.ownerNode = ownerNode;
			propNode = modNode.Context.DocumentTreeView.Create(property);
		}
Exemplo n.º 17
0
			public ModuleState(CorModuleDefFile corModuleDefFile, ModuleDocumentNode moduleNode, HashSet<uint> modifiedTypes, HashSet<uint> loadClassHash) {
				CorModuleDefFile = corModuleDefFile;
				ModuleNode = moduleNode;
				ModifiedTypes = modifiedTypes;
				LoadClassHash = loadClassHash;
			}
Exemplo n.º 18
0
		static ResourcesFolderNode GetResourceListTreeNode(ModuleDocumentNode modNode) {
			modNode.TreeNode.EnsureChildrenLoaded();
			return modNode.TreeNode.DataChildren.OfType<ResourcesFolderNode>().FirstOrDefault();
		}
Exemplo n.º 19
0
		public AddUpdatedNodesHelper Create(ModuleDocumentNode modNode, ModuleImporter importer) =>
			new AddUpdatedNodesHelper(methodAnnotations, resourceNodeFactory, documentTreeView, modNode, importer);
Exemplo n.º 20
0
		AddExistingNetModuleToAssemblyCommand(IUndoCommandService undoCommandService, DsDocumentNode asmNode, ModuleDocumentNode modNode)
			: base(undoCommandService, asmNode, modNode, false) {
		}
Exemplo n.º 21
0
		EditMethodBodyCodeCommand(Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer)
			: base(addUpdatedNodesHelperProvider, modNode, importer) {
		}
Exemplo n.º 22
0
		ModuleSettingsCommand(ModuleDocumentNode modNode, ModuleOptions newOptions) {
			this.modNode = modNode;
			this.newOptions = newOptions;
			origOptions = new ModuleOptions(modNode.Document.ModuleDef);
		}
Exemplo n.º 23
0
		protected EditCodeCommandBase(Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer) {
			addUpdatedNodesHelper = addUpdatedNodesHelperProvider.Value.Create(modNode, importer);
		}
Exemplo n.º 24
0
		public MethodNodeCreator(ModuleDocumentNode modNode, TypeNode ownerNode, MethodDef method) {
			this.ownerNode = ownerNode;
			methodNode = modNode.Context.DocumentTreeView.Create(method);
		}
Exemplo n.º 25
0
		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;
		}
Exemplo n.º 26
0
		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;
		}
Exemplo n.º 27
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;
		}
Exemplo n.º 28
0
		MergeWithAssemblyCommand(Lazy<IAddUpdatedNodesHelperProvider> addUpdatedNodesHelperProvider, ModuleDocumentNode modNode, ModuleImporter importer)
			: base(addUpdatedNodesHelperProvider, modNode, importer) {
		}
Exemplo n.º 29
0
		public ReferencesFolderNodeImpl(ITreeNodeGroup treeNodeGroup, ModuleDocumentNode moduleNode) {
			Debug.Assert(moduleNode.Document.ModuleDef != null);
			TreeNodeGroup = treeNodeGroup;
			this.moduleNode = moduleNode;
		}
Exemplo n.º 30
0
		AddNewNetModuleToAssemblyCommand(IUndoCommandService undoCommandService, DsDocumentNode asmNode, ModuleDocumentNode modNode)
			: base(undoCommandService, asmNode, modNode, true) {
		}