Warpten / DBClientFiles.NET

The new version of DBFilesClient.NET.
GNU General Public License v3.0
11 stars 5 forks source link

Deserializing arrays #10

Closed Warpten closed 5 years ago

Warpten commented 5 years ago

The two-fold approach to arrays leads to a glaring issue (not really a bug).

Given this declaration

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
public Substructure[] SomeMember {get;set;}

But the corresponding file metadata instead says that the member is not of cardinality 5, the generator will produce this kind of code:

{
    var structure = new ...();
    structure.SomeMember = new Substructure [5];
    for (var i = 0; i < 5; ++i)
        structure.SomeMember[i]= new Substructure();

    // Deserialization happens now
    structure.SomeMember[i] = reader.ReadArray<Substructure>(3);
    // ...

    return structure;
}

User code should never have to hardcode array sizes but instead use SomeMember.Length, which here will yield two extra elements.

This is an even more glaring issue when the declared structure has cardinality lower than what the file declares.