12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- 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 ToOptEnum<T>(this string model)
- {
- return model == null ? default(T) : (T) Enum.Parse(typeof(T), model);
- }
-
- public static T ToEnum<T>(this string model)
- {
- return (T) Enum.Parse(typeof(T), model);
- }
-
- public static Guid? ToOptGuid(this string str)
- {
- return str == null ? (Guid?)null : new Guid(str);
- }
-
- public static Guid ToGuid(this string str)
- {
- return 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();
- }
- }
- }
|