mirror of
https://github.com/evopro-ag/Sharp7Reactive.git
synced 2025-12-16 11:42:52 +00:00
Fix all conversions
This commit is contained in:
@@ -16,41 +16,40 @@ namespace Sharp7.Rx
|
||||
if (typeof(TValue) == typeof(int))
|
||||
{
|
||||
if (address.Length == 2)
|
||||
return (TValue) (object) BinaryPrimitives.ReadInt16BigEndian(buffer);
|
||||
return (TValue) (object) (int) BinaryPrimitives.ReadInt16BigEndian(buffer);
|
||||
if (address.Length == 4)
|
||||
{
|
||||
return (TValue) (object) BinaryPrimitives.ReadInt32BigEndian(buffer);
|
||||
}
|
||||
|
||||
throw new InvalidOperationException($"length must be 2 or 4 but is {address.Length}");
|
||||
}
|
||||
|
||||
if (typeof(TValue) == typeof(long))
|
||||
{
|
||||
return (TValue) (object) BinaryPrimitives.ReadInt64BigEndian(buffer);
|
||||
}
|
||||
|
||||
if (typeof(TValue) == typeof(ulong))
|
||||
{
|
||||
return (TValue) (object) BinaryPrimitives.ReadUInt64BigEndian(buffer);
|
||||
}
|
||||
|
||||
if (typeof(TValue) == typeof(short))
|
||||
{
|
||||
return (TValue) (object) BinaryPrimitives.ReadInt16BigEndian(buffer);
|
||||
}
|
||||
|
||||
if (typeof(TValue) == typeof(byte) || typeof(TValue) == typeof(char))
|
||||
{
|
||||
if (typeof(TValue) == typeof(byte))
|
||||
return (TValue) (object) buffer[0];
|
||||
}
|
||||
if (typeof(TValue) == typeof(char))
|
||||
return (TValue) (object) (char)buffer[0];
|
||||
|
||||
if (typeof(TValue) == typeof(byte[]))
|
||||
{
|
||||
return (TValue) (object) buffer;
|
||||
|
||||
if (typeof(TValue) == typeof(double))
|
||||
{
|
||||
var d = new UInt32SingleMap
|
||||
{
|
||||
UInt32 = BinaryPrimitives.ReadUInt32BigEndian(buffer)
|
||||
};
|
||||
return (TValue) (object) (double)d.Single;
|
||||
}
|
||||
|
||||
if (typeof(TValue) == typeof(double) || typeof(TValue) == typeof(float))
|
||||
if (typeof(TValue) == typeof(float))
|
||||
{
|
||||
var d = new UInt32SingleMap
|
||||
{
|
||||
@@ -71,9 +70,7 @@ namespace Sharp7.Rx
|
||||
return (TValue) (object) Encoding.ASCII.GetString(buffer, 2, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (TValue) (object) Encoding.ASCII.GetString(buffer).Trim();
|
||||
}
|
||||
|
||||
throw new InvalidOperationException(string.Format("type '{0}' not supported.", typeof(TValue)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user