From cab6a1ea774f46cf93de0c74a4c2ed9ef4ad219e Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sun, 8 May 2022 10:17:48 +0200 Subject: [PATCH] Fix for default parameter (default) (#33) --- .../Extensions/ParameterSymbolExtensions.cs | 16 +++++++++++++++- .../Extensions/TypeParameterSymbolExtensions.cs | 10 ---------- ...rfaceSourceGeneratorTests.Source.IPerson.g.cs | 2 +- ...eSourceGeneratorTests.Source.PersonProxy.g.cs | 5 +++-- .../Source/Person.cs | 3 ++- 5 files changed, 21 insertions(+), 15 deletions(-) delete mode 100644 src/ProxyInterfaceSourceGenerator/Extensions/TypeParameterSymbolExtensions.cs diff --git a/src/ProxyInterfaceSourceGenerator/Extensions/ParameterSymbolExtensions.cs b/src/ProxyInterfaceSourceGenerator/Extensions/ParameterSymbolExtensions.cs index 4d54b12..fdbfc2e 100644 --- a/src/ProxyInterfaceSourceGenerator/Extensions/ParameterSymbolExtensions.cs +++ b/src/ProxyInterfaceSourceGenerator/Extensions/ParameterSymbolExtensions.cs @@ -5,6 +5,9 @@ namespace ProxyInterfaceSourceGenerator.Extensions; internal static class ParameterSymbolExtensions { + private const string ParameterValueDefault = "default"; + private const string ParameterValueNull = "null"; + public static string GetRefPrefix(this IParameterSymbol ps) { switch (ps.RefKind) @@ -33,7 +36,18 @@ internal static class ParameterSymbolExtensions return string.Empty; } - var defaultValue = ps.ExplicitDefaultValue ?? "null"; + string defaultValue; + if (ps.ExplicitDefaultValue is null) + { + defaultValue = ps.NullableAnnotation == NullableAnnotation.Annotated + ? ParameterValueNull + : ParameterValueDefault; + } + else + { + defaultValue = ps.ExplicitDefaultValue.ToString(); + } + return $" = {defaultValue}"; } diff --git a/src/ProxyInterfaceSourceGenerator/Extensions/TypeParameterSymbolExtensions.cs b/src/ProxyInterfaceSourceGenerator/Extensions/TypeParameterSymbolExtensions.cs deleted file mode 100644 index 2e642f2..0000000 --- a/src/ProxyInterfaceSourceGenerator/Extensions/TypeParameterSymbolExtensions.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using Microsoft.CodeAnalysis; -using ProxyInterfaceSourceGenerator.Models; - -namespace ProxyInterfaceSourceGenerator.Extensions; - -internal static class TypeParameterSymbolExtensions -{ - -} \ No newline at end of file diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IPerson.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IPerson.g.cs index fc19b0e..cfdcee5 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IPerson.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IPerson.g.cs @@ -46,7 +46,7 @@ namespace ProxyInterfaceSourceGeneratorTests.Source System.Threading.Tasks.Task Method3Async(); - void CreateInvokeHttpClient(int i = 5, string? appId = null); + void CreateInvokeHttpClient(int i = 5, string? appId = null, System.Threading.CancellationToken token = default); diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonProxy.g.cs index a1fe143..7498250 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonProxy.g.cs @@ -105,11 +105,12 @@ namespace ProxyInterfaceSourceGeneratorTests.Source return result__57684656; } - public void CreateInvokeHttpClient(int i = 5, string? appId = null) + public void CreateInvokeHttpClient(int i = 5, string? appId = null, System.Threading.CancellationToken token = default) { int i_ = i; string? appId_ = appId; - _Instance.CreateInvokeHttpClient(i_, appId_); + System.Threading.CancellationToken token_ = token; + _Instance.CreateInvokeHttpClient(i_, appId_, token_); } diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Person.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Person.cs index e0a44bb..4836eab 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/Person.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Person.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Net.Http; +using System.Threading; using System.Threading.Tasks; namespace ProxyInterfaceSourceGeneratorTests.Source @@ -69,7 +70,7 @@ namespace ProxyInterfaceSourceGeneratorTests.Source return Task.FromResult((string?)""); } - public void CreateInvokeHttpClient(int i = 5, string? appId = null) + public void CreateInvokeHttpClient(int i = 5, string? appId = null, CancellationToken token = default) { } }