public PropertyOptionsVM(PropertyDefOptions options, ModuleDef ownerModule, Language language, TypeDef ownerType) { this.ownerModule = ownerModule; this.origOptions = options; var typeSigCreatorOptions = new TypeSigCreatorOptions(ownerModule, language) { IsLocal = false, CanAddGenericTypeVar = true, CanAddGenericMethodVar = true, OwnerType = ownerType, }; if (ownerType != null && ownerType.GenericParameters.Count == 0) { typeSigCreatorOptions.CanAddGenericTypeVar = false; } var methodSigCreatorOptions = new MethodSigCreatorOptions(typeSigCreatorOptions); methodSigCreatorOptions.IsPropertySig = true; this.methodSigCreator = new MethodSigCreatorVM(methodSigCreatorOptions); this.methodSigCreator.PropertyChanged += methodSigCreator_PropertyChanged; this.methodSigCreator.ParametersCreateTypeSigArray.PropertyChanged += methodSigCreator_PropertyChanged; this.methodSigCreator.ParametersCreateTypeSigArray.TypeSigCreator.CanAddFnPtr = false; this.getMethodsVM = new MethodDefsVM(ownerModule, language); this.setMethodsVM = new MethodDefsVM(ownerModule, language); this.otherMethodsVM = new MethodDefsVM(ownerModule, language); this.customAttributesVM = new CustomAttributesVM(ownerModule, language); this.constantVM = new ConstantVM(ownerModule, options.Constant == null ? null : options.Constant.Value, "Default value for this property"); this.constantVM.PropertyChanged += constantVM_PropertyChanged; ConstantVM.IsEnabled = HasDefault; Reinitialize(); }
public PropertyOptionsVM(PropertyDefOptions options, ModuleDef ownerModule, Language language, TypeDef ownerType) { this.ownerModule = ownerModule; this.origOptions = options; var typeSigCreatorOptions = new TypeSigCreatorOptions(ownerModule, language) { IsLocal = false, CanAddGenericTypeVar = true, CanAddGenericMethodVar = true, OwnerType = ownerType, }; if (ownerType != null && ownerType.GenericParameters.Count == 0) typeSigCreatorOptions.CanAddGenericTypeVar = false; var methodSigCreatorOptions = new MethodSigCreatorOptions(typeSigCreatorOptions); methodSigCreatorOptions.IsPropertySig = true; this.methodSigCreator = new MethodSigCreatorVM(methodSigCreatorOptions); this.methodSigCreator.PropertyChanged += methodSigCreator_PropertyChanged; this.methodSigCreator.ParametersCreateTypeSigArray.PropertyChanged += methodSigCreator_PropertyChanged; this.methodSigCreator.ParametersCreateTypeSigArray.TypeSigCreator.CanAddFnPtr = false; this.getMethodsVM = new MethodDefsVM(ownerModule, language); this.setMethodsVM = new MethodDefsVM(ownerModule, language); this.otherMethodsVM = new MethodDefsVM(ownerModule, language); this.customAttributesVM = new CustomAttributesVM(ownerModule, language); this.constantVM = new ConstantVM(ownerModule, options.Constant == null ? null : options.Constant.Value, "Default value for this property"); this.constantVM.PropertyChanged += constantVM_PropertyChanged; ConstantVM.IsEnabled = HasDefault; Reinitialize(); }
PropertyDefOptions CopyTo(PropertyDefOptions options) { options.Attributes = Attributes; options.Name = Name; options.PropertySig = PropertySig; options.Constant = HasDefault ? Constant : null; options.GetMethods.Clear(); options.GetMethods.AddRange(GetMethodsVM.Collection.Select(a => a.Method)); options.SetMethods.Clear(); options.SetMethods.AddRange(SetMethodsVM.Collection.Select(a => a.Method)); options.OtherMethods.Clear(); options.OtherMethods.AddRange(OtherMethodsVM.Collection.Select(a => a.Method)); options.CustomAttributes.Clear(); options.CustomAttributes.AddRange(CustomAttributesVM.Collection.Select(a => a.CreateCustomAttributeOptions().Create())); return(options); }
PropertyDefSettingsCommand(PropertyTreeNode propNode, PropertyDefOptions options) { this.propNode = propNode; this.newOptions = options; this.origOptions = new PropertyDefOptions(propNode.PropertyDefinition); this.origParentNode = (ILSpyTreeNode)propNode.Parent; this.origParentChildIndex = this.origParentNode.Children.IndexOf(propNode); Debug.Assert(this.origParentChildIndex >= 0); if (this.origParentChildIndex < 0) { throw new InvalidOperationException(); } this.nameChanged = origOptions.Name != newOptions.Name; }
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 options = PropertyDefOptions.Create(module, "MyProperty", isInstance); var data = new PropertyOptionsVM(options, module, MainWindow.Instance.CurrentLanguage, typeNode.TypeDefinition); var win = new PropertyOptionsDlg(); win.Title = "Create Property"; win.DataContext = data; win.Owner = MainWindow.Instance; if (win.ShowDialog() != true) { return; } UndoCommandManager.Instance.Add(new CreatePropertyDefCommand(typeNode, data.CreatePropertyDefOptions())); }
void InitializeFrom(PropertyDefOptions options) { Attributes = options.Attributes; Name = options.Name; PropertySig = options.PropertySig; if (options.Constant != null) { HasDefault = true; ConstantVM.Value = options.Constant.Value; } else { HasDefault = false; ConstantVM.Value = null; } GetMethodsVM.InitializeFrom(options.GetMethods); SetMethodsVM.InitializeFrom(options.SetMethods); OtherMethodsVM.InitializeFrom(options.OtherMethods); CustomAttributesVM.InitializeFrom(options.CustomAttributes); }
PropertyDefOptions CopyTo(PropertyDefOptions options) { options.Attributes = Attributes; options.Name = Name; options.PropertySig = PropertySig; options.Constant = HasDefault ? Constant : null; options.GetMethods.Clear(); options.GetMethods.AddRange(GetMethodsVM.Collection.Select(a => a.Method)); options.SetMethods.Clear(); options.SetMethods.AddRange(SetMethodsVM.Collection.Select(a => a.Method)); options.OtherMethods.Clear(); options.OtherMethods.AddRange(OtherMethodsVM.Collection.Select(a => a.Method)); options.CustomAttributes.Clear(); options.CustomAttributes.AddRange(CustomAttributesVM.Collection.Select(a => a.CreateCustomAttributeOptions().Create())); return options; }
CreatePropertyDefCommand(TypeTreeNode ownerNode, PropertyDefOptions options) { this.ownerNode = ownerNode; this.propNode = new PropertyTreeNode(options.CreatePropertyDef(ownerNode.TypeDefinition.Module)); }
PropertyDefSettingsCommand(PropertyTreeNode propNode, PropertyDefOptions options) { this.propNode = propNode; this.newOptions = options; this.origOptions = new PropertyDefOptions(propNode.PropertyDefinition); this.origParentNode = (ILSpyTreeNode)propNode.Parent; this.origParentChildIndex = this.origParentNode.Children.IndexOf(propNode); Debug.Assert(this.origParentChildIndex >= 0); if (this.origParentChildIndex < 0) throw new InvalidOperationException(); this.nameChanged = origOptions.Name != newOptions.Name; }