-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
S2699 Reproducer for AssertionMethodAttribute is ignored when assertion method is inherited #6528
S2699 Reproducer for AssertionMethodAttribute is ignored when assertion method is inherited #6528
Conversation
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the result of the following snippet it seems to me that this is not a FP.
The following will print 'false' both with this implementation and with the base.MyMethod();
call inside Child MyMethod().
It seems to me that once overriden the attributes are lost. For this reason I think the CustomAssertionMethod()
within this test case is not decorated by [AssertionMethod]
attribute anymore, hence raising the issue. WDYT?
[AttributeUsage(AttributeTargets.Method)]
public class MyAttribute : Attribute { }
public class Parent
{
[My]
public virtual void MyMethod() { }
}
public class Child : Parent
{
public override void MyMethod() { }
}
public class MainClass
{
public static void Main() =>
Console.WriteLine(typeof(Child).GetMember("MyMethod")
.SelectMany(m => m.CustomAttributes)
.Any());
}
The code will print
using System;
using System.Linq;
[AttributeUsage(AttributeTargets.Method, Inherited = true)]
public class MyAttribute : Attribute { }
public class Parent
{
[My]
public virtual void MyMethod() { }
}
public class Child : Parent
{
public override void MyMethod() { }
}
public class MainClass
{
public static void Main() =>
Console.WriteLine(typeof(Child).GetMember("MyMethod")
.SelectMany(m => m.GetCustomAttributes(inherit: true))
.OfType<MyAttribute>()
.Any());
} So we should check if there is an |
Test for #6525