Hi
I'm using PostSharp to apply a CompoundAspect to a ActiveRecord class (from CastleProject). The code looks like this:
public override void ProvideAspects(object targetElement, LaosReflectionAspectCollection collection)
{
Type targetType = (Type)targetElement;
RevertibleSubAspect revertible = new RevertibleSubAspect();
revertible.Cascade = this.Cascade;
collection.AddAspect(targetType, revertible);
//This isn't working
MethodInfo saveMethod = targetType.GetMethod("Save");
collection.AddAspect(saveMethod, new CommitOnSaveSubAspect());
foreach (PropertyInfo property in targetType.GetProperties())
{
if((this.Only != null && this.Only.IndexOf(property.Name) == -1) ||
(this.Except != null && this.Except.IndexOf(property.Name) > -1))
{
continue;
}
if (property.DeclaringType == targetType && property.CanWrite)
{
MethodInfo method = property.GetSetMethod();
if (method != null && !method.IsStatic)
{
collection.AddAspect(method, new TrackInitialPropertyValuesSubAspect());
}
}
}
}
Everything works fine, except the CommitOnSaveSubAspect which is a OnMethodBoundaryAspect. The OnSuccess method never gets called when the Save method is invoked. I have already tried moving the code to OnEntry and OnExit but same situation here.
The CommitOnSaveSubAspect class looks like this:
[Serializable]
class CommitOnSaveSubAspect : OnMethodBoundaryAspect
{
public override void OnSuccess(MethodExecutionEventArgs eventArgs)
{
((IRevertible)eventArgs.Instance).Commit();
}
}
Am I applying the aspect the wrong way?