I’m trying to create set of interfaces that will be used in several classes. But I have troubles with setting them properly. I want to keep them generic.
I tried to get around this using dynamic type and object type without success. Maybe this will be clear with attached those interfaces below:
In code below type T is unknown. I cannot specify it because each IDeviceParameter will be different type. And number of parameters is not fixed, so I want to simply add all available IParameters to list. Only solution that came into my mind is to use some sort of boxing/unboxing (for example cast int to object and vice versa) or use dynamic. Or to totally change those interfaces. Thanks you in advance for any advises.
public interface IDevice : IDisposable { string Name { get; } bool Close(); Guid DeviceGuid { get; } IList<IDeviceParameter<T>>AvailableParameters { get; } IList<IDeviceCommand> AvailableCommands { get; } } public interface IDeviceParameter<T> { event EventHandler<IDeviceParameter<T>> ParameterValueChanged; event EventHandler<Exception> ParameterNotSet; string ParameterName { get; } string ParameterValue { get; } string ParameterUnit { get; } bool IsReadOnly { get; } T Parameter { get; } void SetParameter(T value); }