Skip to content

Commit bbad46f

Browse files
committed
Merge pull request #497 from Naliath/master
Added additional variants to look for on deserialization
2 parents c963c78 + 1a7c56b commit bbad46f

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
@@ -359,6 +359,19 @@ public static string AddUnderscorePrefix(this string pascalCasedWord)
359359
return string.Format("_{0}", pascalCasedWord);
360360
}
361361

362+
/// <summary>
363+
/// Add spaces to a pascal-cased string
364+
/// </summary>
365+
/// <param name="pascalCasedWord">String to convert</param>
366+
/// <returns>string</returns>
367+
public static string AddSpaces(this string pascalCasedWord)
368+
{
369+
return
370+
Regex.Replace(
371+
Regex.Replace(Regex.Replace(pascalCasedWord, @"([A-Z]+)([A-Z][a-z])", "$1 $2"), @"([a-z\d])([A-Z])",
372+
"$1 $2"), @"[-\s]", " ");
373+
}
374+
362375
/// <summary>
363376
/// Return possible variants of a name for name matching.
364377
/// </summary>
@@ -395,6 +408,12 @@ public static IEnumerable<string> GetNameVariants(this string name, CultureInfo
395408

396409
// try name with underscore prefix, using camel case
397410
yield return name.ToCamelCase(culture).AddUnderscorePrefix();
411+
412+
// try name with spaces
413+
yield return name.AddSpaces();
414+
415+
// try name with spaces with lower case
416+
yield return name.AddSpaces().ToLower(culture);
398417
}
399418
}
400419
}

0 commit comments

Comments
 (0)