diff --git a/src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/Diagnostics/ThinktectureRuntimeExtensionsAnalyzer.cs b/src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/Diagnostics/ThinktectureRuntimeExtensionsAnalyzer.cs index 1df7ace4..4c8312c6 100644 --- a/src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/Diagnostics/ThinktectureRuntimeExtensionsAnalyzer.cs +++ b/src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/Diagnostics/ThinktectureRuntimeExtensionsAnalyzer.cs @@ -251,6 +251,7 @@ private static void AnalyzePropertyDisallowingDefaultValues(SyntaxNodeAnalysisCo || context.ContainingSymbol is not IPropertySymbol propertySymbol || propertySymbol.SetMethod is null // public MyStruct Member { get; } || propertySymbol.IsStatic + || propertySymbol.ContainingType.TypeKind == TypeKind.Interface // interfaces cannot have required members || propertySymbol.DeclaredAccessibility < propertySymbol.ContainingType.DeclaredAccessibility // required members must not be less visible than the containing type || propertySymbol.SetMethod.DeclaredAccessibility < propertySymbol.ContainingType.DeclaredAccessibility) // setter of required members must not be less visible than the containing type return; diff --git a/test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/AnalyzerAndCodeFixTests/TTRESG104_MembersDisallowingDefaultValuesMustBeRequired.cs b/test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/AnalyzerAndCodeFixTests/TTRESG104_MembersDisallowingDefaultValuesMustBeRequired.cs index 0fb8c476..e1c5e90a 100644 --- a/test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/AnalyzerAndCodeFixTests/TTRESG104_MembersDisallowingDefaultValuesMustBeRequired.cs +++ b/test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/AnalyzerAndCodeFixTests/TTRESG104_MembersDisallowingDefaultValuesMustBeRequired.cs @@ -187,6 +187,27 @@ public partial class TestClass await Verifier.VerifyAnalyzerAsync(code, [typeof(ComplexValueObjectAttribute).Assembly]); } + [Fact] + public async Task Should_not_trigger_on_interface_property() + { + var code = """ + + using System; + using Thinktecture; + using Thinktecture.Runtime.Tests.TestValueObjects; + + namespace TestNamespace + { + public interface IMyInterface + { + IntBasedStructValueObjectDoesNotAllowDefaultStructs DisallowingProperty { get; set; } + } + } + """; + + await Verifier.VerifyAnalyzerAsync(code, [typeof(ValueObjectAttribute<>).Assembly, typeof(IntBasedStructValueObjectDoesNotAllowDefaultStructs).Assembly]); + } + [Fact] public async Task Should_not_trigger_on_special_type_property() {