internal static string GetNormalizedTaxonomyName(string name, string argumentName) { ToolkitUtilities.ConfirmNotNull(name, argumentName); string normalizedName = Regex.Replace(name, @"\s+", " "); normalizedName = normalizedName.Replace('&', (char)0xff06).Replace('"', (char)0xff02); if (normalizedName.Length > 255) { throw new ArgumentException("The name length cannot exceed 255 characters: \"" + normalizedName + "\""); } normalizedName = normalizedName.Trim(); if (normalizedName.Length == 0) { throw new ArgumentException("The name cannot be empty"); } if (!ToolkitUtilities.validNameRegex.IsMatch(normalizedName)) { throw new ArgumentException("The name contains invalid characters: \"" + normalizedName + "\""); } return(normalizedName); }
/// <summary> /// This returns an enumerator that traverses a tree in the preorder sequence. /// The child nodes are specified by the <paramref name="getChildren" /> delegate. /// </summary> public static IEnumerable <T> GetPreorder <T>(T node, GetChildren <T> getChildren) { yield return(node); foreach (T child in getChildren(node)) { foreach (T item in ToolkitUtilities.GetPreorder(child, getChildren)) { yield return(item); } } }
/// <summary> /// TaxonomyItem.NormalizeName() replaces ampersands with a Unicode character. This form is /// used throughout the Taxonomy API and should be used in code, but when displayed in the /// UI it looks wrong in many fonts. You can use GetDenormalizedTaxonomyNameForDisplay() /// to convert it back to the regular ampersand. /// </summary> public static string GetDenormalizedTaxonomyNameForDisplay(string name) { ToolkitUtilities.ConfirmNotNull(name, "name"); return(name.Replace((char)0xff06, '&')); }
/// <summary> /// This performs a similar operation as TaxonomyItem.NormalizeName(), and also checks /// that the name is valid. /// </summary> public static string GetNormalizedTaxonomyName(string name) { return(ToolkitUtilities.GetNormalizedTaxonomyName(name, "name")); }