I'm having issues on how to seperate property values and their accessors. I have some electronic instruments encapsulated into classes. Some wrap a DLL which was provided by the manufacturer to handle communications.
A simple example:
public class Instrument
{
private ManufacturerDLL.Instrument _instrument;
public Instrument()
{
_instrument = new ManufacturerDLL.Instrument;
}
public float SomeSetting
{
get
{
return _instrument.SomeSetting;
}
set
{
_instrument.SomeSetting = value;
}
}
}
Once connected, I can edit the properties with a propertygrid. I want to use serialization to not only save/restore the settings to a file, but also edit the settings with the device offline. With the implementation above, exceptions will throw if the device is not connected. I could add private fields as a middle man and if statements to check for connection status. But I have a lot of properties and hope there is a better way.
Is there an easy method to construct an 'abstract' version of an object? I basically want a clone but replace the original accessors logic with private fields. I know I can use GetMembers, but where to go from there?
Instrumentimplement any interfaces? In case it does, you could try to generate a proxy.