init properties support
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using FluentAssertions;
|
||||
using System.Runtime.CompilerServices;
|
||||
using FluentAssertions;
|
||||
using FluentAssertions.Common;
|
||||
using Xunit;
|
||||
|
||||
@@ -42,6 +43,22 @@ namespace InterfaceGenerator.Tests
|
||||
_sut.PublicProperty = string.Empty;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InitProperty_IsImplemented()
|
||||
{
|
||||
var prop = typeof(IAccessorsTestsService)
|
||||
.GetProperty(nameof(IAccessorsTestsService.InitOnlyProperty));
|
||||
|
||||
prop.Should().NotBeNull();
|
||||
|
||||
prop.GetMethod.Should().NotBeNull();
|
||||
prop.SetMethod.Should().NotBeNull();
|
||||
|
||||
prop.SetMethod.ReturnParameter.GetRequiredCustomModifiers().Should().Contain(typeof(IsExternalInit));
|
||||
|
||||
string _ = _sut.InitOnlyProperty;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PrivateSetter_IsOmitted()
|
||||
{
|
||||
@@ -128,6 +145,8 @@ namespace InterfaceGenerator.Tests
|
||||
}
|
||||
|
||||
public string PublicProperty { get; set; }
|
||||
|
||||
public string InitOnlyProperty { get; init; }
|
||||
|
||||
public string PropertyWithPrivateSetter { get; private set; }
|
||||
|
||||
|
||||
@@ -254,7 +254,14 @@ namespace InterfaceGenerator
|
||||
|
||||
if (hasPublicSetter)
|
||||
{
|
||||
writer.Write("set; ");
|
||||
if (propertySymbol.SetMethod!.IsInitOnly)
|
||||
{
|
||||
writer.Write("init; ");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write("set; ");
|
||||
}
|
||||
}
|
||||
|
||||
writer.WriteLine("}");
|
||||
|
||||
Reference in New Issue
Block a user