From f9db732d7bd33224912a9a84fddbb383c4584852 Mon Sep 17 00:00:00 2001 From: Timothy Makkison Date: Thu, 7 Nov 2024 20:25:54 +0000 Subject: [PATCH 1/3] fix: support - symbols in csproj names --- InterfaceStubGenerator.Shared/Parser.cs | 2 +- Refit/UniqueName.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/InterfaceStubGenerator.Shared/Parser.cs b/InterfaceStubGenerator.Shared/Parser.cs index a603d7a6f..b1315ab77 100644 --- a/InterfaceStubGenerator.Shared/Parser.cs +++ b/InterfaceStubGenerator.Shared/Parser.cs @@ -265,7 +265,7 @@ bool nullableEnabled } // Remove dots - ns = ns!.Replace(".", ""); + ns = ns!.Replace(".", "").Replace('-', '_'); var interfaceDisplayName = interfaceSymbol.ToDisplayString( SymbolDisplayFormat.FullyQualifiedFormat ); diff --git a/Refit/UniqueName.cs b/Refit/UniqueName.cs index 0fc7e85f9..fafb23acc 100644 --- a/Refit/UniqueName.cs +++ b/Refit/UniqueName.cs @@ -39,7 +39,7 @@ public static string ForType(Type refitInterfaceType) interfaceTypeName = interfaceTypeName.Replace("+", ""); // Get the namespace and remove the dots - var ns = refitInterfaceType.Namespace?.Replace(".", ""); + var ns = refitInterfaceType.Namespace?.Replace(".", "").Replace("-", "_"); // Refit types will be generated as private classes within a Generated type in namespace // Refit.Implementation From 7d3b00a273daea3e3d3bda2f35fd10322992fa53 Mon Sep 17 00:00:00 2001 From: Timothy Makkison Date: Thu, 7 Nov 2024 22:45:43 +0000 Subject: [PATCH 2/3] fix: revert --- InterfaceStubGenerator.Shared/Parser.cs | 2 +- Refit/UniqueName.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/InterfaceStubGenerator.Shared/Parser.cs b/InterfaceStubGenerator.Shared/Parser.cs index b1315ab77..a603d7a6f 100644 --- a/InterfaceStubGenerator.Shared/Parser.cs +++ b/InterfaceStubGenerator.Shared/Parser.cs @@ -265,7 +265,7 @@ bool nullableEnabled } // Remove dots - ns = ns!.Replace(".", "").Replace('-', '_'); + ns = ns!.Replace(".", ""); var interfaceDisplayName = interfaceSymbol.ToDisplayString( SymbolDisplayFormat.FullyQualifiedFormat ); diff --git a/Refit/UniqueName.cs b/Refit/UniqueName.cs index fafb23acc..0fc7e85f9 100644 --- a/Refit/UniqueName.cs +++ b/Refit/UniqueName.cs @@ -39,7 +39,7 @@ public static string ForType(Type refitInterfaceType) interfaceTypeName = interfaceTypeName.Replace("+", ""); // Get the namespace and remove the dots - var ns = refitInterfaceType.Namespace?.Replace(".", "").Replace("-", "_"); + var ns = refitInterfaceType.Namespace?.Replace(".", ""); // Refit types will be generated as private classes within a Generated type in namespace // Refit.Implementation From 744d4df65062de290d33031c7f49a3ac7e9cef27 Mon Sep 17 00:00:00 2001 From: Timothy Makkison Date: Thu, 7 Nov 2024 22:50:07 +0000 Subject: [PATCH 3/3] fix: remove -,@ symbols in namespaces --- InterfaceStubGenerator.Shared/Parser.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/InterfaceStubGenerator.Shared/Parser.cs b/InterfaceStubGenerator.Shared/Parser.cs index a603d7a6f..0c90cb201 100644 --- a/InterfaceStubGenerator.Shared/Parser.cs +++ b/InterfaceStubGenerator.Shared/Parser.cs @@ -34,6 +34,9 @@ CancellationToken cancellationToken refitInternalNamespace = $"{refitInternalNamespace ?? string.Empty}RefitInternalGenerated"; + // Remove - as they are valid in csproj, but invalid in a namespace + refitInternalNamespace = refitInternalNamespace.Replace('-', '_').Replace('@', '_'); + // we're going to create a new compilation that contains the attribute. // TODO: we should allow source generators to provide source during initialize, so that this step isn't required. var options = (CSharpParseOptions)compilation.SyntaxTrees[0].Options;