Add non-generic GetValue and improve documentation

This commit is contained in:
Peter Butzhammer
2024-04-26 09:23:51 +02:00
parent 99cf9cbc12
commit f5a51c074f
3 changed files with 175 additions and 43 deletions

View File

@@ -22,4 +22,23 @@ internal static class VariableAddressExtensions
public static bool MatchesType(this VariableAddress address, Type type) =>
supportedTypeMap.TryGetValue(type, out var map) && map(address);
public static Type GetClrType(this VariableAddress address) =>
address.Type switch
{
DbType.Bit => typeof(bool),
DbType.String => typeof(string),
DbType.WString => typeof(string),
DbType.Byte => address.Length == 1 ? typeof(byte) : typeof(byte[]),
DbType.Int => typeof(short),
DbType.UInt => typeof(ushort),
DbType.DInt => typeof(int),
DbType.UDInt => typeof(uint),
DbType.LInt => typeof(long),
DbType.ULInt => typeof(ulong),
DbType.Single => typeof(float),
DbType.Double => typeof(double),
_ => throw new ArgumentOutOfRangeException(nameof(address))
};
}