m31coding / M31.FluentAPI

Generate fluent builders for your C# classes with ease.
MIT License
94 stars 4 forks source link

FluentCollection on a nullable array results in duplicate method signatures #7

Closed m31coding closed 4 months ago

m31coding commented 5 months ago

This fluent API definition

[FluentApi]
public class Student
{
    [FluentCollection(0, "Friend", "WhoseFriendsAre", "WhoseFriendIs", "WhoHasNoFriends")]
    public string[]? Friends { get; private set; }
}

generates several methods, including the following:

public static Student WhoseFriendsAre(string[]? friends)
{
    CreateStudent createStudent = new CreateStudent();
    friendsPropertyInfo.SetValue(createStudent.student, friends);
    return createStudent.student;
}

public static Student WhoseFriendsAre(params string[] friends)
{
    CreateStudent createStudent = new CreateStudent();
    friendsPropertyInfo.SetValue(createStudent.student, friends);
    return createStudent.student;
}

The compiler raises an error due to duplicate method signatures:

Type 'CreateStudent' already defines a member called 'WhoseFriendsAre' with the same parameter types
m31coding commented 5 months ago

For the example above, the following, single, method should get generated:

public static Student WhoseFriendsAre(params string[]? friends)
{
    CreateStudent createStudent = new CreateStudent();
    friendsPropertyInfo.SetValue(createStudent.student, friends);
    return createStudent.student;
}