From 55043701dbcafa74a356f5e9b78aee5482840a44 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Fri, 6 May 2022 23:57:26 +0200 Subject: [PATCH] Fix for Explicit DefaultValue is not defined (#31) * Fix for Explicit DefaultValue is not defined * . --- .../Extensions/ParameterSymbolExtensions.cs | 12 ++++++++++-- ...InterfaceSourceGeneratorTests.Source.IPerson.g.cs | 2 ++ ...rfaceSourceGeneratorTests.Source.PersonProxy.g.cs | 7 +++++++ .../Source/Person.cs | 5 +++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/ProxyInterfaceSourceGenerator/Extensions/ParameterSymbolExtensions.cs b/src/ProxyInterfaceSourceGenerator/Extensions/ParameterSymbolExtensions.cs index 7e4094f..4d54b12 100644 --- a/src/ProxyInterfaceSourceGenerator/Extensions/ParameterSymbolExtensions.cs +++ b/src/ProxyInterfaceSourceGenerator/Extensions/ParameterSymbolExtensions.cs @@ -26,8 +26,16 @@ internal static class ParameterSymbolExtensions public static string GetParamsPrefix(this IParameterSymbol ps) => ps.IsParams ? "params " : string.Empty; - public static string GetDefaultValue(this IParameterSymbol ps) => - ps.HasExplicitDefaultValue ? $" = {ps.ExplicitDefaultValue}" : string.Empty; + public static string GetDefaultValue(this IParameterSymbol ps) + { + if (!ps.HasExplicitDefaultValue) + { + return string.Empty; + } + + var defaultValue = ps.ExplicitDefaultValue ?? "null"; + return $" = {defaultValue}"; + } public static TypeEnum GetTypeEnum(this IParameterSymbol p) => p.Type.GetTypeEnum(); diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IPerson.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IPerson.g.cs index 6499f7b..fc19b0e 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IPerson.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.IPerson.g.cs @@ -46,6 +46,8 @@ namespace ProxyInterfaceSourceGeneratorTests.Source System.Threading.Tasks.Task Method3Async(); + void CreateInvokeHttpClient(int i = 5, string? appId = null); + diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonProxy.g.cs b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonProxy.g.cs index 07b69b6..a1fe143 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonProxy.g.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Destination/ProxyInterfaceSourceGeneratorTests.Source.PersonProxy.g.cs @@ -105,6 +105,13 @@ namespace ProxyInterfaceSourceGeneratorTests.Source return result__57684656; } + public void CreateInvokeHttpClient(int i = 5, string? appId = null) + { + int i_ = i; + string? appId_ = appId; + _Instance.CreateInvokeHttpClient(i_, appId_); + } + diff --git a/tests/ProxyInterfaceSourceGeneratorTests/Source/Person.cs b/tests/ProxyInterfaceSourceGeneratorTests/Source/Person.cs index b18defe..e0a44bb 100644 --- a/tests/ProxyInterfaceSourceGeneratorTests/Source/Person.cs +++ b/tests/ProxyInterfaceSourceGeneratorTests/Source/Person.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Net.Http; using System.Threading.Tasks; namespace ProxyInterfaceSourceGeneratorTests.Source @@ -67,5 +68,9 @@ namespace ProxyInterfaceSourceGeneratorTests.Source { return Task.FromResult((string?)""); } + + public void CreateInvokeHttpClient(int i = 5, string? appId = null) + { + } } } \ No newline at end of file