C#/Resharper 5 structural search, detect and warn if any non-virtual public methods on classes with

Posted by chillitom on Stack Overflow See other posts from Stack Overflow or by chillitom
Published on 2010-04-16T12:41:23Z Indexed on 2010/04/16 12:43 UTC
Read the original article Hit count: 353

Hi All,

I'm using LinFu's dynamic proxy to add some advice to some classes. The problem is that the proxied objects can only intercept virtual methods and will return the return type's default value for non-virtual methods.

I can tell whether a class is proxied or not based whether the class or any of it's method has an interception attribute, e.g. [Transaction]

Is it possible to write a ReSharper 5 structural search that would warn if any non-virtual public methods are defined on a class with an interception attribute.

E.g.

Ok

public class InterceptedClass
{
    [Transaction]
    public virtual void TransactionalMethod()
    {
       ...
    }

    public virtual void AnotherMethod()
    {
       ...
    }
}

Bad

public class InterceptedClass
{
    [Transaction]
    public virtual void TransactionalMethod()
    {
       ...
    }

    public void AnotherMethod() // non-virtual method will not be called by proxy
    {
       ...
    }
}

Many Thanks.

© Stack Overflow or respective owner

Related posts about c#

Related posts about resharper-5.0