private void ValidateName(ValidationContext context) { Debug.WriteLine("ConfigurationProperty.ValidateName called for " + this.Name); // CALLED! // TODO: Should verify IsDefaultCollection validition is enforced or check if parent element is a collection. NamingHelper.ValidationOptions options = NamingHelper.ValidationOptions.None; if (NamingHelper.RequiresValidation(this.Name, this, out options)) { Debug.WriteLine(" - ConfigurationProperty.ValidateName: Reqiures validation!"); string msg = ""; if (!NamingHelper.TryValidateAttributesItemNameProperty(this.Name, this.Name, options, out msg)) { context.LogError(msg, "RequiredProperty", this); } } }
protected override void OnValueChanged(ConfigurationProperty element, string oldValue, string newValue) { /* * // Accessing validator. * Microsoft.VisualStudio.Modeling.Shell.VsValidationController validator = new Microsoft.VisualStudio.Modeling.Shell.VsValidationController(element.Store); * if (!validator.Validate(element.Store, ValidationCategories.Menu)) * { * element.Store.TransactionManager.CurrentTransaction.Rollback(); * System.Windows.Forms.MessageBox.Show(validator.ValidationMessages.First().Description); * } */ //bool isParentCollection = this.FindAncestor<ConfigurationElementCollection>( // Don't run in an undo or when store is loading from file (CSD with issue could never open!). if (!element.Store.InUndoRedoOrRollback && !element.Store.InSerializationTransaction) { newValue = newValue.Trim(); // Trim and set new value in case user adds spaces by accident. element.Name = newValue; // Hard validation of the new name. //NamingHelper.ValidateRequiredName(newValue); // TODO: Should verify IsDefaultCollection validition is enforced or check if parent element is a collection. NamingHelper.ValidationOptions options = NamingHelper.ValidationOptions.None; if (NamingHelper.RequiresValidation(newValue, element, out options)) { string msg = ""; if (!NamingHelper.TryValidateAttributesItemNameProperty(newValue, newValue, options, out msg)) { throw new ArgumentException(msg, "RequiredProperty"); } } // When the name changes, set the XML name to the same name but camelCased. element.XmlName = NamingHelper.ToCamelCase(element.Name); } // Always call the base class method. base.OnValueChanged(element, oldValue, newValue); }