Skip to content

Commit

Permalink
Merge pull request #13 from dgmjr-io/12-cs-r1116-consider-using-if-el…
Browse files Browse the repository at this point in the history
…se-instead-of-a-switch-statement-when-having-2-or-fewer-cases

Fixes it
  • Loading branch information
dgmjr authored Jul 6, 2023
2 parents 74c5795 + d40d65c commit 8506082
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions Decomposer/src/aigenerated/TypeDecomposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,30 @@ public void Execute(IncrementalGeneratorExecutionContext context)
// Generate an interface for each public property and method
foreach (var symbol in symbolsForType)
{
switch (symbol)
if (symbol is IPropertySymbol propertySymbol)
{
case IPropertySymbol propertySymbol:
if (propertySymbol.IsReadOnly || propertySymbol.IsWriteOnly)
continue;
var interfaceName = GetInterfaceName(targetType, propertySymbol);
var interfaceSyntax = GenerateInterfaceSyntax(targetType, propertySymbol, interfaceName);
if (propertySymbol.IsReadOnly || propertySymbol.IsWriteOnly)
continue;
var interfaceName = GetInterfaceName(targetType, propertySymbol);
var interfaceSyntax = GenerateInterfaceSyntax(targetType, propertySymbol, interfaceName);
interfaces.Add(interfaceSyntax);
break;
}
else if (symbol is IMethodSymbol)
{
if (methodSymbol.IsAccessor())
continue;
var overloadedMethodSymbols = targetType.GetMembers(methodSymbol.Name)
.OfType<IMethodSymbol>()
.Where(m => SymbolEqualityComparer.Default.Equals(m.ReturnType, methodSymbol.ReturnType)
&& m.Parameters.SequenceEqual(methodSymbol.Parameters, ParameterEqualityComparer.Default));
foreach (var overloadedMethodSymbol in overloadedMethodSymbols)
{
var interfaceName = GetInterfaceName(targetType, overloadedMethodSymbol);
var interfaceSyntax = GenerateInterfaceSyntax(targetType, overloadedMethodSymbol, interfaceName);
interfaces.Add(interfaceSyntax);
break;
case IMethodSymbol methodSymbol:
if (methodSymbol.IsAccessor())
continue;
var overloadedMethodSymbols = targetType.GetMembers(methodSymbol.Name)
.OfType<IMethodSymbol>()
.Where(m => SymbolEqualityComparer.Default.Equals(m.ReturnType, methodSymbol.ReturnType)
&& m.Parameters.SequenceEqual(methodSymbol.Parameters, ParameterEqualityComparer.Default));
foreach (var overloadedMethodSymbol in overloadedMethodSymbols)
{
var interfaceName = GetInterfaceName(targetType, overloadedMethodSymbol);
var interfaceSyntax = GenerateInterfaceSyntax(targetType, overloadedMethodSymbol, interfaceName);
interfaces.Add(interfaceSyntax);
}
break;
}
break;
}
}

Expand Down

0 comments on commit 8506082

Please sign in to comment.