Search code examples
c#vb.netinterfaceattributesunity-interception

VB.net Attributes on properties get and set


The scenario is that we have written a debugger interceptor using Unity to easily wrap an object to write the timelapse it takes for a method to complete. Sadly, it is also writing all public property get and set invokations. So we simply put an attribute on the property to exclude it from tracing. Something like:

Property Example { [ExcludeFromTracing]get; [ExcludeFromTracing]set; }

Since:

ExcludeFromTracing
Property Example { get; set; }

Does not work, as the get and set get compiled to their own methods which will get intercepted at runtime.

So this works for us in C#... now the challenge comes, we also have legacy vb.net applications were we have performance issues and simply want to add this interceptor to pinpoint the bottlenecks in our application.

Sadly I can't find the vb.net equivalent of adding an attribute to a property get and set methods in an interface? Or any other way of excluding the interception of property invocations using unity.interception


Solution

  • You could check if the IsSpecialName flag is set to filter out compiler generated getters and setters (and events etc...).

    I guess you're using an IInterceptionBehavior. In the Invoke method, check for input.MethodBase.IsSpecialName.