Skip to content

Commit

Permalink
Exclude obsolete property from 'required' rule
Browse files Browse the repository at this point in the history
  • Loading branch information
sliekens committed Oct 5, 2024
1 parent 24b4578 commit 4f2bded
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions GW2SDK.Tests/PatternsAndPractices/RequireAssignmentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4f2bded

Please sign in to comment.