Skip to content

67 method with a default enum parameter wich type is byte does not compile #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3 changes: 2 additions & 1 deletion AutomaticInterface/AutomaticInterface/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ private static string InheritDoc(ISymbol source) =>
private static readonly SymbolDisplayFormat FullyQualifiedDisplayFormat =
new(
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
memberOptions: SymbolDisplayMemberOptions.IncludeParameters,
memberOptions: SymbolDisplayMemberOptions.IncludeParameters
| SymbolDisplayMemberOptions.IncludeContainingType,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't believe this is a member option! 🤦‍♀️ I didn't even consider that a member option could control default parameter rendering!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that also quite surprising. I played around until it worked ;).
Not ideal, but nothing of that is documented...

parameterOptions: SymbolDisplayParameterOptions.IncludeType
| SymbolDisplayParameterOptions.IncludeParamsRefOut
| SymbolDisplayParameterOptions.IncludeDefaultValue
Expand Down
2 changes: 2 additions & 0 deletions AutomaticInterface/AutomaticInterface/InterfaceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ public string Build()

cb.Indent();
foreach (var method in methodInfos)
{
BuildMethod(cb, method);
}

cb.Dedent();

Expand Down
44 changes: 44 additions & 0 deletions AutomaticInterface/Tests/GeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2025,4 +2025,48 @@ public partial interface IDemoClass
""";
GenerateCode(code).Should().Be(expected);
}

[Fact]
public void WorksWithByteEnums()
{
const string code = """

using AutomaticInterface;
using System;

namespace AutomaticInterfaceExample;

public enum EnumWithByteType : byte { A = 1, B = 2, C = 3 };

[GenerateAutomaticInterface]
public class DemoClass
{
public void MethodWithDefaultParameter(EnumWithByteType a = EnumWithByteType.B) { }
}

""";

const string expected = """
//--------------------------------------------------------------------------------------------------
// <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 AutomaticInterfaceExample
{
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.MethodWithDefaultParameter(AutomaticInterfaceExample.EnumWithByteType)" />
void MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B);

}
}

""";
GenerateCode(code).Should().Be(expected);
}
}