From 4f2bdedb6a365d40ec41c3bae41361d22b585410 Mon Sep 17 00:00:00 2001 From: Steven Liekens Date: Sat, 5 Oct 2024 13:25:52 +0000 Subject: [PATCH] Exclude obsolete property from 'required' rule --- .../PatternsAndPractices/RequireAssignmentTest.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/GW2SDK.Tests/PatternsAndPractices/RequireAssignmentTest.cs b/GW2SDK.Tests/PatternsAndPractices/RequireAssignmentTest.cs index 9120b1657..5b6ee825d 100644 --- a/GW2SDK.Tests/PatternsAndPractices/RequireAssignmentTest.cs +++ b/GW2SDK.Tests/PatternsAndPractices/RequireAssignmentTest.cs @@ -13,14 +13,19 @@ public void Data_transfer_object_members_are_required() actual => { Assert.True( - IsRequired(actual), + IsCompliant(actual), $"{actual.DeclaringType?.Name}.{actual.Name} must be read-only or read-write and marked as 'required'." ); } ); - static bool IsRequired(PropertyInfo actual) + static bool IsCompliant(PropertyInfo actual) { + if (actual.CustomAttributes.Any(annotation => annotation.AttributeType == typeof(ObsoleteAttribute))) + { + return true; + } + return !actual.CanWrite || actual.CustomAttributes.Any( annotation => annotation.AttributeType.Name == "RequiredMemberAttribute"