ExtensionMethods.cs 997 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.Linq;
  3. namespace Unity.Cloud.Collaborate.Utilities
  4. {
  5. static class ExtensionMethods
  6. {
  7. // Credit: https://stackoverflow.com/a/4405876
  8. /// <summary>
  9. /// Take the first letter of the string and capitalise it.
  10. /// </summary>
  11. /// <param name="input">String to work with.</param>
  12. /// <returns>String with first letter capitalised.</returns>
  13. /// <exception cref="ArgumentNullException">If string is null.</exception>
  14. /// <exception cref="ArgumentException">If string is empty.</exception>
  15. public static string FirstCharToUpper(this string input)
  16. {
  17. switch (input)
  18. {
  19. case null: throw new ArgumentNullException(nameof(input));
  20. case "": throw new ArgumentException($"{nameof(input)} cannot be empty", nameof(input));
  21. default: return input.First().ToString().ToUpper() + input.Substring(1);
  22. }
  23. }
  24. }
  25. }