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#

11 months ago
using System.Reflection;
using NetTaste;
11 months ago
11 months ago
namespace DS.Module.Core;
11 months ago
/// <summary>
/// 实体帮助类
/// </summary>
public static class EntityUtil
11 months ago
{
10 months ago
//获取实体类型
11 months ago
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;
}
10 months ago
/// <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;
}
11 months ago
}