だから、私が持っている場合:
public class Sedan : Car
{
/// ...
}
public class Car : Vehicle, ITurn
{
[MyCustomAttribute(1)]
public int TurningRadius { get; set; }
}
public abstract class Vehicle : ITurn
{
[MyCustomAttribute(2)]
public int TurningRadius { get; set; }
}
public interface ITurn
{
[MyCustomAttribute(3)]
int TurningRadius { get; set; }
}
次のようなことを行うためにどのような魔法を使用できますか:
[Test]
public void Should_Use_Magic_To_Get_CustomAttributes_From_Ancestry()
{
var property = typeof(Sedan).GetProperty("TurningRadius");
var attributes = SomeMagic(property);
Assert.AreEqual(attributes.Count, 3);
}
両方
property.GetCustomAttributes(true);
と
Attribute.GetCustomAttributes(property, true);
1 つの属性のみを返します。インスタンスは、MyCustomAttribute(1) で構築されたものです。これは期待どおりに動作しないようです。