Это упрощенный пример. У меня есть абстрактный класс < /p>
Код: Выделить всё
public abstract class A
{
protected virtual ushort MinRegister => 0;
protected virtual ushort MinRegister => 0;
}
Код: Выделить всё
public class B : A
{
protected override ushort MinRegister => Functions.GetTemperature;
protected override ushort MaxRegister => Functions.SetHumidity;
class MODBUSRegisterAddresses // register addresses
{
public const ushort GetTemperature = 0;
public const ushort GetHumidity = 10;
public const ushort SetTemperature = 300;
public const ushort SetHumidity = 310;
}
}
Код: Выделить всё
values = ReadRegisters(device.SlaveAddress, RegisterMin, (ushort)(RegisterMax - RegisterMin + 1));
Код: Выделить всё
public abstract class A
{
internal static class MODBUSRegisterAddresses { }
private readonly Lazy getFunctions = new Lazy(() =>
{
return typeof(MODBUSRegisterAddresses).GetFields(
System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.Static |
System.Reflection.BindingFlags.FlattenHierarchy).
Where(fi => fi.IsLiteral && !fi.IsInitOnly).
Select(fi => fi.GetValue(null)).
OfType().
Distinct();
});
Подробнее здесь: https://stackoverflow.com/questions/797 ... ived-class
Мобильная версия