protected override void OnNameChanged(EventArgs e)
        {
            // When the name changes, set the XML name to the same name but camelCased.
            this.XmlSectionName = NamingHelper.ToCamelCase(this.Name);

            // Always call the base class method.
            base.OnNameChanged(e);
        }
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            ConfigurationElementCollectionHasItemType link = e.ModelElement as ConfigurationElementCollectionHasItemType;

            if (link != null && !link.Store.TransactionManager.CurrentTransaction.IsSerializing)
            {
                // When the item type changes, set the XML item name to the new item type's name but camelCased.
                link.ConfigurationElementCollection.XmlItemName = NamingHelper.ToCamelCase(link.ConfigurationElement.Name);
            }
        }
Exemplo n.º 3
0
        protected override void OnNameChanged(EventArgs e)
        {
            // When the name changes, set the XML name to the same name but camelCased.
            this.XmlSectionName = NamingHelper.ToCamelCase(this.Name);

            // Always call the base class method.
            base.OnNameChanged(e);

            /*
             * foreach (BaseConfigurationType type in this.ConfigurationSectionModel.ConfigurationElements)
             * {
             *  var element = type as ConfigurationElement;
             *  IConfigSectionElement configSectionElement = type as IConfigSectionElement;
             * }*/
        }
            protected override void OnValueChanged(ConfigurationProperty element, string oldValue, string newValue)
            {
                if (!element.Store.InUndoRedoOrRollback)
                {
                    // Hard validation of the new name.
                    if (string.IsNullOrEmpty(newValue))
                    {
                        throw new ArgumentException("The Name is required and cannot be an empty string.", newValue);
                    }

                    // 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);
            }
            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);
            }