Update framework reference so it's the older one

This commit is contained in:
KillzXGaming 2020-03-08 19:11:44 -04:00
parent 979b39d374
commit 81e48cd20e

View file

@ -83,21 +83,18 @@ namespace Toolbox.Library.IO
if (!isBigEndian)
return;
Console.WriteLine("type " + type + " " + type.IsPrimitive);
if (type.IsPrimitive)
{
if (type == typeof(short) || type == typeof(ushort) ||
type == typeof(int) || type == typeof(uint) ||
type == typeof(long) || type == typeof(ulong))
type == typeof(long) || type == typeof(ulong) ||
type == typeof(double) || type == typeof(float))
{
Array.Reverse(buffer);
return;
}
}
Console.WriteLine("GetFields " + type.GetFields().Length);
foreach (var field in type.GetFields())
{
var fieldType = field.FieldType;
@ -108,13 +105,7 @@ namespace Toolbox.Library.IO
if (fieldType.BaseType == typeof(Enum) && fieldType != typeof(ByteOrder))
fieldType = fieldType.GetFields()[0].FieldType;
// Swap bytes only for the following types (incomplete just like BinaryReaderX is)
if (fieldType == typeof(short) || fieldType == typeof(ushort) ||
fieldType == typeof(int) || fieldType == typeof(uint) ||
fieldType == typeof(long) || fieldType == typeof(ulong))
{
var offset = Marshal.OffsetOf(type, field.Name).ToInt32();
// Enums
if (fieldType.IsEnum)
fieldType = Enum.GetUnderlyingType(fieldType);
@ -123,11 +114,18 @@ namespace Toolbox.Library.IO
var subFields = fieldType.GetFields().Where(subField => subField.IsStatic == false).ToArray();
var effectiveOffset = startOffset + offset;
if (fieldType == typeof(short) || fieldType == typeof(ushort) ||
fieldType == typeof(int) || fieldType == typeof(uint) ||
fieldType == typeof(long) || fieldType == typeof(ulong) ||
fieldType == typeof(double) || fieldType == typeof(float))
{
if (subFields.Length == 0)
Array.Reverse(buffer, effectiveOffset, Marshal.SizeOf(fieldType));
else
AdjustBigEndianByteOrder(fieldType, buffer, isBigEndian, effectiveOffset);
}
if (subFields.Length > 0)
AdjustBigEndianByteOrder(fieldType, buffer, isBigEndian, effectiveOffset);
}
}