From 696601ef1806a3861085589ee6069293f21fe8f5 Mon Sep 17 00:00:00 2001 From: daver32 <38791383+daver32@users.noreply.github.com> Date: Sat, 22 Oct 2022 21:17:09 +0200 Subject: [PATCH] fix for Nullable default values --- InterfaceGenerator.Tests/MethodGenerationTests.cs | 12 +++++++++--- InterfaceGenerator/AutoInterfaceGenerator.cs | 3 +++ InterfaceGenerator/InterfaceGenerator.csproj | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/InterfaceGenerator.Tests/MethodGenerationTests.cs b/InterfaceGenerator.Tests/MethodGenerationTests.cs index a59a1f3..fb9a748 100644 --- a/InterfaceGenerator.Tests/MethodGenerationTests.cs +++ b/InterfaceGenerator.Tests/MethodGenerationTests.cs @@ -213,7 +213,7 @@ public class MethodGenerationTests method.ReturnType.Should().Be(typeof(void)); var parameters = method.GetParameters(); - parameters.Should().HaveCount(7); + parameters.Should().HaveCount(10); parameters.Select(x => x.IsOptional).Should().AllBeEquivalentTo(true); parameters[0].DefaultValue.Should().Be("cGFyYW0="); @@ -223,7 +223,10 @@ public class MethodGenerationTests parameters[4].DefaultValue.Should().Be(0.3d); parameters[5].DefaultValue.Should().Be(true); parameters[6].DefaultValue.Should().Be(false); - + parameters[7].DefaultValue.Should().Be(true); + parameters[8].DefaultValue.Should().Be(false); + parameters[9].DefaultValue.Should().Be(null); + _sut.VoidMethodWithOptionalParams(); } @@ -319,7 +322,10 @@ internal class MethodsTestService : IMethodsTestService double doubleLiteral = 0.2, decimal decimalLiteral = 0.3m, bool trueLiteral = true, - bool falseLiteral = false) + bool falseLiteral = false, + bool? nullableTrueLiteral = true, + bool? nullableFalseLiteral = false, + bool? nullableNullBoolLiteral = null) { } diff --git a/InterfaceGenerator/AutoInterfaceGenerator.cs b/InterfaceGenerator/AutoInterfaceGenerator.cs index c7b2852..4bc8c51 100644 --- a/InterfaceGenerator/AutoInterfaceGenerator.cs +++ b/InterfaceGenerator/AutoInterfaceGenerator.cs @@ -399,6 +399,9 @@ namespace InterfaceGenerator case nameof(Boolean): writer.Write(" = {0}", param.ExplicitDefaultValue.ToString().ToLower()); break; + case nameof(Nullable): + writer.Write(" = {0}", param.ExplicitDefaultValue.ToString().ToLower()); + break; default: writer.Write(" = {0}", param.ExplicitDefaultValue); break; diff --git a/InterfaceGenerator/InterfaceGenerator.csproj b/InterfaceGenerator/InterfaceGenerator.csproj index f272122..521840d 100644 --- a/InterfaceGenerator/InterfaceGenerator.csproj +++ b/InterfaceGenerator/InterfaceGenerator.csproj @@ -3,7 +3,7 @@ netstandard2 9.0 enable - 1.0.11 + 1.0.12 true false