I want to provide an implementation of System.Object.ToString to various classes using PostSharp. I've created an aspect inheriting from MethodInterceptionAspect but the OnInvoke method isn't getting invoked when a call to EchoDto.ToString takes place.
How can I get OnInvoke to be called when ToString is called?
[DataContract]
[ImplementJsonToStringAspect()]
public class EchoDto
{
[DataMember]
public string Text { get; set; }
}
[Serializable]
[MulticastAttributeUsage(MulticastTargets.Method)]
public class ImplementJsonToStringAspect : MethodInterceptionAspect
{
public override void OnInvoke(MethodInterceptionArgs args)
{
base.OnInvoke(args); // Never gets called
}
public override bool CompileTimeValidate(MethodBase method)
{
return method.Name == "ToString";
}
}