using System;
namespace AMWD.Protocols.Modbus.Common
{
///
/// Represents the base of all Modbus specific objects.
///
public abstract class ModbusObject
{
///
/// Gets the type of the object.
///
public abstract ModbusObjectType Type { get; }
///
/// Gets or sets the address of the object.
///
public ushort Address { get; set; }
///
/// Gets or sets the high byte of the value.
///
public byte HighByte { get; set; }
///
/// Gets or sets the low byte of the value.
///
public byte LowByte { get; set; }
///
public override bool Equals(object obj)
{
if (obj is not ModbusObject mo)
return false;
return Type == mo.Type
&& Address == mo.Address
&& HighByte == mo.HighByte
&& LowByte == mo.LowByte;
}
///
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public override int GetHashCode()
{
#if NET6_0_OR_GREATER
return HashCode.Combine(Type, Address, HighByte, LowByte);
#else
return Type.GetHashCode()
^ Address.GetHashCode()
^ HighByte.GetHashCode()
^ LowByte.GetHashCode();
#endif
}
}
}