/// <summary> /// 写入数据表至Database对象 /// </summary> /// <param name="tableName">数据表名称</param> /// <param name="database">数据库对象</param> /// <param name="lstTypes">C#类型集合</param> /// <param name="logAction">日志委托</param> public static void SetCoreDataBaseTableItems(string tableName, Air.CodeGeneration.Data.Core.Model.Database database, List <Type> lstTypes, Action <string> logAction = null) { Air.CodeGeneration.Data.Core.Model.DatabaseTable table = new Air.CodeGeneration.Data.Core.Model.DatabaseTable(); Type t = lstTypes.Find(p => p.Name == tableName); table.Name = t.Name; table.FieldItems = new List <Air.CodeGeneration.Data.Core.Model.DatabaseTableField>(); table.FieldRuleItems = new List <Air.CodeGeneration.Data.Core.Attribute.DataBaseFieldRuleAttribute>(); Air.CodeGeneration.Data.Core.Attribute.DataBaseTableRuleAttribute attributeTable = t.GetCustomAttribute <Air.CodeGeneration.Data.Core.Attribute.DataBaseTableRuleAttribute>(); if (attributeTable == null) { return; } if (attributeTable.IsCreateGnore) { return; } List <PropertyInfo> lstField = t.GetProperties() .Where(p => p.GetCustomAttribute <Air.CodeGeneration.Data.Core.Attribute.DataBaseFieldRuleAttribute>() != null) .ToList(); foreach (var field in lstField) { Air.CodeGeneration.Data.Core.Attribute.DataBaseFieldRuleAttribute attribute = field.GetAttribute <Air.CodeGeneration.Data.Core.Attribute.DataBaseFieldRuleAttribute>(); if (attribute.IsCreateGnore) { continue; } if (attribute.Name.IsNullOrWhiteSpace()) { attribute.Name = field.Name; } if (attribute.DataType.IsNullOrWhiteSpace()) { logAction($"类型[{t.Name}]下的字段[{attribute.Name}]未指定数据类型!生成该类型的建表脚本失败!"); continue; } table.FieldRuleItems.Add(attribute); } database.TableItems.Add(table); }
/// <summary> /// 获取反射DLL后的类型集合DataTable /// </summary> /// <param name="assemblyPath"></param> /// <param name="lstTypes"></param> /// <param name="platform"></param> /// <returns></returns> public static DataTable GetTypeDataTable(string assemblyPath, ref List <Type> lstTypes, int platform = 1) { DataTable dt = new DataTable(); lstTypes = ReflectHandler.GetTypeList(assemblyPath); List <TypeReflectDto> lstDto = new List <TypeReflectDto>(); if (platform != 1 && platform != 2) { throw new Exception($"无效的入参[{nameof(platform)}]"); } for (int i = 0; i < lstTypes.Count; i++) { if (platform == 1) { Air.CodeGeneration.Data.Core.Attribute.DataBaseTableRuleAttribute attr = lstTypes[i].GetCustomAttribute <Air.CodeGeneration.Data.Core.Attribute.DataBaseTableRuleAttribute>(); if (attr == null) { continue; } if (attr.IsCreateGnore) { continue; } } if (platform == 2) { Air.CodeGeneration.Data.Attribute.DataBaseTableRuleAttribute attr = lstTypes[i].GetCustomAttribute <Air.CodeGeneration.Data.Attribute.DataBaseTableRuleAttribute>(); if (attr == null) { continue; } if (attr.IsCreateGnore) { continue; } } TypeReflectDto item = new TypeReflectDto(); item.Sort = i + 1; item.Name = lstTypes[i].Name; item.FieldCount = lstTypes[i].GetProperties().Count().ToString(); item.IsSel = true; lstDto.Add(item); } if (lstDto != null && lstDto.Count > 1) { lstDto.Add(new TypeReflectDto() { FieldCount = "", IsSel = true, Sort = lstDto.Count + 1, Name = "全选" }); } dt = lstDto.ToDataTable(); return(dt); }