jeudi 7 avril 2016

Check if Generic Interface Member has Attribute

I have an interface with methods annotated with the Pure attribute from System.Diagnostics.Contracts:

public interface IFoo<T> {
    [Pure]
    T First { get; }

    [Pure]
    T Last { get; }

    [Pure]
    T Choose();

    void Add(T item);

    T Remove();
}

I wish to iterate over the members and check if the member is pure or not. Currently I'm not able to get any attributes from the member info:

var type = typeof(IFoo<>);
var memberInfos = type.GetMembers();
var memberInfo = memberInfos.First(); // <-- Just select one of them
var attributes = memberInfo.GetCustomAttributesData(); // <-- Empty

What am I missing?





Aucun commentaire:

Enregistrer un commentaire