Skip to content

Conversation

Copy link

Copilot AI commented Nov 23, 2025

Source generator failed when multiple [Projectable] methods shared the same name, as generated class names were identical and caused compilation errors. This prevented natural method overloading:

class MyClass {
    [Projectable] public Image FindImage(int id) => ...;
    [Projectable] public Image FindImage(Uri uri) => ...;  // Error: duplicate class name
}

Changes

Class name generation now includes parameter type signatures:

  • Format: Namespace_Class_Method_P0_Type1_P1_Type2
  • Primitives use C# keywords (int, string) matching Roslyn output
  • Arrays: int__, generic types: List_int_, type parameters: TEntity
  • Generic class arity markers positioned at end per CLR convention

Runtime resolution updated to match:

  • Maps Type.FullName to Roslyn's SymbolDisplayFormat.FullyQualifiedFormat
  • Handles generic method definitions, nested types (+.), and type parameter substitution

Examples of generated names:

Method(int x)                    → Method_P0_int
Method(string s, int[] arr)      → Method_P0_string_P1_int__
Method(List<int> items)          → Method_P0_System_Collections_Generic_List_int_
BaseEntity<T,U>.Method(string s) → BaseEntity_Method_P0_string`2

Backward compatibility

Methods without parameters or without overloads generate unchanged names. Properties remain unaffected.

Original prompt

Please work on this issue :

Add support for projectable method overloads

If I try to define 2+ projectable methods with the same name on the same class but give them different argument lists, then the source generator triggers an error indicating that classes with the same name cannot be provided by the same source generator. It appears this is because the class name is generated via the namespace+class+method. Would it be difficult/problematic to expand this so that the generated class names also include the number and type of the arguments? For example...

namespace MyNamespace
{
class MyClass
{
[Projectable] public MyImage? FindImage(DbContext db, int id) => db.Set().Where(m => true);
[Projectable] public MyImage? FindImage(DbContext db, Uri uri) => db.Set().Where(m => true);
[Projectable] public MyImage? FindImage(DbContext db, Uri folder, string tagName) => db.Set().Where(m => true);
}
}

EntityFrameworkCore.Projectables.Generated.MyNamespace_MyClass_FindImage_P1_System_Int32
EntityFrameworkCore.Projectables.Generated.MyNamespace_MyClass_FindImage_P1_System_Uri
EntityFrameworkCore.Projectables.Generated.MyNamespace_MyClass_FindImage_P1_System_Uri_P2_System_String

It's important to note that this is more of a nice-to-have. I attempted to do method overloads and ran into this error, after which I had to work around it by using a naming convention like, FindImageById, FindImageByUri, FindImageByFolderAndTag, etc. It did not significantly impact my ability to use this library, but it was something I wanted to do and which I was disappointed to discover I could not do. However, I can understand if one would not wish to work on adding it as a feature.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits November 23, 2025 10:15
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for projectable method overloads Add support for projectable method overloads Nov 23, 2025
Copilot AI requested a review from PhenX November 23, 2025 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants