net_automatic_interface icon indicating copy to clipboard operation
net_automatic_interface copied to clipboard

Handle generic types in method deduplication

Open simonmckenzie opened this issue 1 year ago • 2 comments

This fixes an error where methods with the same parameters but different generic type parameters were being treated as identical during deduplication, resulting in the loss of interface methods.

The fix is to use genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters when constucting the SymbolDisplayFormat used for deduplication.

I have also added SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces to prevent types with the same name from being seen as identical.

Finally, I have unified MethodSignatureDisplayFormat and TypeDisplayFormat into a single FullyQualifiedDisplayFormat. These two display formats were used for method deduplication and generating type signatures from strings. It makes sense that they should follow the same rules.

The effect of the change

Given this:

public void AMethod(Func<Task<int>> getValue) {}

Deduplication key before change: AMethod(Func) Deduplication key after change: AMethod(Func<Task<System.Int32>>)

... or, given user-defined types, the key will contain fully-qualified types:

namespace Demo;

public delegate T Func<T>();
public class Task<T>;

//...
public void AMethod(Demo.Func<Demo.Task<int>> getValue) {}

Deduplication key: AMethod(Demo.Func<Demo.Task<System.Int32>>)

I have left the global namespaces out of the examples for the sake of simplicity

Addresses #56

simonmckenzie avatar Aug 14 '24 00:08 simonmckenzie

I think this is obsolete after your last PR for 5.0.0?

ChristianSauer avatar Sep 01 '24 17:09 ChristianSauer

Hi @ChristianSauer,

This PR isn't obsolete - there's still an issue with generic type parameter deduplication. I've rebased, simplified the code, and added another test now the other PR is merged.

simonmckenzie avatar Sep 01 '24 23:09 simonmckenzie

So, finally found time to merge

ChristianSauer avatar Nov 29 '24 08:11 ChristianSauer