jeudi 18 octobre 2018

How to get the declaring member of implementing one?

I am working with PostSharp and I cannot figure out how to get to declaring member (in my case it is method). Say I would like to write some custom null validation for arguments (using OnMethodBoundaryAspect) and I would like to apply my aspect right on the interface level.

When I do this when, and OnEntry is triggered:

public override void OnEntry(MethodExecutionArgs args)
{
    args.Method...?
} 

I get the implemented method (the one which was actually called) but I need the "original", declaring one. For example:

class Speaker : ISpeaker
{
    public string Say(); // I get access to this method...
}

interface ISpeaker
{
    [MyCustomAspect]
    string Say();  // ... and I need to get this one
}

It seems that using reflection I can get only to first implementation, not declaration. And on the other hand attribute or Postsharp aspect do no keep any information for which member they were applied (at least I didn't find it).

So how to get to it?

For the record, I need to apply aspects at interface level, it is a must.





Aucun commentaire:

Enregistrer un commentaire