Exemple #1
0
 MethodDefOptions CopyTo(MethodDefOptions options)
 {
     options.ImplAttributes = ImplAttributes;
     options.Attributes     = Attributes;
     options.Name           = Name;
     options.MethodSig      = MethodSig;
     options.ImplMap        = PinvokeImpl ? ImplMap : null;
     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.ParamDefs.Clear();
     options.ParamDefs.AddRange(ParamDefsVM.Collection.Select(a => a.CreateParamDefOptions().Create(ownerModule)));
     options.GenericParameters.Clear();
     options.GenericParameters.AddRange(GenericParamsVM.Collection.Select(a => a.CreateGenericParamOptions().Create(ownerModule)));
     options.Overrides.Clear();
     options.Overrides.AddRange(MethodOverridesVM.Collection.Select(a => a.CreateMethodOverrideOptions().Create()));
     if (ModelUtils.GetHasSecurityBit(options.DeclSecurities, options.CustomAttributes))
     {
         options.Attributes |= MethodAttributes.HasSecurity;
     }
     else
     {
         options.Attributes &= ~MethodAttributes.HasSecurity;
     }
     return(options);
 }
Exemple #2
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();
            }

            bool isInstance = !(typeNode.TypeDefinition.IsAbstract && typeNode.TypeDefinition.IsSealed);
            var  sig        = isInstance ? MethodSig.CreateInstance(module.CorLibTypes.Void) : MethodSig.CreateStatic(module.CorLibTypes.Void);
            var  options    = MethodDefOptions.Create("MyMethod", sig);

            if (typeNode.TypeDefinition.IsInterface)
            {
                options.Attributes |= MethodAttributes.Abstract | MethodAttributes.Virtual | MethodAttributes.NewSlot;
            }

            var data = new MethodOptionsVM(options, module, MainWindow.Instance.CurrentLanguage, typeNode.TypeDefinition, null);
            var win  = new MethodOptionsDlg();

            win.Title       = "Create Method";
            win.DataContext = data;
            win.Owner       = MainWindow.Instance;
            if (win.ShowDialog() != true)
            {
                return;
            }

            UndoCommandManager.Instance.Add(new CreateMethodDefCommand(typeNode, data.CreateMethodDefOptions()));
        }
Exemple #3
0
        MethodDefSettingsCommand(MethodTreeNode methodNode, MethodDefOptions options)
        {
            this.methodNode  = methodNode;
            this.newOptions  = options;
            this.origOptions = new MethodDefOptions(methodNode.MethodDefinition);

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

            this.nameChanged = origOptions.Name != newOptions.Name;
        }
Exemple #4
0
 void InitializeFrom(MethodDefOptions options)
 {
     ImplAttributes                = options.ImplAttributes;
     Attributes                    = options.Attributes;
     Name                          = options.Name;
     MethodSig                     = options.MethodSig;
     ImplMap                       = options.ImplMap;
     CodeType.SelectedItem         = (Method.CodeType)((int)(options.ImplAttributes & MethodImplAttributes.CodeTypeMask) >> 0);
     ManagedType.SelectedItem      = (Method.ManagedType)((int)(options.ImplAttributes & MethodImplAttributes.ManagedMask) >> 2);
     MethodVisibility.SelectedItem = (Method.MethodVisibility)((int)(options.Attributes & MethodAttributes.MemberAccessMask) >> 0);
     VtableLayout.SelectedItem     = (Method.VtableLayout)((int)(options.Attributes & MethodAttributes.VtableLayoutMask) >> 8);
     CustomAttributesVM.InitializeFrom(options.CustomAttributes);
     DeclSecuritiesVM.InitializeFrom(options.DeclSecurities);
     ParamDefsVM.InitializeFrom(options.ParamDefs);
     GenericParamsVM.InitializeFrom(options.GenericParameters);
     MethodOverridesVM.InitializeFrom(options.Overrides);
 }
Exemple #5
0
        public MethodOptionsVM(MethodDefOptions options, ModuleDef ownerModule, Language language, TypeDef ownerType, MethodDef ownerMethod)
        {
            this.ownerModule = ownerModule;
            var typeSigCreatorOptions = new TypeSigCreatorOptions(ownerModule, language)
            {
                IsLocal = false,
                CanAddGenericTypeVar   = true,
                CanAddGenericMethodVar = ownerMethod == null || ownerMethod.GenericParameters.Count > 0,
                OwnerType   = ownerType,
                OwnerMethod = ownerMethod,
            };

            if (ownerType != null && ownerType.GenericParameters.Count == 0)
            {
                typeSigCreatorOptions.CanAddGenericTypeVar = false;
            }

            var methodSigCreatorOptions = new MethodSigCreatorOptions(typeSigCreatorOptions);

            methodSigCreatorOptions.IsPropertySig = false;
            this.methodSigCreator = new MethodSigCreatorVM(methodSigCreatorOptions);
            this.methodSigCreator.PropertyChanged += methodSigCreator_PropertyChanged;
            this.methodSigCreator.ParametersCreateTypeSigArray.PropertyChanged += methodSigCreator_PropertyChanged;
            this.methodSigCreator.ParametersCreateTypeSigArray.TypeSigCreator.ShowTypeFullName = true;
            this.methodSigCreator.ParametersCreateTypeSigArray.TypeSigCreator.CanAddFnPtr      = false;

            this.customAttributesVM = new CustomAttributesVM(ownerModule, language, ownerType, ownerMethod);
            this.declSecuritiesVM   = new DeclSecuritiesVM(ownerModule, language, ownerType, ownerMethod);
            this.paramDefsVM        = new ParamDefsVM(ownerModule, language, ownerType, ownerMethod);
            this.genericParamsVM    = new GenericParamsVM(ownerModule, language, ownerType, ownerMethod);
            this.methodOverridesVM  = new MethodOverridesVM(ownerModule, language, ownerType, ownerMethod);

            this.origOptions = options;

            this.implMapVM             = new ImplMapVM(ownerModule);
            ImplMapVM.PropertyChanged += implMapVM_PropertyChanged;

            ImplMapVM.IsEnabled = PinvokeImpl;
            Reinitialize();
        }
Exemple #6
0
 void InitializeFrom(MethodDefOptions options)
 {
     ImplAttributes = options.ImplAttributes;
     Attributes = options.Attributes;
     Name = options.Name;
     MethodSig = options.MethodSig;
     ImplMap = options.ImplMap;
     CodeType.SelectedItem = (Method.CodeType)((int)(options.ImplAttributes & MethodImplAttributes.CodeTypeMask) >> 0);
     ManagedType.SelectedItem = (Method.ManagedType)((int)(options.ImplAttributes & MethodImplAttributes.ManagedMask) >> 2);
     MethodVisibility.SelectedItem = (Method.MethodVisibility)((int)(options.Attributes & MethodAttributes.MemberAccessMask) >> 0);
     VtableLayout.SelectedItem = (Method.VtableLayout)((int)(options.Attributes & MethodAttributes.VtableLayoutMask) >> 8);
     CustomAttributesVM.InitializeFrom(options.CustomAttributes);
     DeclSecuritiesVM.InitializeFrom(options.DeclSecurities);
     ParamDefsVM.InitializeFrom(options.ParamDefs);
     GenericParamsVM.InitializeFrom(options.GenericParameters);
     MethodOverridesVM.InitializeFrom(options.Overrides);
 }
Exemple #7
0
 MethodDefOptions CopyTo(MethodDefOptions options)
 {
     options.ImplAttributes = ImplAttributes;
     options.Attributes = Attributes;
     options.Name = Name;
     options.MethodSig = MethodSig;
     options.ImplMap = PinvokeImpl ? ImplMap : null;
     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.ParamDefs.Clear();
     options.ParamDefs.AddRange(ParamDefsVM.Collection.Select(a => a.CreateParamDefOptions().Create(ownerModule)));
     options.GenericParameters.Clear();
     options.GenericParameters.AddRange(GenericParamsVM.Collection.Select(a => a.CreateGenericParamOptions().Create(ownerModule)));
     options.Overrides.Clear();
     options.Overrides.AddRange(MethodOverridesVM.Collection.Select(a => a.CreateMethodOverrideOptions().Create()));
     if (ModelUtils.GetHasSecurityBit(options.DeclSecurities, options.CustomAttributes))
         options.Attributes |= MethodAttributes.HasSecurity;
     else
         options.Attributes &= ~MethodAttributes.HasSecurity;
     return options;
 }
Exemple #8
0
        public MethodOptionsVM(MethodDefOptions options, ModuleDef ownerModule, Language language, TypeDef ownerType, MethodDef ownerMethod)
        {
            this.ownerModule = ownerModule;
            var typeSigCreatorOptions = new TypeSigCreatorOptions(ownerModule, language) {
                IsLocal = false,
                CanAddGenericTypeVar = true,
                CanAddGenericMethodVar = ownerMethod == null || ownerMethod.GenericParameters.Count > 0,
                OwnerType = ownerType,
                OwnerMethod = ownerMethod,
            };
            if (ownerType != null && ownerType.GenericParameters.Count == 0)
                typeSigCreatorOptions.CanAddGenericTypeVar = false;

            var methodSigCreatorOptions = new MethodSigCreatorOptions(typeSigCreatorOptions);
            methodSigCreatorOptions.IsPropertySig = false;
            this.methodSigCreator = new MethodSigCreatorVM(methodSigCreatorOptions);
            this.methodSigCreator.PropertyChanged += methodSigCreator_PropertyChanged;
            this.methodSigCreator.ParametersCreateTypeSigArray.PropertyChanged += methodSigCreator_PropertyChanged;
            this.methodSigCreator.ParametersCreateTypeSigArray.TypeSigCreator.ShowTypeFullName = true;
            this.methodSigCreator.ParametersCreateTypeSigArray.TypeSigCreator.CanAddFnPtr = false;

            this.customAttributesVM = new CustomAttributesVM(ownerModule, language, ownerType, ownerMethod);
            this.declSecuritiesVM = new DeclSecuritiesVM(ownerModule, language, ownerType, ownerMethod);
            this.paramDefsVM = new ParamDefsVM(ownerModule, language, ownerType, ownerMethod);
            this.genericParamsVM = new GenericParamsVM(ownerModule, language, ownerType, ownerMethod);
            this.methodOverridesVM = new MethodOverridesVM(ownerModule, language, ownerType, ownerMethod);

            this.origOptions = options;

            this.implMapVM = new ImplMapVM(ownerModule);
            ImplMapVM.PropertyChanged += implMapVM_PropertyChanged;

            ImplMapVM.IsEnabled = PinvokeImpl;
            Reinitialize();
        }
Exemple #9
0
 CreateMethodDefCommand(TypeTreeNode ownerNode, MethodDefOptions options)
 {
     this.ownerNode = ownerNode;
     this.methodNode = new MethodTreeNode(options.CreateMethodDef(ownerNode.TypeDefinition.Module));
 }
Exemple #10
0
        MethodDefSettingsCommand(MethodTreeNode methodNode, MethodDefOptions options)
        {
            this.methodNode = methodNode;
            this.newOptions = options;
            this.origOptions = new MethodDefOptions(methodNode.MethodDefinition);

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

            this.nameChanged = origOptions.Name != newOptions.Name;
        }
Exemple #11
0
        MethodDefSettingsCommand(MethodTreeNode methodNode, MethodDefOptions options)
        {
            this.methodNode = methodNode;
            this.newOptions = options;
            this.origOptions = new MethodDefOptions(methodNode.MethodDefinition);

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

            this.nameChanged = origOptions.Name != newOptions.Name;
            if (this.nameChanged)
                this.memberRefInfos = RefFinder.FindMemberRefsToThisModule(ILSpyTreeNode.GetModule(methodNode)).Where(a => RefFinder.MethodEqualityComparerInstance.Equals(a, methodNode.MethodDefinition)).Select(a => new Field.MemberRefInfo(a)).ToArray();
        }
Exemple #12
0
 CreateMethodDefCommand(TypeTreeNode ownerNode, MethodDefOptions options)
 {
     this.ownerNode  = ownerNode;
     this.methodNode = new MethodTreeNode(options.CreateMethodDef(ownerNode.TypeDefinition.Module));
 }