Let's say I have two classes, the base class has a custom attribute:
[MyAttribute]
public class BaseModel
{
public string Id { get; set; }
public string Name { get; set; }
}
public class InheritedModel : BaseModel
{
public string CompanyName { get; set; }
public int Amount { get; set; }
}
When I'm working with inherited class, like
// member.DeclaringType is InheritedModel
if (member.DeclaringType.GetCustomAttributes(typeof(MyAttribute)).Any())
{
// returns true
}
I expect this should be false
because InheritedModel
has not MyAttribute
attribute directly.
It it correct behaviour? How can I divide parents and inheritors in condition above?