屠宰场客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
namespace ButcherManage.BO.Utils
{
public static class FormUtil
{
public static Form CreateFrom()
{
//var dll = Path.Combine(Environment.CurrentDirectory, "ButcherManage.Form.dll");
var dll = Path.Combine(@"C:\BwpB3Project\src\B3ButcherManageClient\ButcherManage.Form\bin\Debug", "ButcherManage.Form.dll");
if (!File.Exists(dll))
throw new Exception("缺少必要的程序集文件 ButcherManage.Form.dll");
var formType = typeof(IWithRoleForm);
Form form = null;
foreach (var type in Assembly.LoadFile(dll).GetTypes())
{
if (formType.IsAssignableFrom(type))
{
var instance = (IWithRoleForm)Activator.CreateInstance(type);
foreach (var item in instance.RoleName)
{
if (AppContext.Worker.RoleList.Contains(item))
return instance.Generate();
}
}
}
return form;
}
}
public interface IWithRoleForm
{
List<short> RoleName { get; }
Form Generate();
}
}