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
{
/////
///// 根据实体主键类型,把参数转换为对应的类型
/////
/////
/////
/////
//public static object GetWrapKeyValue(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()
//{
// return HasAutoGenerateKey(typeof(T));
//}
public static bool HasAutoGenerateKey(Type type)
{
var ifs = type.GetInterfaces();
var numericTypes = new List { typeof(IKeyIntType), typeof(IKeyLongType) };
var manualTypes = new List { typeof(IKeyIntNeverGeneratedType), typeof(IKeyLongNeverGeneratedType) };
if(ifs.Any(e => numericTypes.Contains(e)) && ifs.Any(e => manualTypes.Contains(e)) == false)
{
return true;
}
return false;
}
}
}