![](/img/trans.png)
[英]C# How to call the base class == operator, without explicitly typecasting?
[英]How to call constructor of the generic class explicitly in c#
我有下面的类,如何显式调用该类的构造函数?
[TestFixture(typeof(ChromeDriver))]
public class BaseWebDriver<TWebDriver> where TWebDriver : IWebDriver, new()
{
public IWebDriver Driver { get; set; }
public WebDriverWait wait;
public BaseWebDriver()
{
Driver = new TWebDriver();
}
[OneTimeSetUp]
public virtual void SetupTest()
{
// Go to the login page
Driver.Navigate().GoToUrl("LoginUrl");
}
[OneTimeTearDown]
public virtual void TearDownTest()
{
Driver.Quit();
Driver.Dispose();
Console.WriteLine("***TearDown***\n");
}
public void restartBrowser()
{
Driver.Quit();
//Here I have to call the constructor of the class to open the browser again
}
}
是否可以从派生类调用构造函数? 我是泛型新手,请帮忙。
如Andrew所说,Driver = new TWebDriver()有效。 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.