From 02e671371ef016abd379cb4ef7ec4be0a6c21eda Mon Sep 17 00:00:00 2001 From: daver32 <38791383+daver32@users.noreply.github.com> Date: Sun, 15 Aug 2021 16:31:06 +0200 Subject: [PATCH] Added record's Deconstruct method support --- .../RecordInterfaceGenerationTests.cs | 17 +++++++++++++++++ InterfaceGenerator/AutoInterfaceGenerator.cs | 5 +++-- InterfaceGenerator/InterfaceGenerator.csproj | 2 +- InterfaceGenerator/TextWriterExtensions.cs | 1 - 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/InterfaceGenerator.Tests/RecordInterfaceGenerationTests.cs b/InterfaceGenerator.Tests/RecordInterfaceGenerationTests.cs index d300119..b69bc15 100644 --- a/InterfaceGenerator.Tests/RecordInterfaceGenerationTests.cs +++ b/InterfaceGenerator.Tests/RecordInterfaceGenerationTests.cs @@ -42,6 +42,23 @@ namespace InterfaceGenerator.Tests _sut.RecordMethod(); } + + [Fact] + public void Deconstruct_IsGenerated() + { + var method = typeof(ITestRecord).GetMethod( + nameof(TestRecord.Deconstruct)); + + method.Should().NotBeNull(); + method.ReturnType.Should().Be(typeof(void)); + + var parameters = method.GetParameters(); + parameters.Length.Should().Be(1); + + var parameter = parameters[0]; + parameter.ParameterType.Should().Be(typeof(int).MakeByRefType()); + parameter.IsOut.Should().BeTrue(); + } } [GenerateAutoInterface] diff --git a/InterfaceGenerator/AutoInterfaceGenerator.cs b/InterfaceGenerator/AutoInterfaceGenerator.cs index 056602a..b06f513 100644 --- a/InterfaceGenerator/AutoInterfaceGenerator.cs +++ b/InterfaceGenerator/AutoInterfaceGenerator.cs @@ -273,9 +273,10 @@ namespace InterfaceGenerator return; } - if (methodSymbol.IsImplicitlyDeclared) + if (methodSymbol.IsImplicitlyDeclared && methodSymbol.Name != "Deconstruct") { - // omit methods that are auto generated by the compiler (eg. record's methods) + // omit methods that are auto generated by the compiler (eg. record's methods), + // except for the record Deconstruct method return; } diff --git a/InterfaceGenerator/InterfaceGenerator.csproj b/InterfaceGenerator/InterfaceGenerator.csproj index 83495a2..e30788b 100644 --- a/InterfaceGenerator/InterfaceGenerator.csproj +++ b/InterfaceGenerator/InterfaceGenerator.csproj @@ -3,7 +3,7 @@ netstandard2 9.0 enable - 1.0.6 + 1.0.7 true false diff --git a/InterfaceGenerator/TextWriterExtensions.cs b/InterfaceGenerator/TextWriterExtensions.cs index cc77368..2c25a61 100644 --- a/InterfaceGenerator/TextWriterExtensions.cs +++ b/InterfaceGenerator/TextWriterExtensions.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; namespace InterfaceGenerator {