private static string GetTableName(Type type) { //检测类型是否为泛型 if (type.GetType().IsGenericType) {//取出泛型类型 var types = type.GetGenericArguments(); type = types.FirstOrDefault(); }
var name = type.GetAttribute<TableNameAttribute>()?.Name; if (string.IsNullOrEmpty(name))//找不到标记名称取类型名称 { name = type.Name; } return name; }