You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LuCoreUtilsExtensions.cs 755B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using System.Linq;
  3. using System.Reflection;
  4. namespace Luticate2.Utils.Utils
  5. {
  6. public static class LuCoreUtilsExtensions
  7. {
  8. public static string ToSnakeCase(this string str)
  9. {
  10. if (str == null)
  11. {
  12. throw new ArgumentNullException(nameof(str));
  13. }
  14. return string.Concat(str.Select((x, i) => i > 0 && char.IsUpper(x) ? "_" + x.ToString() : x.ToString())).ToLower();
  15. }
  16. public static Guid? ToGuid(this string str)
  17. {
  18. return str == null ? (Guid?)null : new Guid(str);
  19. }
  20. public static bool HasProperty(this Type type, string name)
  21. {
  22. return type.GetProperty(name) != null;
  23. }
  24. }
  25. }