Skip to content

Conversation

@simonmckenzie
Copy link
Contributor

This addresses an issue where, when a class references a generated interface, those references are not fully qualified, resulting in an interface that doesn't compile. See #87.

The change is to precalculate the list of interface names that will be generated, and, during symbol string generation, replace unrecognised symbols with generated names where a single unambiguous match can be made between the symbol and the list of interfaces being generated.

For the example provided in #87, the code will now generate this output:

//--------------------------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// </auto-generated>
//--------------------------------------------------------------------------------------------------

namespace Test
{
    [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
    public partial interface ITest1
    {
        /// <inheritdoc cref="Test.Test1.Get(ITest2)" />
        void Get(global::Test.Tests.ITest2 test);
        
    }
}


//--------------------------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// </auto-generated>
//--------------------------------------------------------------------------------------------------

namespace Test.Tests
{
    [global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
    public partial interface ITest2
    {
    }
}

@simonmckenzie simonmckenzie force-pushed the feature/fully-qualify-references-to-generated-interfaces branch from 011fcc7 to 332a2db Compare September 3, 2025 04:55
@simonmckenzie simonmckenzie force-pushed the feature/fully-qualify-references-to-generated-interfaces branch 2 times, most recently from f449545 to dfcb5b7 Compare October 15, 2025 09:18
@simonmckenzie simonmckenzie force-pushed the feature/fully-qualify-references-to-generated-interfaces branch from dfcb5b7 to 28df788 Compare October 22, 2025 08:43
@simonmckenzie
Copy link
Contributor Author

This is ready for review again - I just had a last minute refactoring idea :)

@ChristianSauer
Copy link
Collaborator

Could you be so kind and merge master into this? Than I will merge it as 6.x I think because it's potentially breaking

@simonmckenzie
Copy link
Contributor Author

Not a problem @ChristianSauer. I hope to get this done next week.

@simonmckenzie simonmckenzie force-pushed the feature/fully-qualify-references-to-generated-interfaces branch from 28df788 to 12ad491 Compare November 12, 2025 01:39
@simonmckenzie
Copy link
Contributor Author

simonmckenzie commented Nov 12, 2025

Hi @ChristianSauer,

I've rebased the branch on master, but happy to get the other PR merged first, then I can rebase and refactor again, as I think I should probably move the other PR's changes into the RoslynExtensions class. Whatever suits you, of course :)

@simonmckenzie simonmckenzie force-pushed the feature/fully-qualify-references-to-generated-interfaces branch from 12ad491 to 7302977 Compare November 12, 2025 02:22
@simonmckenzie simonmckenzie force-pushed the feature/fully-qualify-references-to-generated-interfaces branch from 5d8726b to 4cce479 Compare November 12, 2025 02:26
@ChristianSauer
Copy link
Collaborator

@simonmckenzie I merged the other PR first :)

This addresses an issue where, when a class references a generated interface, those references are not fully qualified, resulting in an interface that doesn't compile.

The change is to precalculate the list of interface names that will be generated, and, during symbol string generation, replace unrecognised symbols with generated names _where a single unambiguous match can be made between the symbol and the list of interfaces being generated_.
- Change approach to use `ToDisplayParts`, which removes the need for regex parsing of generated code
- Fix bug in `ReplaceWithInferredInterfaceName` where dots weren't being escaped
- Add tests to ensure partially qualified references will be resolved correctly
…class; refactor

This centralises the rendering logic plus simplifies the implementation to use `ITypeSymbol.WithNullableAnnotation` and hands the rendering off to the default `ToDisplayString` implementation
@simonmckenzie simonmckenzie force-pushed the feature/fully-qualify-references-to-generated-interfaces branch from 4cce479 to 9148e56 Compare November 18, 2025 23:11
@simonmckenzie
Copy link
Contributor Author

Hi @ChristianSauer,

I've rebased again and refactored the changes from #85 into the RoslynExtensions (9148e56).

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