1
我有MethodInterceptionAspect
(PostSharp)的實現 但是當我在覆蓋OnInvoke
法,args.Method
爲null, 我需要知道方法的返回值類型,Postsharp MethodInterceptionAspect獲得方法的返回值
任何人都知道?
[PSerializable]
public class PSHandleRequestAttribute : MethodInterceptionAspect
{
public PSHandleRequestAttribute(bool readOnly = true) : base()
{
ReadOnly = readOnly;
}
#region Properties
protected bool ReadOnly { get; set; }
#endregion Properties
#region Public Methods
public override void OnInvoke(MethodInterceptionArgs args)
{
var instance = args.Instance as IBusinessTransaction;
var method = args.Method;
if (instance.IsNull())
{
throw new Exception("Use PSHandleRequestAttribute only for IBusinessTransaction");
}
instance.OpenTransaction();
try
{
args.Proceed();
//base.OnInvoke(args);
instance.CommitTransaction();
return;
}
catch (Exception ex)
{
var errorMessage = instance.RollbackTransaction(ex);
return;
}
}
#endregion Public Methods
}
感謝!,它的工作!,還可以在'CompileTimeValidate'中保存返回值類型,並在運行時使用 – Shoshana