所以我有一个Visual Studio解决方案,其中包含3个项目:
代码:
App.config-应用设置
添加key =“ EmployeeMemoryProvider” value =“ EmployeeMemoryProvider.MemoryProvider,EmployeeMemoryProvider”
EmployeeViewModel.cs-构造函数:
public EmployeeViewModel()
{
var configString = ConfigurationManager.AppSettings["EmployeeMemoryProvider"];
_employeeBLL = new EmployeeBLL(configString);
var employeeList = new ObservableCollection<Employee>(_employeeBLL.GetAllEmployess());
}
}
EmployeeBLL.cs,构造函数:
public EmployeeBLL(string configString)
{
var providerType = Type.GetType(configString);
_employeeProvider = (IEmployeeProvider)Activator.CreateInstance(providerType);
}
目标: 我想从App.config获取字符串的类型,该字符串首先在 EmployeeViewModel.cs 作为 configString ,然后传递到 EmployeeBLL.cs 的构造函数中,最后使用 Type.GetType(configString)来获取的类型> configString
问题:即使DAL项目的程序集名称和名称空间均为 EmployeeMemoryProvider , providerType 返回null。
谁能阐明一些想法?是因为我错过了“ EmployeeMemoryProvider.MemoryProvider,EmployeeMemoryProvider” 中逗号后的空格吗?