簡體   English   中英

如何在C#中顯式調用泛型類的構造函數

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM