You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
using System.Reflection;
|
|
using NetTaste;
|
|
|
|
namespace DS.Module.Core;
|
|
|
|
/// <summary>
|
|
/// 实体帮助类
|
|
/// </summary>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="t"></param>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <returns></returns>
|
|
public static T CreateInstance<T>(Type t)
|
|
{
|
|
dynamic obj = Activator.CreateInstance(t);
|
|
return (T)obj;
|
|
}
|
|
} |