I am working on a C# net micro framework project, in particular an I2C bus class.I have several different I2C devices each defined in separate classes which contain all of the devices' unique methods. In my case, I can only have ONE I2CDevice object defined and to switch to another I2C device, I have to change the I2CDevice.Config = DeviceConfig.For example (pseudo-code):Class Device1 -DeviceConfig1-Method 1-Method 2-Method 3Class Device2-DeviceConfig2-Method 1-Method 2-Method 3Main Program{I2cBus = new I2CDevice(configuration)Device1.Method1Device2.Method3}When switching between devices, I need to change the I2CDevice.Config property. I'm looking for an elegant way such that whenever I call a Method for a device, that the I2CBus.Config is automatically changed. Is there a way that I don't need to re-type this config code in each method? Have a separate internal method that's called each time I access any of those methods?I hope my description is clear.Update, As an alternative, is there a way I can have my make my I2C Bus class and then ADD the devices to the this class? Then To access The Devices, I would Do something likeI2CBus.AddDevice(Device1ObjectClass)I2CBus.AddDevice(Device2ObjectClass)I2CBus.Device1.Method1I2CBus.Device2.Method2I still have the same problem that I need to automatically switch the I2C configuration between Different Device calls.
How to invoke a method in a class always when the class is accessed - like a reaction?
c#;class