C#.NET反射调用静态类中的方法
C# 全选
public static UpgraderDbContext CreateDatabase(UpgraderConfig config)
{
var ns = "CSFramework.AutoUpgrader.DAL.UpgraderDbContext_" + config.DatabaseType;
Type type = typeof(UpgraderDbContext).Assembly.GetType(ns, false, true);
if (type == null)
{
throw new Exception("无法识别的数据库类型,创建数据库连接失败!");
}
//C#.NET反射调用静态类中的方法
var obj = type.InvokeMember("CreateDbContext",
BindingFlags.Public |
BindingFlags.Static |
BindingFlags.InvokeMethod,
null,
null,
new object[] { config });
return obj as UpgraderDbContext;
}
C# 全选
public class CSFramework.AutoUpgrader.DAL.UpgraderDbContext_SqlServer
{
/// <summary>
/// 公共静态方法
/// </summary>
/// <param name="config"></param>
/// <returns></returns>
public static UpgraderDbContext CreateDbContext(UpgraderConfig config)
{
}
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网