2 Replies - 253 Views - Last Post: 30 October 2017 - 05:11 AM Rate Topic: -----

#1 shinyme  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-October 17

reference & access question. Passing function from form to class.

Posted 29 October 2017 - 01:00 PM

I know this is basics. However, I can't figure this out. I have declared "driver" to be my Firefox web browser in a "Form1 class". How can I access this same web browser from new item class "X.cs" without re-declaring it or oping a new window?

public partial class Form1 : Form    
{        
public static IWebDriver driver = new FirefoxDriver();

Is This A Good Question/Topic? 0
  • +

Replies To: reference & access question. Passing function from form to class.

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13485
  • View blog
  • Posts: 53,843
  • Joined: 12-June 08

Re: reference & access question. Passing function from form to class.

Posted 29 October 2017 - 01:09 PM

You could always pass it into the declaration of another class.
Was This Post Helpful? 1
  • +
  • -

#3 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon


Reputation: 6979
  • View blog
  • Posts: 14,600
  • Joined: 16-October 07

Re: reference & access question. Passing function from form to class.

Posted 30 October 2017 - 05:11 AM

If you're going to insist on public static IWebDriver driver I'd put it in class to hold such things.

Something like:
public static class AppGlobal {
   private static IWebDriver driverInstance = null;
   public static IWebDriver Driver {
       get {
           if(driverInstance == null) { driverInstance = new FirefoxDriver(); }
           return driverInstance;
       }
   }
}



However, ideally, you just pass an instance to anything that needed it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1