This project is read-only.

CallMethodPointcut Does Not Detect get_*


The CallMethodPointcut.cs class is used for "SelectCallMethods" yet it is unable to locate method calls used to retrieve properties (i.e. calls with method names "get_*"). This is due to the MethodPoint constructor, line 12:
    public MethodPointcut()
        Where(m => !m.IsConstructor && !m.IsSpecialName);
Method calls used to retrieve properties apparently use a "Special Name" and thus this criteria above, automatically applied to CallMethodPointcut, prevents such discovery.

Might I recommend commenting out "&& !m.IsSpecialName" thereby ensuring that "get_*" method call property retrievals are returned in the SelectCallMethods results? What scenarios are you concerned about where ensuring that the method is not a constructor is not enough (i.e. what besides constructors do we actually need to exclude)?

My vote is for special names to be included in the results...


hendryluk wrote May 30, 2013 at 5:05 AM

You can use [SelectPropertyMethods] for your purpose, which specifically targets the situations you describe. And similarly with [SelectConstructors] for constructors.
[SelectMethod] will specifically only select methods to avoid accidental matches resulted by compiler-generated methods that aren't actually visible to developers.

esheri3 wrote May 30, 2013 at 5:43 AM

I was using SelectCallMethods as I needed the advice woven in at the
instruction level. SelectPropertyMethods assumes that I have the DLL
with a class declaring the getters and setters of the target property,
correct? This is not the case in my environment - I don't have that
information available. Since SelectGetProperties is not currently
implemented, I tried a work-around with SelectCallMethods.

Any other ideas that I could try?

hendryluk wrote Jun 12, 2013 at 2:07 PM

Sorry for the delay.
SelectGetProperties (and Set) is indeed something that hasn't been included. However in the meantime you could use the following implementation in your solution (which leverages the ability to extend SheepAspect and SAQL with your own custom pointcuts).
public class SelectGetProperties : SaqlPointcutAttribute
    public SelectGetProperties(string saql)
        : base(saql)

    protected override IPointcut CreatePointcut(AspectDefinition aspect, string pointcutName)
        return aspect.AddPointcut<GetPropertyPointcut>(pointcutName);

public class PropertyGetPointcut : InstructionPointcut<PropertyGetPointcut>
    private readonly PropertyMethodPointcut _propertyMethodPointcut = new PropertyMethodPointcut();

    public PropertyGetPointcut()

            (m,i) =>
            (i.OpCode == OpCodes.Call || i.OpCode == OpCodes.Callvirt) &&

    public void WhereProperty(PropertyPointcut methodPointcut)
To use it, you define your pointcut as the following:
Eventually this will make it to the next iteration, once I implement adequate tests and features around it.
Hope that helps.


esheri3 wrote Oct 3, 2014 at 6:55 PM

Any luck getting this capability integrated into SheepAspect? I have a need to use SelectCallMethods-like capabilities to wrap calls to retrieve property values and set property values.