NeVeSpl / NTypewriter

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

Extend AllReferencedTypes to search on Interfaces #112

Closed christophdebaene closed 8 months ago

christophdebaene commented 8 months ago

First of all I like your project very much and planning to use it for more use cases.

Right now I am using it for scanning Requests from MediatR and consequently generate API client. Given the following class, that Customer is also resolved.

public class GetCustomerById : IRequest<Customer> 
{ 
    public int CustomerId { get; set;}
}

Extending the SearchIn enum with Interfaces and AllInterfaces. An extra boolean parameter includeSelf that includes the given type is also a nice functionality I found handy.

public static IEnumerable<IType> AllReferencedTypes(this IType type, SearchIn searchIn = SearchIn.All, includeSelf = false)

Another option could be to make it more explicit and maybe add another method AllReferencedTypesAndSelf. Having an overload that accepts an IEnumerable<IType> would also be handy.

Please let me know where I can help or create a pull request for the given functionality.

NeVeSpl commented 8 months ago

Indeed implemented interfaces by the given type are not checked right now, but only Interfaces should be considered, not AllInterfaces. You are welcome to add this functionality, just remember to write unit tests for it.

About the remaining two, I am not sure If they are needed, a user can easily achieve similar outcomes by writing custom functions that utilize the current version of AllReferencedTypes.