private void ValidateXmlName(ValidationContext context)
 {
     if (string.IsNullOrEmpty(this.XmlSectionName))
     {
         context.LogError("The Xml Section Name is required and cannot be an empty string.", "RequiredProperty", this);
     }
     if (!NamingHelper.IsValidXmlName(this.Name))
     {
         context.LogError(string.Format(Resources.Error_InvalidName_FormatString, "Xml Section"), "RequiredProperty", this);
     }
 }
示例#2
0
 private void ValidateNamespaces(ValidationContext context)
 {
     if (string.IsNullOrEmpty(this.Namespace))
     {
         context.LogError("The Namespace is required and cannot be an empty string.", "RequiredProperty", this);
     }
     if (!NamingHelper.IsValidName(this.Namespace))
     {
         context.LogError(Resources.Error_InvalidNamespace, "RequiredProperty", this);
     }
     if (string.IsNullOrEmpty(this.XmlSchemaNamespace))
     {
         context.LogError("The XML Schema Namespace is required and cannot be an empty string.", "RequiredProperty", this);
     }
     if (!NamingHelper.IsValidXmlName(this.XmlSchemaNamespace))
     {
         context.LogError(Resources.Error_InvalidXmlNamespace, "RequiredProperty", this);
     }
 }
            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);
                    }

                    if (!NamingHelper.IsValidXmlName(newValue))
                    {
                        throw new ArgumentException(Resources.Error_InvalidName, 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);
            }