A
Anders Eriksson
I need to be able to switch between two different types of IO.
HardIO which communicates with actual hardware on the computer
and SoftIO which uses Tcp/Ip to communicate with an another
device. The selection of which type of IO is done on upstart and
will not change during the run of the program.
I have these classes(see below) and using
delegate int getPort(int port);
delegate int setPort(int port, int mask);
getPort = HardIO.GetPort;
setPort = HardIO.SetPort;
or
getPort = SoftIO.GetPort;
setPort = SoftIO.SetPort;
I can connect the delegates to the chosen class methods.
My question: Is there someway of connecting a delegate to the class?
In this sample there are only two methods but if I have a class with
20 methods I need 20 delegates...
There surely must be a better way?
// Anders
interface IBitIO
{
int GetPort(int port);
bool SetPort(int port, int mask);
}
public class HardIO : IBitIO
{
public static int GetPort(int port)
{
// implementation
}
public static bool SetPort(int port, int mask)
{
// implementation
}
}
public class SoftIO : IBitIO
{
public static int GetPort(int port)
{
// implementation
}
public static bool SetPort(int port, int mask)
{
// implementation
}
}
HardIO which communicates with actual hardware on the computer
and SoftIO which uses Tcp/Ip to communicate with an another
device. The selection of which type of IO is done on upstart and
will not change during the run of the program.
I have these classes(see below) and using
delegate int getPort(int port);
delegate int setPort(int port, int mask);
getPort = HardIO.GetPort;
setPort = HardIO.SetPort;
or
getPort = SoftIO.GetPort;
setPort = SoftIO.SetPort;
I can connect the delegates to the chosen class methods.
My question: Is there someway of connecting a delegate to the class?
In this sample there are only two methods but if I have a class with
20 methods I need 20 delegates...
There surely must be a better way?
// Anders
interface IBitIO
{
int GetPort(int port);
bool SetPort(int port, int mask);
}
public class HardIO : IBitIO
{
public static int GetPort(int port)
{
// implementation
}
public static bool SetPort(int port, int mask)
{
// implementation
}
}
public class SoftIO : IBitIO
{
public static int GetPort(int port)
{
// implementation
}
public static bool SetPort(int port, int mask)
{
// implementation
}
}