using static System.AttributeTargets; namespace InnovEnergy.Lib.Protocols.Modbus.Reflection.Attributes; [AttributeUsage(Field | Property)] public class ModbusAttribute : Attribute { public UInt16 Address { get; } public UInt16 Size { get; } public TypeCode ModbusType { get; } protected ModbusAttribute(UInt16 address, TypeCode modbusType) { Address = address; ModbusType = modbusType; Size = modbusType switch { TypeCode.Boolean => 1, TypeCode.Int16 => 1, TypeCode.UInt16 => 1, TypeCode.Int32 => 2, TypeCode.UInt32 => 2, TypeCode.Single => 2, TypeCode.Int64 => 4, TypeCode.UInt64 => 4, TypeCode.Double => 4, _ => throw new ArgumentException(nameof(modbusType)) }; } }