Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Loading