我正在尝试在一些自动化测试中使用浏览器特定的 resx 文件。我被困在我希望实例化类型的地方。谁能指出我正确的方向?我已经尝试了 activator.createInstance 等......没有运气。
public class WebAiiBaseTest : BaseTest
{
private readonly IDictionary<BrowserType, Type> resxMapper = new Dictionary<BrowserType, Type>{
{BrowserType.Chrome, typeof(Chrome)}
, {BrowserType.Safari, typeof(Safari)}
, {BrowserType.FireFox, typeof(Firefox)}
, {BrowserType.InternetExplorer, typeof(InternetExplorer)}
};
[TestFixtureSetUp]
public void FixtureSetup()
{
Initialize();
Launcher.LaunchRepairInformation();
}
[TearDown]
public void TestCleanUp()
{
Launcher.NavigateToRepairInformation();
}
[TestFixtureTearDown]
public void FixtureCleanup()
{
CleanUp();
}
protected object BrowserResx
{
get { return Activator.CreateInstance(resxMapper[ActiveBrowser.BrowserType]); }
}
}
此代码返回一个实例,但它是对象类型。我想返回一个强类型实例。我已经尝试过 CreateInstance 的通用重载,就像这样
return Activator.CreateInstance<resxMapper[ActiveBrowser.BrowserType]>();
但 Visual Studio 不喜欢这种语法。我在这里做错了什么?感谢您提供任何提示或建议。
干杯,
~ck 在圣地亚哥