123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using System;
- using System.Linq;
- using System.Reflection;
-
- namespace Luticate2.Utils.Utils
- {
- public static class LuCoreUtilsExtensions
- {
- public static bool HasProperty(this Type type, string name)
- {
- return type.GetProperty(name) != null;
- }
-
- public static string ToSnakeCase(this string str)
- {
- if (str == null)
- {
- throw new ArgumentNullException(nameof(str));
- }
- return string.Concat(str.Select((x, i) => i > 0 && char.IsUpper(x) ? "_" + x.ToString() : x.ToString())).ToLower();
- }
-
- public static T ToEnum<T>(this string model)
- {
- return (T) Enum.Parse(typeof(T), model);
- }
-
- public static Guid? ToGuid(this string str)
- {
- return str == null ? (Guid?)null : new Guid(str);
- }
-
- public static string ToDbo(this Guid model)
- {
- return model.ToString();
- }
-
- public static string ToDbo(this Guid? model)
- {
- return model?.ToDbo();
- }
-
- public static DateTime ToDbo(this DateTime model)
- {
- return model.ToLocalTime().ToUniversalTime();
- }
-
- public static DateTime? ToDbo(this DateTime? model)
- {
- return model?.ToDbo();
- }
-
- public static DateTime ToModel(this DateTime model)
- {
- return model.ToUniversalTime();
- }
-
- public static DateTime? ToModel(this DateTime? model)
- {
- return model?.ToModel();
- }
- }
- }
|