Skip to content

Commit c63960a

Browse files
authored
Merge pull request #18 from PawelGerr/claude/remove-interface-diagnostic-8eDBb
Skip TTRESG104 diagnostic for interface properties
2 parents 3b7a96f + a550145 commit c63960a

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/Diagnostics/ThinktectureRuntimeExtensionsAnalyzer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ private static void AnalyzePropertyDisallowingDefaultValues(SyntaxNodeAnalysisCo
251251
|| context.ContainingSymbol is not IPropertySymbol propertySymbol
252252
|| propertySymbol.SetMethod is null // public MyStruct Member { get; }
253253
|| propertySymbol.IsStatic
254+
|| propertySymbol.ContainingType.TypeKind == TypeKind.Interface // interfaces cannot have required members
254255
|| propertySymbol.DeclaredAccessibility < propertySymbol.ContainingType.DeclaredAccessibility // required members must not be less visible than the containing type
255256
|| propertySymbol.SetMethod.DeclaredAccessibility < propertySymbol.ContainingType.DeclaredAccessibility) // setter of required members must not be less visible than the containing type
256257
return;

test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/AnalyzerAndCodeFixTests/TTRESG104_MembersDisallowingDefaultValuesMustBeRequired.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,27 @@ public partial class TestClass
187187
await Verifier.VerifyAnalyzerAsync(code, [typeof(ComplexValueObjectAttribute).Assembly]);
188188
}
189189

190+
[Fact]
191+
public async Task Should_not_trigger_on_interface_property()
192+
{
193+
var code = """
194+
195+
using System;
196+
using Thinktecture;
197+
using Thinktecture.Runtime.Tests.TestValueObjects;
198+
199+
namespace TestNamespace
200+
{
201+
public interface IMyInterface
202+
{
203+
IntBasedStructValueObjectDoesNotAllowDefaultStructs DisallowingProperty { get; set; }
204+
}
205+
}
206+
""";
207+
208+
await Verifier.VerifyAnalyzerAsync(code, [typeof(ValueObjectAttribute<>).Assembly, typeof(IntBasedStructValueObjectDoesNotAllowDefaultStructs).Assembly]);
209+
}
210+
190211
[Fact]
191212
public async Task Should_not_trigger_on_special_type_property()
192213
{

0 commit comments

Comments
 (0)