static protected void VerifySectionName(string name, IConfigErrorInfo errorInfo, bool allowImplicit) {
if (String.IsNullOrEmpty(name)) {
throw new ConfigurationErrorsException(SR.GetString(SR.Config_tag_name_invalid), errorInfo);
}
// must be a valid name in xml, so that it can be used as an element
// n.b. - it also excludes forward slash '/'
try {
XmlConvert.VerifyName(name);
}
// Do not let the exception propagate as an XML exception,
// for we want errors in the section name to be treated as local errors,
// not global ones.
catch (Exception e) {
throw ExceptionUtil.WrapAsConfigException(SR.GetString(SR.Config_tag_name_invalid), e, errorInfo);
}
catch {
throw ExceptionUtil.WrapAsConfigException(SR.GetString(SR.Config_tag_name_invalid), null, errorInfo);
}
if (IsImplicitSection(name)) {
if (allowImplicit) {
// avoid test below for strings starting with "config"
return;
}
else {
throw new ConfigurationErrorsException(SR.GetString(SR.Cannot_declare_or_remove_implicit_section, name), errorInfo);
}
}
if (StringUtil.StartsWith(name, "config")) {
throw new ConfigurationErrorsException(SR.GetString(SR.Config_tag_name_cannot_begin_with_config), errorInfo);
}
if (name == KEYWORD_LOCATION) {
throw new ConfigurationErrorsException(SR.GetString(SR.Config_tag_name_cannot_be_location), errorInfo);
}
}