|
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using HealthMonitor.Util.Entities.Base;
- using HealthMonitor.Util.Entities.Interfaces;
-
- namespace HealthMonitor.Util.Common
- {
- public class EntityUtils
- {
- ///// <summary>
- ///// 根据实体主键类型,把参数转换为对应的类型
- ///// </summary>
- ///// <typeparam name="T"></typeparam>
- ///// <param name="value"></param>
- ///// <returns></returns>
- //public static object GetWrapKeyValue<T>(string value) where T : EntityBase
- //{
- // var type = typeof(T);
- // var ifs = type.GetInterfaces();
-
- // if (ifs.Contains(typeof(IKeyIntType)))
- // {
- // int key;
- // key = int.TryParse(value, out key) ? key : 0;
- // return key;
- // }
-
- // if (ifs.Contains(typeof(IKeyLongType)))
- // {
- // long key;
- // key = long.TryParse(value, out key) ? key : 0;
- // return key;
- // }
- // return value;
- //}
-
- //public static bool HasAutoGenerateKey<T>()
- //{
- // return HasAutoGenerateKey(typeof(T));
- //}
-
- public static bool HasAutoGenerateKey(Type type)
- {
- var ifs = type.GetInterfaces();
- var numericTypes = new List<Type> { typeof(IKeyIntType), typeof(IKeyLongType) };
- var manualTypes = new List<Type> { typeof(IKeyIntNeverGeneratedType), typeof(IKeyLongNeverGeneratedType) };
-
- if(ifs.Any(e => numericTypes.Contains(e)) && ifs.Any(e => manualTypes.Contains(e)) == false)
- {
- return true;
- }
- return false;
- }
- }
- }
|