frhagn / Typewriter

Automatic TypeScript template generation from C# source files
http://frhagn.github.io/Typewriter
Apache License 2.0
536 stars 132 forks source link

Wrong Property.Type.IsGeneric value in case of primitive[] array #345

Closed buchatsky closed 2 years ago

buchatsky commented 2 years ago

Description .IsGeneric returns 'false' for primitive[] array types of properties (but correctly returns 'true' for Object[] array props). C# class:

   public partial class Category
    {
        public int CategoryId { get; set; }
        public string CategoryName { get; set; } = null!;
        public string? Description { get; set; }
        public byte[]? Picture { get; set; }

        public virtual ICollection<Product> Products { get; set; }
    }

For 'Picture' property (incorrect): type: number[], isEnum: True, isGeneric: False, unwrapType: number[], isUnwrapPrimitive: False, firstTypeArg: number;

For 'Products' property (correct): type: Product[], isEnum: True, isGeneric: True, unwrapType: Product, isUnwrapPrimitive: False, firstTypeArg: Product;

Desired behaviour For 'Picture' property: type: number[], isEnum: True, isGeneric: True, unwrapType: number, isUnwrapPrimitive: True, firstTypeArg: number;

Versions Typewriter64: 2.5.0 ( @adaskothebeast 's clone ) Visual Studio: 2022 (17.0.4)

NeVeSpl commented 2 years ago

.IsGeneric applies to C# type, not Typescript type. Arrays in C# are not generic type.

(byte[]?).IsGeneric == false
(Product[]?).IsGeneric == false
(ICollection<byte>).IsGeneric == true
(ICollection<Product>).IsGeneric == true

Typewriter has many bugs, but this is not one of them.

buchatsky commented 2 years ago

But property.Type.Name returns "number[]", not "byte[]". So I thought it was applied to Typescript

NeVeSpl commented 2 years ago

Yeah, it is a mess, you never know in Typewriter if you work with C# or TS type. It is why in NTypewriter there is a clear separation, code model is pure c# and TS functionality is available only through built-in functions.