NeVeSpl / NTypewriter

File/code generator using Scriban text templates populated with C# code metadata from Roslyn API.
https://nevespl.github.io/NTypewriter/
MIT License
124 stars 24 forks source link

IType.IsCollection returns false for IList<T> #65

Closed Xriuk closed 1 year ago

Xriuk commented 1 year ago

Type:

IList<MyClass> or IList<MyClass>?

the result is the same

AllInterfaces print:

[ICollection<MyClass>, IEnumerable<MyClass>, IEnumerable]

It returns false for IType.IsCollection but true for IType.IsEnumerable

I think here: https://github.com/NeVeSpl/NTypewriter/blob/96354ef3e5a38856e09daaccf417a44688f841bc/NTypewriter.CodeModel.Roslyn/Type.cs#L17 should become something like:

public bool IsCollection => symbol.AllInterfaces.Any(x => x.ToString() == "System.Collections.ICollection" || x.ToString().StartsWith("System.Collections.Generic.ICollection")) || this.FullName.StartsWith("System.Collections.Generic.ICollection") || this.FullName == "System.Collections.ICollection";
NeVeSpl commented 1 year ago

Indeed, you are right.