Skip to content

Commit 1a7c56b

Browse files
committed
Add additional way to proccess enum values
1 parent ef43aae commit 1a7c56b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

RestSharp/Extensions/StringExtensions.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,19 @@ public static string AddUnderscorePrefix(this string pascalCasedWord)
355355
return string.Format("_{0}", pascalCasedWord);
356356
}
357357

358+
/// <summary>
359+
/// Add spaces to a pascal-cased string
360+
/// </summary>
361+
/// <param name="pascalCasedWord">String to convert</param>
362+
/// <returns>string</returns>
363+
public static string AddSpaces(this string pascalCasedWord)
364+
{
365+
return
366+
Regex.Replace(
367+
Regex.Replace(Regex.Replace(pascalCasedWord, @"([A-Z]+)([A-Z][a-z])", "$1 $2"), @"([a-z\d])([A-Z])",
368+
"$1 $2"), @"[-\s]", " ");
369+
}
370+
358371
/// <summary>
359372
/// Return possible variants of a name for name matching.
360373
/// </summary>
@@ -391,6 +404,12 @@ public static IEnumerable<string> GetNameVariants(this string name, CultureInfo
391404

392405
// try name with underscore prefix, using camel case
393406
yield return name.ToCamelCase(culture).AddUnderscorePrefix();
407+
408+
// try name with spaces
409+
yield return name.AddSpaces();
410+
411+
// try name with spaces with lower case
412+
yield return name.AddSpaces().ToLower(culture);
394413
}
395414
}
396415
}

0 commit comments

Comments
 (0)