Retrieve Attribute from an interface method
<p>How do I retrieve an attribute from an interface method my class implements? </p>

<p>Edit: I dont know the interface at the time, only the type of the class, or an instance of that class.</p>

<p>Edit: Added the inherited flag to the attribute but it has no effect.</p>

<pre><code>[TestFixture]
public class MyTests {
    [Test]
    public void shouldGetMyAttribute() {
        var type = typeof (MyClass);
        var method = type.GetMethod("MyMethod");
        var attributes = method.GetCustomAttributes(true);
        var myAttribute = attributes.SingleOrDefault(x =&gt; x is MyAttributeAttribute);
        Assert.That(myAttribute, Is.Not.Null);
    }
}

public class MyClass : IMyInterface {
    public void MyMethod() {
        throw new NotImplementedException();
    }
}

public interface IMyInterface {
    [MyAttribute]
    void MyMethod();
}

[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class MyAttributeAttribute : Attribute {}
</code></pre>
