Added Array specific logic to Reader. **NOTE: This doesn't use the new attribute yet**

This commit is contained in:
Samuele Lorefice
2025-03-11 18:44:48 +01:00
parent 8678ee6c85
commit 0bf0aeab09

View File

@@ -222,9 +222,23 @@ public class Reader {
var data = new byte[size]; var data = new byte[size];
Array.Copy((byte[])block.Body, offset, data, 0, size); Array.Copy((byte[])block.Body, offset, data, 0, size);
//Check if it's an array
if (Type.GetType(attrib.UnderlyingType) is { IsArray: true }) {
int itemLenght = attrib.OriginalType.ParseFSize();
var array = new object?[attrib.Size / itemLenght];
for (int i = 0; i < attrib.Size; i += itemLenght) {
var itemData = new byte[itemLenght];
Array.Copy(data, i, itemData, 0, itemLenght);
array[i / itemLenght] = ConvertFieldData(itemData, attrib.OriginalType);
}
return array;
} else {
//Convert the data to the correct type if it's a base type //Convert the data to the correct type if it's a base type
object? value = ConvertFieldData(data, attrib.OriginalType); object? value = ConvertFieldData(data, attrib.OriginalType);
if (value != null) return value; if (value != null) return value;
}
//Check if the field is a pointer to another DNA structure //Check if the field is a pointer to another DNA structure
if (dnaTypesDb.ContainsKey(attrib.OriginalType)) { if (dnaTypesDb.ContainsKey(attrib.OriginalType)) {