AArnott / CodeGeneration.Roslyn

Assists in performing Roslyn-based code generation during a build.
Microsoft Public License
408 stars 59 forks source link

IRichCodeGenerator not emitting the same as ICodeGenerator #158

Closed fuocor closed 5 years ago

fuocor commented 5 years ago

the IRichCodeGenerator not emitting the same as ICodeGenerator. The transformation creates a default implementation of an interface definition. Using ICodeGenerator, the output includes the namespace from the interface I am applying the transformation, but IRichCodeGenerator does not.

when running a test using IRichCodeGenerator I get output that looks like the following

[0.011s] TestLifetime Information: Starting test ResourceTest at 2019-08-02T23:38:53
| [0.015s] TestLifetime Information: Starting test ResourceTest at 2019-08-02T23:38:53
| [1.307s] ResourceTest Information: // ------------------------------------------------------------------------------
|                                    // <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>
|                                    // ------------------------------------------------------------------------------
|                                    partial class Resource2 : IResource2
|                                    {
|                                        [System.ObsoleteAttribute("This constructor for use with json deserializers only. Use the static Create factory method instead.")]
|                                        public Resource2(JsonElement json)
|                                        {
|                                        }
|                                    }
| [1.328s] ResourceTest Information: GeneratorDiagnostics: 
| [1.335s] ResourceTest Information: CompilationDiagnostics: 
|                                    input.cs(4,6): error CS0592: Attribute 'Chorus.CodeGenerator.GenerateClass' is not valid on this declaration type. It is only valid on 'class' declarations.
|                                    output.cs(10,27): error CS0246: The type or namespace name 'IResource2' could not be found (are you missing a using directive or an assembly reference?)
|                                    output.cs(13,22): error CS0246: The type or namespace name 'JsonElement' could not be found (are you missing a using directive or an assembly reference?)
| [1.338s] TestLifetime Information: Finished test ResourceTest in 1.322262s
| [1.368s] TestLifetime Information: Finished test ResourceTest in 1.3621874999999999s

With the same contents in the SyntaxList<MemberDeclarationSyntax> but flowing through ICodeGenerator I get the following

| [0.009s] TestLifetime Information: Starting test ResourceTest at 2019-08-02T23:43:51
| [0.015s] TestLifetime Information: Starting test ResourceTest at 2019-08-02T23:43:51
| [1.398s] ResourceTest Information: // ------------------------------------------------------------------------------
|                                    // <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 Chorus.Azure.Cosmos
|                                    {
|                                        partial class Resource2 : IResource2
|                                        {
|                                            [System.ObsoleteAttribute("This constructor for use with json deserializers only. Use the static Create factory method instead.")]
|                                            public Resource2(JsonElement json)
|                                            {
|                                            }
|                                        }
|                                    }
| [1.423s] ResourceTest Information: GeneratorDiagnostics: 
| [1.442s] ResourceTest Information: CompilationDiagnostics: 
|                                    input.cs(4,6): error CS0592: Attribute 'Chorus.CodeGenerator.GenerateClass' is not valid on this declaration type. It is only valid on 'class' declarations.
|                                    output.cs(12,31): error CS0535: 'Resource2' does not implement interface member 'IResource2.ResourceId'
|                                    output.cs(12,31): error CS0535: 'Resource2' does not implement interface member 'IResource2.SelfLink'
|                                    output.cs(12,31): error CS0535: 'Resource2' does not implement interface member 'IResource2.Timestamp'
|                                    output.cs(12,31): error CS0535: 'Resource2' does not implement interface member 'IResource2.ETag'
|                                    output.cs(15,26): error CS0246: The type or namespace name 'JsonElement' could not be found (are you missing a using directive or an assembly reference?)
| [1.446s] TestLifetime Information: Finished test ResourceTest in 1.430456s
| [1.474s] TestLifetime Information: Finished test ResourceTest in 1.4696844s

Any help is appreciated.

regards, rich

fuocor commented 5 years ago

Figured it out... The IRichCodeGenerator does not wrap the generated members into the ancestor namespace.