Пример #1
0
		static void Execute(ILSpyTreeNode[] nodes)
		{
			if (!CanExecute(nodes))
				return;

			var ownerNode = nodes[0];
			if (!(ownerNode is TypeTreeNode))
				ownerNode = (ILSpyTreeNode)ownerNode.Parent;
			var typeNode = ownerNode as TypeTreeNode;
			Debug.Assert(typeNode != null);
			if (typeNode == null)
				throw new InvalidOperationException();

			var module = ILSpyTreeNode.GetModule(typeNode);
			Debug.Assert(module != null);
			if (module == null)
				throw new InvalidOperationException();
			var options = TypeDefOptions.Create(UTF8String.Empty, TypeConstants.DEFAULT_TYPE_NAME, module.CorLibTypes.Object.TypeDefOrRef, true);

			var data = new TypeOptionsVM(options, module, MainWindow.Instance.CurrentLanguage, null);
			var win = new TypeOptionsDlg();
			win.Title = "Create Nested Type";
			win.DataContext = data;
			win.Owner = MainWindow.Instance;
			if (win.ShowDialog() != true)
				return;

			UndoCommandManager.Instance.Add(new CreateNestedTypeDefCommand(typeNode, data.CreateTypeDefOptions()));
		}
Пример #2
0
 TypeDefOptions CopyTo(TypeDefOptions options)
 {
     options.Attributes  = Attributes;
     options.Namespace   = Namespace;
     options.Name        = Name;
     options.PackingSize = PackingSize.Value;
     options.ClassSize   = ClassSize.Value;
     options.BaseType    = BaseTypeSig.ToTypeDefOrRef();
     options.CustomAttributes.Clear();
     options.CustomAttributes.AddRange(CustomAttributesVM.Collection.Select(a => a.CreateCustomAttributeOptions().Create()));
     options.DeclSecurities.Clear();
     options.DeclSecurities.AddRange(DeclSecuritiesVM.Collection.Select(a => a.CreateDeclSecurityOptions().Create(ownerModule)));
     options.GenericParameters.Clear();
     options.GenericParameters.AddRange(GenericParamsVM.Collection.Select(a => a.CreateGenericParamOptions().Create(ownerModule)));
     options.Interfaces.Clear();
     options.Interfaces.AddRange(InterfaceImplsVM.Collection.Select(a => a.CreateTypeDefOrRefAndCAOptions().CreateInterfaceImpl(ownerModule)));
     if (ModelUtils.GetHasSecurityBit(options.DeclSecurities, options.CustomAttributes))
     {
         options.Attributes |= TypeAttributes.HasSecurity;
     }
     else
     {
         options.Attributes &= ~TypeAttributes.HasSecurity;
     }
     return(options);
 }
Пример #3
0
        CreateNestedTypeDefCommand(TypeTreeNode ownerType, TypeDefOptions options)
        {
            this.ownerType = ownerType;

            var modNode = ILSpyTreeNode.GetNode<AssemblyTreeNode>(ownerType);
            Debug.Assert(modNode != null);
            if (modNode == null)
                throw new InvalidOperationException();
            this.nestedType = new TypeTreeNode(options.CreateTypeDef(modNode.LoadedAssembly.ModuleDefinition), modNode.Parent as AssemblyTreeNode ?? modNode);
        }
Пример #4
0
		CreateNestedTypeDefCommand(TypeTreeNode ownerType, TypeDefOptions options)
		{
			this.ownerType = ownerType;

			var modNode = ILSpyTreeNode.GetNode<AssemblyTreeNode>(ownerType);
			Debug.Assert(modNode != null);
			if (modNode == null)
				throw new InvalidOperationException();
			this.nestedType = new TypeTreeNode(options.CreateTypeDef(modNode.LoadedAssembly.ModuleDefinition), modNode.Parent as AssemblyTreeNode ?? modNode);
		}
Пример #5
0
		CreateTypeDefCommand(IList<TypeDef> ownerList, ILSpyTreeNode ownerNode, TypeDefOptions options)
		{
			this.ownerList = ownerList;
			var modNode = ILSpyTreeNode.GetNode<AssemblyTreeNode>(ownerNode);
			Debug.Assert(modNode != null);
			if (modNode == null)
				throw new InvalidOperationException();
			this.nsNodeCreator = new NamespaceTreeNodeCreator(options.Namespace, modNode);
			this.typeNode = new TypeTreeNode(options.CreateTypeDef(modNode.LoadedAssembly.ModuleDefinition), modNode.Parent as AssemblyTreeNode ?? modNode);
		}
Пример #6
0
        public TypeOptionsVM(TypeDefOptions options, ModuleDef ownerModule, Language language, TypeDef ownerType)
        {
            this.ownerModule = ownerModule;
            var typeSigCreatorOptions = new TypeSigCreatorOptions(ownerModule, language)
            {
                IsLocal = false,
                CanAddGenericTypeVar   = true,
                CanAddGenericMethodVar = false,
                OwnerType = ownerType,
            };

            if (ownerType != null && ownerType.GenericParameters.Count == 0)
            {
                typeSigCreatorOptions.CanAddGenericTypeVar = false;
            }
            this.typeSigCreator = new TypeSigCreatorVM(typeSigCreatorOptions);
            this.typeSigCreator.PropertyChanged += typeSigCreator_PropertyChanged;

            this.customAttributesVM   = new CustomAttributesVM(ownerModule, language, ownerType, null);
            this.declSecuritiesVM     = new DeclSecuritiesVM(ownerModule, language, ownerType, null);
            this.genericParamsVM      = new GenericParamsVM(ownerModule, language, ownerType, null);
            this.typeDefOrRefAndCAsVM = new TypeDefOrRefAndCAsVM <InterfaceImpl>("Edit Interface Impl", "Create Interface Impl", ownerModule, language, ownerType, null);

            this.origOptions     = options;
            this.isNestedType    = (options.Attributes & TypeAttributes.VisibilityMask) > TypeAttributes.Public;
            this.typeKindVM      = new EnumListVM(typeKindList, (a, b) => OnTypeKindChanged());
            this.typeLayoutVM    = new EnumListVM(typeLayoutList, (a, b) => InitializeTypeKind());
            this.typeSemanticsVM = new EnumListVM(typeSemanticsList, (a, b) => InitializeTypeKind());
            this.packingSize     = new NullableUInt16VM(a => HasErrorUpdated());
            this.classSize       = new NullableUInt32VM(a => HasErrorUpdated());

            Types.TypeVisibility start, end;
            if (!IsNestedType)
            {
                start = Types.TypeVisibility.NotPublic;
                end   = Types.TypeVisibility.Public;
            }
            else
            {
                start = Types.TypeVisibility.NestedPublic;
                end   = Types.TypeVisibility.NestedFamORAssem;
            }
            for (var t = Types.TypeVisibility.NotPublic; t <= Types.TypeVisibility.NestedFamORAssem; t++)
            {
                if (t < start || t > end)
                {
                    TypeVisibility.Items.RemoveAt(TypeVisibility.GetIndex(t));
                }
            }

            InitializeTypeKind();
            this.typeSigCreator.CanAddFnPtr = false;
            Reinitialize();
        }
Пример #7
0
 void InitializeFrom(TypeDefOptions options)
 {
     Attributes                    = options.Attributes;
     Namespace                     = options.Namespace;
     Name                          = options.Name;
     PackingSize.Value             = options.PackingSize;
     ClassSize.Value               = options.ClassSize;
     BaseTypeSig                   = options.BaseType.ToTypeSig();
     TypeVisibility.SelectedItem   = (Types.TypeVisibility)((int)(options.Attributes & TypeAttributes.VisibilityMask) >> 0);
     TypeLayout.SelectedItem       = (Types.TypeLayout)(((int)options.Attributes >> 3) & 3);
     TypeSemantics.SelectedItem    = (Types.TypeSemantics)(((int)options.Attributes >> 5) & 1);
     TypeStringFormat.SelectedItem = (Types.TypeStringFormat)(((int)options.Attributes >> 16) & 3);
     TypeCustomFormat.SelectedItem = (Types.TypeCustomFormat)(((int)options.Attributes >> 22) & 3);
     CustomAttributesVM.InitializeFrom(options.CustomAttributes);
     DeclSecuritiesVM.InitializeFrom(options.DeclSecurities);
     GenericParamsVM.InitializeFrom(options.GenericParameters);
     InterfaceImplsVM.InitializeFrom(options.Interfaces);
 }
Пример #8
0
		TypeDefSettingsCommand(ModuleDef module, TypeTreeNode typeNode, TypeDefOptions options)
		{
			this.module = module;
			this.typeNode = typeNode;
			this.newOptions = options;
			this.origOptions = new TypeDefOptions(typeNode.TypeDefinition);

			this.origParentNode = (ILSpyTreeNode)typeNode.Parent;
			this.origParentChildIndex = this.origParentNode.Children.IndexOf(typeNode);
			Debug.Assert(this.origParentChildIndex >= 0);
			if (this.origParentChildIndex < 0)
				throw new InvalidOperationException();

			this.nameChanged = origOptions.Name != newOptions.Name;
			if (this.origParentNode is NamespaceTreeNode) {
				var asmNode = (AssemblyTreeNode)this.origParentNode.Parent;
				if (AssemblyTreeNode.NamespaceStringComparer.Compare(newOptions.Namespace, origOptions.Namespace) != 0)
					this.nsNodeCreator = new NamespaceTreeNodeCreator(newOptions.Namespace, asmNode);
			}
		}
Пример #9
0
		static void Execute(ILSpyTreeNode[] nodes)
		{
			if (!CanExecute(nodes))
				return;

			var nsNode = ILSpyTreeNode.GetNode<NamespaceTreeNode>(nodes[0]);
			string ns = nsNode == null ? string.Empty : nsNode.Name;

			var module = ILSpyTreeNode.GetModule(nodes[0]);
			Debug.Assert(module != null);
			if (module == null)
				throw new InvalidOperationException();
			var options = TypeDefOptions.Create(ns, TypeConstants.DEFAULT_TYPE_NAME, module.CorLibTypes.Object.TypeDefOrRef, false);

			var data = new TypeOptionsVM(options, module, MainWindow.Instance.CurrentLanguage, null);
			var win = new TypeOptionsDlg();
			win.Title = "Create Type";
			win.DataContext = data;
			win.Owner = MainWindow.Instance;
			if (win.ShowDialog() != true)
				return;

			UndoCommandManager.Instance.Add(new CreateTypeDefCommand(module.Types, nodes[0], data.CreateTypeDefOptions()));
		}
Пример #10
0
        TypeDefSettingsCommand(ModuleDef module, TypeTreeNode typeNode, TypeDefOptions options)
        {
            this.module = module;
            this.typeNode = typeNode;
            this.newOptions = options;
            this.origOptions = new TypeDefOptions(typeNode.TypeDefinition);

            this.origParentNode = (ILSpyTreeNode)typeNode.Parent;
            this.origParentChildIndex = this.origParentNode.Children.IndexOf(typeNode);
            Debug.Assert(this.origParentChildIndex >= 0);
            if (this.origParentChildIndex < 0)
                throw new InvalidOperationException();

            this.nameChanged = origOptions.Name != newOptions.Name;
            if (this.origParentNode is NamespaceTreeNode) {
                var asmNode = (AssemblyTreeNode)this.origParentNode.Parent;
                if (AssemblyTreeNode.NamespaceStringComparer.Compare(newOptions.Namespace, origOptions.Namespace) != 0)
                    this.nsNodeCreator = new NamespaceTreeNodeCreator(newOptions.Namespace, asmNode);
            }
        }
Пример #11
0
 CreateTypeDefCommand(IList<TypeDef> ownerList, ILSpyTreeNode ownerNode, TypeDefOptions options)
 {
     this.ownerList = ownerList;
     var modNode = ILSpyTreeNode.GetNode<AssemblyTreeNode>(ownerNode);
     Debug.Assert(modNode != null);
     if (modNode == null)
         throw new InvalidOperationException();
     this.nsNodeCreator = new NamespaceTreeNodeCreator(options.Namespace, modNode);
     this.typeNode = new TypeTreeNode(options.CreateTypeDef(modNode.LoadedAssembly.ModuleDefinition), modNode.Parent as AssemblyTreeNode ?? modNode);
 }
Пример #12
0
        TypeDefSettingsCommand(ModuleDef module, TypeTreeNode typeNode, TypeDefOptions options)
        {
            this.module = module;
            this.typeNode = typeNode;
            this.newOptions = options;
            this.origOptions = new TypeDefOptions(typeNode.TypeDefinition);

            this.origParentNode = (ILSpyTreeNode)typeNode.Parent;
            this.origParentChildIndex = this.origParentNode.Children.IndexOf(typeNode);
            Debug.Assert(this.origParentChildIndex >= 0);
            if (this.origParentChildIndex < 0)
                throw new InvalidOperationException();

            this.nameChanged = origOptions.Name != newOptions.Name;
            if (this.origParentNode is NamespaceTreeNode) {
                var asmNode = (AssemblyTreeNode)this.origParentNode.Parent;
                if (!AssemblyTreeNode.NamespaceStringEqualsComparer.Equals(newOptions.Namespace, origOptions.Namespace))
                    this.nsNodeCreator = new NamespaceTreeNodeCreator(newOptions.Namespace, asmNode);
            }

            if (this.nameChanged || origOptions.Namespace != newOptions.Namespace)
                this.typeRefInfos = RefFinder.FindTypeRefsToThisModule(module).Where(a => RefFinder.TypeEqualityComparerInstance.Equals(a, typeNode.TypeDefinition)).Select(a => new TypeRefInfo(a)).ToArray();
        }
Пример #13
0
 void InitializeFrom(TypeDefOptions options)
 {
     Attributes = options.Attributes;
     Namespace = options.Namespace;
     Name = options.Name;
     PackingSize.Value = options.PackingSize;
     ClassSize.Value = options.ClassSize;
     BaseTypeSig = options.BaseType.ToTypeSig();
     TypeVisibility.SelectedItem = (Types.TypeVisibility)((int)(options.Attributes & TypeAttributes.VisibilityMask) >> 0);
     TypeLayout.SelectedItem = (Types.TypeLayout)(((int)options.Attributes >> 3) & 3);
     TypeSemantics.SelectedItem = (Types.TypeSemantics)(((int)options.Attributes >> 5) & 1);
     TypeStringFormat.SelectedItem = (Types.TypeStringFormat)(((int)options.Attributes >> 16) & 3);
     TypeCustomFormat.SelectedItem = (Types.TypeCustomFormat)(((int)options.Attributes >> 22) & 3);
     CustomAttributesVM.InitializeFrom(options.CustomAttributes);
     DeclSecuritiesVM.InitializeFrom(options.DeclSecurities);
     GenericParamsVM.InitializeFrom(options.GenericParameters);
     InterfaceImplsVM.InitializeFrom(options.Interfaces);
 }
Пример #14
0
 TypeDefOptions CopyTo(TypeDefOptions options)
 {
     options.Attributes = Attributes;
     options.Namespace = Namespace;
     options.Name = Name;
     options.PackingSize = PackingSize.Value;
     options.ClassSize = ClassSize.Value;
     options.BaseType = BaseTypeSig.ToTypeDefOrRef();
     options.CustomAttributes.Clear();
     options.CustomAttributes.AddRange(CustomAttributesVM.Collection.Select(a => a.CreateCustomAttributeOptions().Create()));
     options.DeclSecurities.Clear();
     options.DeclSecurities.AddRange(DeclSecuritiesVM.Collection.Select(a => a.CreateDeclSecurityOptions().Create(ownerModule)));
     options.GenericParameters.Clear();
     options.GenericParameters.AddRange(GenericParamsVM.Collection.Select(a => a.CreateGenericParamOptions().Create(ownerModule)));
     options.Interfaces.Clear();
     options.Interfaces.AddRange(InterfaceImplsVM.Collection.Select(a => a.CreateTypeDefOrRefAndCAOptions().CreateInterfaceImpl(ownerModule)));
     if (ModelUtils.GetHasSecurityBit(options.DeclSecurities, options.CustomAttributes))
         options.Attributes |= TypeAttributes.HasSecurity;
     else
         options.Attributes &= ~TypeAttributes.HasSecurity;
     return options;
 }
Пример #15
0
        public TypeOptionsVM(TypeDefOptions options, ModuleDef ownerModule, Language language, TypeDef ownerType)
        {
            this.ownerModule = ownerModule;
            var typeSigCreatorOptions = new TypeSigCreatorOptions(ownerModule, language) {
                IsLocal = false,
                CanAddGenericTypeVar = true,
                CanAddGenericMethodVar = false,
                OwnerType = ownerType,
            };
            if (ownerType != null && ownerType.GenericParameters.Count == 0)
                typeSigCreatorOptions.CanAddGenericTypeVar = false;
            this.typeSigCreator = new TypeSigCreatorVM(typeSigCreatorOptions);
            this.typeSigCreator.PropertyChanged += typeSigCreator_PropertyChanged;

            this.customAttributesVM = new CustomAttributesVM(ownerModule, language, ownerType, null);
            this.declSecuritiesVM = new DeclSecuritiesVM(ownerModule, language, ownerType, null);
            this.genericParamsVM = new GenericParamsVM(ownerModule, language, ownerType, null);
            this.typeDefOrRefAndCAsVM = new TypeDefOrRefAndCAsVM<InterfaceImpl>("Edit Interface Impl", "Create Interface Impl", ownerModule, language, ownerType, null);

            this.origOptions = options;
            this.isNestedType = (options.Attributes & TypeAttributes.VisibilityMask) > TypeAttributes.Public;
            this.typeKindVM = new EnumListVM(typeKindList, (a, b) => OnTypeKindChanged());
            this.typeLayoutVM = new EnumListVM(typeLayoutList, (a, b) => InitializeTypeKind());
            this.typeSemanticsVM = new EnumListVM(typeSemanticsList, (a, b) => InitializeTypeKind());
            this.packingSize = new NullableUInt16VM(a => HasErrorUpdated());
            this.classSize = new NullableUInt32VM(a => HasErrorUpdated());

            Types.TypeVisibility start, end;
            if (!IsNestedType) {
                start = Types.TypeVisibility.NotPublic;
                end = Types.TypeVisibility.Public;
            }
            else {
                start = Types.TypeVisibility.NestedPublic;
                end = Types.TypeVisibility.NestedFamORAssem;
            }
            for (var t = Types.TypeVisibility.NotPublic; t <= Types.TypeVisibility.NestedFamORAssem; t++) {
                if (t < start || t > end)
                    TypeVisibility.Items.RemoveAt(TypeVisibility.GetIndex(t));
            }

            InitializeTypeKind();
            this.typeSigCreator.CanAddFnPtr = false;
            Reinitialize();
        }