您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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. }