Skip to content

Commit 8e451ff

Browse files
67 method with a default enum parameter wich type is byte does not compile (#70)
* feat: Add byte enum to method params * wip: fix tests * feat: add more tests for enums * feat: docs * feat: tests using verify * feat: Use simons idea on how to avoid having two similar SymbolDisplayFormats * feat: better enum testing
1 parent 1afa5e3 commit 8e451ff

15 files changed

+289
-4
lines changed

AutomaticInterface/AutomaticInterface/AutomaticInterface.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2626
<EnableNETAnalyzers>True</EnableNETAnalyzers>
2727
<AnalysisLevel>latest-Recommended</AnalysisLevel>
28-
<Version>5.1.1</Version>
28+
<Version>5.1.2</Version>
2929
<PackageReadmeFile>README.md</PackageReadmeFile>
3030
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
3131
<NoWarn>1701;1702;NU5128</NoWarn>

AutomaticInterface/AutomaticInterface/Builder.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ private static string InheritDoc(ISymbol source) =>
1515
private static readonly SymbolDisplayFormat FullyQualifiedDisplayFormat =
1616
new(
1717
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
18-
memberOptions: SymbolDisplayMemberOptions.IncludeParameters,
18+
memberOptions: SymbolDisplayMemberOptions.IncludeParameters
19+
| SymbolDisplayMemberOptions.IncludeContainingType,
1920
parameterOptions: SymbolDisplayParameterOptions.IncludeType
2021
| SymbolDisplayParameterOptions.IncludeParamsRefOut
2122
| SymbolDisplayParameterOptions.IncludeDefaultValue
@@ -27,6 +28,20 @@ private static string InheritDoc(ISymbol source) =>
2728
| SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers
2829
);
2930

31+
/// <summary>
32+
/// We do need to be able to group shadowing and new methods/events into a single entry, hence this is missing SymbolDisplayMemberOptions.IncludeContainingType
33+
/// </summary>
34+
private static readonly SymbolDisplayFormat FullyQualifiedDisplayFormatForGrouping =
35+
new(
36+
genericsOptions: FullyQualifiedDisplayFormat.GenericsOptions,
37+
memberOptions: FullyQualifiedDisplayFormat.MemberOptions
38+
& ~SymbolDisplayMemberOptions.IncludeContainingType,
39+
parameterOptions: FullyQualifiedDisplayFormat.ParameterOptions,
40+
typeQualificationStyle: FullyQualifiedDisplayFormat.TypeQualificationStyle,
41+
globalNamespaceStyle: FullyQualifiedDisplayFormat.GlobalNamespaceStyle,
42+
miscellaneousOptions: FullyQualifiedDisplayFormat.MiscellaneousOptions
43+
);
44+
3045
public static string BuildInterfaceFor(ITypeSymbol typeSymbol)
3146
{
3247
if (
@@ -91,7 +106,7 @@ private static void AddMethodsToInterface(List<ISymbol> members, InterfaceBuilde
91106
.Where(x => x.MethodKind == MethodKind.Ordinary)
92107
.Where(x => x.ContainingType.Name != nameof(Object))
93108
.Where(x => !HasIgnoreAttribute(x))
94-
.GroupBy(x => x.ToDisplayString(FullyQualifiedDisplayFormat))
109+
.GroupBy(x => x.ToDisplayString(FullyQualifiedDisplayFormatForGrouping))
95110
.Select(g => g.First())
96111
.ToList()
97112
.ForEach(method => AddMethod(codeGenerator, method));
@@ -182,7 +197,7 @@ private static void AddEventsToInterface(List<ISymbol> members, InterfaceBuilder
182197
members
183198
.Where(x => x.Kind == SymbolKind.Event)
184199
.OfType<IEventSymbol>()
185-
.GroupBy(x => x.ToDisplayString(FullyQualifiedDisplayFormat))
200+
.GroupBy(x => x.ToDisplayString(FullyQualifiedDisplayFormatForGrouping))
186201
.Select(g => g.First())
187202
.ToList()
188203
.ForEach(evt =>

AutomaticInterface/AutomaticInterface/InterfaceBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ public string Build()
121121

122122
cb.Indent();
123123
foreach (var method in methodInfos)
124+
{
124125
BuildMethod(cb, method);
126+
}
125127

126128
cb.Dedent();
127129

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//--------------------------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
6+
// </auto-generated>
7+
//--------------------------------------------------------------------------------------------------
8+
9+
namespace AutomaticInterfaceExample
10+
{
11+
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
12+
public partial interface IDemoClass
13+
{
14+
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.MethodWithDefaultParameter(AutomaticInterfaceExample.EnumWithByteType)" />
15+
void MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B);
16+
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//--------------------------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
6+
// </auto-generated>
7+
//--------------------------------------------------------------------------------------------------
8+
9+
namespace AutomaticInterfaceExample
10+
{
11+
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
12+
public partial interface IDemoClass
13+
{
14+
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.MethodWithDefaultParameter(AutomaticInterfaceExample.EnumWithByteType)" />
15+
global::AutomaticInterfaceExample.EnumWithByteType MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B);
16+
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//--------------------------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
6+
// </auto-generated>
7+
//--------------------------------------------------------------------------------------------------
8+
9+
namespace AutomaticInterfaceExample
10+
{
11+
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
12+
public partial interface IDemoClass
13+
{
14+
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.SomeProperty" />
15+
global::AutomaticInterfaceExample.EnumWithByteType SomeProperty { get; set; }
16+
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//--------------------------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
6+
// </auto-generated>
7+
//--------------------------------------------------------------------------------------------------
8+
9+
namespace AutomaticInterfaceExample
10+
{
11+
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
12+
public partial interface IDemoClass
13+
{
14+
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.MethodWithDefaultParameter(AutomaticInterfaceExample.EnumWithByteType)" />
15+
void MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B);
16+
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//--------------------------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
6+
// </auto-generated>
7+
//--------------------------------------------------------------------------------------------------
8+
9+
namespace AutomaticInterfaceExample
10+
{
11+
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
12+
public partial interface IDemoClass
13+
{
14+
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.MethodWithDefaultParameter(AutomaticInterfaceExample.EnumWithByteType)" />
15+
void MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B);
16+
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//--------------------------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
6+
// </auto-generated>
7+
//--------------------------------------------------------------------------------------------------
8+
9+
namespace AutomaticInterfaceExample
10+
{
11+
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
12+
public partial interface IDemoClass
13+
{
14+
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.MethodWithDefaultParameter(AutomaticInterfaceExample.EnumWithByteType)" />
15+
void MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B);
16+
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//--------------------------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
6+
// </auto-generated>
7+
//--------------------------------------------------------------------------------------------------
8+
9+
namespace AutomaticInterfaceExample
10+
{
11+
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
12+
public partial interface IDemoClass
13+
{
14+
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.MethodWithDefaultParameter(AutomaticInterfaceExample.EnumWithByteType)" />
15+
void MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B);
16+
17+
}
18+
}

0 commit comments

Comments
 (0)