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
    {
    }
}

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_.
@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
- 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
@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.

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