orleans icon indicating copy to clipboard operation
orleans copied to clipboard

Added #pragma warning disable CS1591 to supress warnings in the source generated code

Open m3nax opened this issue 1 year ago • 3 comments

Description

Added #pragma warning disable CS1591 and "#pragma warning restore CS1591 to the source generated file to supress warnings when projects contains <GenerateDocumentationFile>True</GenerateDocumentationFile>

Fix

  • #8290

m3nax avatar Apr 11 '24 14:04 m3nax

Thank you for opening this PR, @m3nax!

I was looking for the Roslyn-native way to do this. It might look something like this, in CodeGenerator.cs before we return the CompilationSyntax but I haven't tested this yet:

            var disabledWarnings = new List<string>();
            assemblyAttributes[0] = assemblyAttributes[0]
                .WithLeadingTrivia(
                    SingletonList(
                        PragmaWarningDirectiveTrivia(
                            Token(SyntaxKind.DisableKeyword),
                            SeparatedList(disabledWarnings.Select(w => (ExpressionSyntax)w.GetLiteralExpression())), isActive: true)));
            
            return CompilationUnit()
                .WithAttributeLists(List(assemblyAttributes))
                .WithMembers(List(namespaces));

ReubenBond avatar Apr 20 '24 18:04 ReubenBond

I Will test It tomorrow

m3nax avatar Apr 20 '24 19:04 m3nax

@ReubenBond I have updated the implementation as you suggested but, as it is the first time I have modified a source generator, I did not understand how to remove the double quotes from the list of warnings to be suppressed

Now the output of orleans.g,cs is like this:

#pragma warning disable "CS1591"
[assembly: global::Orleans.ApplicationPartAttribute("ConsoleApp1")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.ConsoleApp1.Metadata_ConsoleApp1))]
namespace OrleansCodeGen.ConsoleApp1
{

// CODE

}
#pragma warning restore "CS1591"

Do you have any suggestions?

m3nax avatar Apr 22 '24 08:04 m3nax

@ReubenBond Problem fixed

m3nax avatar May 28 '24 08:05 m3nax

Fantastic, thank you, @m3nax!

ReubenBond avatar May 30 '24 14:05 ReubenBond