lundi 11 avril 2016

How to dynamically instantiate an object from different reference files

using InstrumentA.Interop;
using InstrumentB.Interop;
using InstrumentC.Interop;

namespace SomeProject
{
    class Program
    {
        void InitializeInstruments()
        {
            //I want to be able to instantiate whatever driver I want: (just one of them)
            InstrumentA.Interop.DriverA driver = new InstrumentA.Interop.DriverA();
            InstrumentB.Interop.DriverB driver = new InstrumentB.Interop.DriverB();
            InstrumentC.Interop.DriverC driver = new InstrumentC.Interop.DriverC();
            //or some instrumentD,E, F that users can choose to add.

            driver.Initialize();
            driver.DoOtherStuffs();
        }
    }
}

As you can see from the code above, how can I make it so that I can choose to instantiate which class I want, and name it driver?





Aucun commentaire:

Enregistrer un commentaire