C# generated code for Nullable byte and DateTime arrays

I think there is an issue with the C# code generated when a DTO contains a byte?[] or DateTime?[] property.

I noticed this as the T4 template for OrmLite to generate DTO’s and the associated QueryType produces the Query classes with byte?[] and DateTime?[] properties for Nullable byte and DateTime columns in the DTO.

The problem is the resultant property generated by /types/chsarp (and thus C# ServiceStack clients who add a ServiceStack reference) looks like this:

public virtual Nullable DisplayOrderIn { get; set; }

I think it should be like this:

public virtual byte?[] DisplayOrderIn { get; set; }

I’ve tested this on 4.5.12 and also the 4.5.13 on MyGet moments ago.

EDIT: I should add that the currently generated C# code won’t compile.

A simple repro is:

  1. Create a new ServiceStack self hosted c# project from the template in Visual Studio

  2. Add to the Hello DTO a byte?[] or DateTime?[] property - e.g.:

    public class Hello : IReturn
    public string Name { get; set; }
    public DateTime?[] DateTimeTestIn { get; set; }
    public byte?[] byteTestIn { get; set; }

  3. Run the project, and visit the /types/csharp route to see the generated code:

    public partial class Hello
    : IReturn
    public virtual string Name { get; set; }
    public virtual Nullable DateTimeTestIn { get; set; }
    public virtual Nullable byteTestIn { get; set; }

We’ll look into it, but you can use List’s which have the same wire format as arrays, e.g:

public List<byte?> NullableByteList { get; set; }
public List<DateTime?> NullableDateTimeList { get; set; }

This will generate the full type, e.g:

public virtual List<Nullable<Byte>> NullableByteList { get; set; }
public virtual List<Nullable<DateTime>> NullableDateTimeList { get; set; }
1 Like

Thanks - I’ll modify the T4 template to generate the QueryType classes such that those properties are of type List instead.

We should now support Arrays of nullable types in the latest v4.5.13 Release that’s now available on MyGet.

1 Like