예제 #1
0
        /// <summary>
        /// Return possible variants of a name for name matching.
        /// </summary>
        /// <param name="name">String to convert</param>
        /// <param name="culture">The culture to use for conversion</param>
        /// <param name="options">The variants to try and match against (less is faster)</param>
        /// <returns>IEnumerable&lt;string&gt;</returns>
        public static IEnumerable<string> GetNameVariants(this string name, CultureInfo culture, NameVariants options)
        {
            if (String.IsNullOrEmpty(name))
                yield break;

            yield return name;

            // try pascal cased name
            if ((options & NameVariants.PascalCase) == NameVariants.PascalCase)
                yield return name.ToPascalCase(true, culture);

            // try camel cased name
            if ((options & NameVariants.CamelCase) == NameVariants.CamelCase)
                yield return name.ToCamelCase(culture);

            // try lower cased name
            if ((options & NameVariants.Lowercase) == NameVariants.Lowercase)
                yield return name.ToLower(culture);

            // try name with underscores
            if ((options & NameVariants.WithUnderscores) == NameVariants.WithUnderscores)
                yield return name.AddUnderscores();

            // try name with underscores with lower case
            if ((options & NameVariants.WithUnderscoresLowercase) == NameVariants.WithUnderscoresLowercase)
                yield return name.AddUnderscores().ToLower(culture);

            // try name with dashes
            if ((options & NameVariants.Dashes) == NameVariants.Dashes)
                yield return name.AddDashes();

            // try name with dashes with lower case
            if ((options & NameVariants.DashesLowercase) == NameVariants.DashesLowercase)
                yield return name.AddDashes().ToLower(culture);

            // try name with underscore prefix
            if ((options & NameVariants.UnderscorePrefix) == NameVariants.UnderscorePrefix)
                yield return name.AddUnderscorePrefix();

            // try name with underscore prefix, using camel case
            if ((options & NameVariants.UnderscorePrefixCamelCase) == NameVariants.UnderscorePrefixCamelCase)
                yield return name.ToCamelCase(culture).AddUnderscorePrefix();
        }
        /// <summary>
        /// Return possible variants of a name for name matching.
        /// </summary>
        /// <param name="name">String to convert</param>
        /// <param name="culture">The culture to use for conversion</param>
        /// <returns>IEnumerable&lt;string&gt;</returns>
        public static IEnumerable<string> GetNameVariants(this string name, CultureInfo culture)
        {
            if (string.IsNullOrEmpty(name))
                yield break;

            yield return name;

            // try camel cased name
            yield return name.ToCamelCase(culture);

            // try lower cased name
            yield return name.ToLower(culture);

            // try name with underscores
            yield return name.AddUnderscores();

            // try name with underscores with lower case
            yield return name.AddUnderscores().ToLower(culture);

            // try name with dashes
            yield return name.AddDashes();

            // try name with dashes with lower case
            yield return name.AddDashes().ToLower(culture);

            // try name with underscore prefix
            yield return name.AddUnderscorePrefix();

            // try name with underscore prefix, using camel case
            yield return name.ToCamelCase(culture).AddUnderscorePrefix();

            // try name with spaces
            yield return name.AddSpaces();

            // try name with spaces with lower case
            yield return name.AddSpaces().ToLower(culture);
        }
예제 #3
0
        /// <summary>
        /// Return possible variants of a name for name matching.
        /// </summary>
        /// <param name="name">String to convert</param>
        /// <param name="culture">The culture to use for conversion</param>
        /// <returns>IEnumerable&lt;string&gt;</returns>
        public static IEnumerable<string> GetNameVariants(this string name, CultureInfo culture)
        {
            if (string.IsNullOrEmpty(name))
            {
                yield break;
            }

            yield return name;

            // try camel cased name
            yield return name.ToCamelCase(culture);

            // try lower cased name
#if !WINDOWS_UWP
            yield return name.ToLower(culture);
#else
            yield return name.ToLowerInvariant();
#endif

            // try name with underscores
            yield return name.AddUnderscores();

            // try name with underscores with lower case
#if !WINDOWS_UWP
            yield return name.AddUnderscores().ToLower(culture);
#else
            yield return name.AddUnderscores().ToLowerInvariant();
#endif

            // try name with dashes
            yield return name.AddDashes();

            // try name with dashes with lower case
#if !WINDOWS_UWP
            yield return name.AddDashes().ToLower(culture);
#else
            yield return name.AddDashes().ToLowerInvariant();
#endif

            // try name with underscore prefix
            yield return name.AddUnderscorePrefix();

            // try name with underscore prefix, using camel case
            yield return name.ToCamelCase(culture).AddUnderscorePrefix();

            // try name with spaces
            yield return name.AddSpaces();

            // try name with spaces with lower case
#if !WINDOWS_UWP
            yield return name.AddSpaces().ToLower(culture);
#else
            yield return name.AddSpaces().ToLowerInvariant();
#endif

            yield return name.ReplaceInvalidSpecialCharacters().ToLowerInvariant();
        }