using System.Reflection; using NetTaste; namespace DS.Module.Core; /// /// 实体帮助类 /// public static class EntityUtil { //获取实体类型 public static Type getEntity(string typeName) { var workPath = AppDomain.CurrentDomain.BaseDirectory; string[] files = Directory.GetFiles(workPath, "DS.WMS.Core.dll", SearchOption.TopDirectoryOnly); foreach (string file in files) { string ext = file.Substring(file.LastIndexOf(".")); if (ext != ".dll") continue; try { Assembly asm = Assembly.LoadFile(file); Type[] allTypes = asm.GetTypes(); foreach (Type t in allTypes) { if (t.Name.ToUpper() == typeName.ToUpper()) return t; // if (t.IsSubclassOf(typeof(XXDataRecord))) // { // if (t.Name.ToUpper().IsSame(typeName.ToUpper())) // return t; // } } } catch { return null; } } return null; } /// /// /// /// /// /// public static T CreateInstance(Type t) { dynamic obj = Activator.CreateInstance(t); return (T)obj; } }