School类
namespace Common
{
public class School
{
public string SchoolNO { get; set; }
public string SchoolName { get; set; }
}
}
Student类
namespace Common
{
public class Student
{
public string StudentNO { get; set; }
public string StudentName { get; set; }
}
}
业务方法
namespace Bll
{
public class TestBll
{
public bool Test<T>(string strWhere) where T : class, new()
{
//根据查询条件、对象类型获取数据
// List<T> list = myDbContext.MDM.Queryable<T>().Where(whereStr).ToList();
return true;
}
}
}
调用
using System.Reflection;
namespace ConsoleApp9
{
class Program
{
static void Main(string[] args)
{
string CommonAssembly =
"Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
string BllAssembly =
"Bll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";
string[] tables = { "School", "Student" };
foreach (string table in tables)
{
// 实例化实体类
object entity = Assembly.Load(CommonAssembly)
.CreateInstance("Common." + table);
// 实例化业务类
object TestBll = Assembly.Load(BllAssembly)
.CreateInstance("Bll.TestBll");
// 初始化参数
object[] para = new object[] { "where 1=1" };
// 调用方法
var result = TestBll.GetType().GetMethod("Test")
.MakeGenericMethod(entity.GetType()).Invoke(TestBll, para);
}
}
}
}