Skip to content

Commit

Permalink
#8: Handle service name clash when there are two services with same n…
Browse files Browse the repository at this point in the history
…ame under different namespace
  • Loading branch information
cezarypiatek committed Oct 9, 2023
1 parent ef2a9aa commit 6d20484
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/GrpcToRestGenerator/GrpcToRestProxyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private static void Execute(Compilation compilation, ImmutableArray<SyntaxNode>

var b = new ProxyBuilder(generatorType.ContainingNamespace.ToDisplayString(), generatorType.Name);
var output = b.Build(symbols.ToList());
context.AddSource($"{generatorType.Name}.g.cs", SourceText.From(output, Encoding.UTF8));
context.AddSource($"{GenerateFileName(generatorType)}.g.cs", SourceText.From(output, Encoding.UTF8));
}
}
foreach (var mockingHelperClass in classes.OfType<ClassDeclarationSyntax>().Where(x => HasAttribute(x, "GrpcMockHelperFor")))
Expand All @@ -145,8 +145,13 @@ private static void Execute(Compilation compilation, ImmutableArray<SyntaxNode>

var b = new StubHelperBuilder(mockingHelperType.ContainingNamespace.ToDisplayString(), mockingHelperType.Name);
var output = b.Build(serviceBaseSymbol.ToList());
context.AddSource($"{mockingHelperType.Name}.g.cs", SourceText.From(output, Encoding.UTF8));
context.AddSource($"{GenerateFileName(mockingHelperType)}.g.cs", SourceText.From(output, Encoding.UTF8));
}
}
}

private static string GenerateFileName(INamedTypeSymbol type)
{
return type.ToDisplayString().Replace(".", "_");
}
}

0 comments on commit 6d20484

Please sign in to comment.