我正在使用Unity拦截来审核方法调用。一切正常:该方法被拦截,我可以得到方法名称和其他想法。我也想获得方法的结果。例如,如果我的方法返回一个列表对象,我只能访问imethodreturn.turnvalue,其类型是对象。就我而言,结果的基本类型是列表,因此我可以施放Imethodreturn.ReturnValue返回对象。 (列表)Imethodreturn.ReturnValue问题:当我不知道截距方法的返回类型时,我必须做这项工作。也就是说,被拦截方法的执行有时可以返回字符串类型,其他列表,其他列表等。该产品是巨大的。如果可能的话,我需要一种将imethodreturn的方法转换为截止方法的返回值的基础类型。最终目标是将方法结果转换为XML并将数据保存在数据库中。出于审计目的。

这是代码(对不起,格式...)

/// Invoke方法公共Imethodreturn Invoke(Imethodinvocation输入,getNexthandlerdelegate getNext){imethododreturn resultdata = getNext()(input,getNext); //方法执行后注入。 this.IndoctionCall(输入,resultdata);
返回结果达塔; }

//这是问题...私有void indectionCall(imethodinvocation输入,imethodreturn结果){字符串methodname = input.methodbase.name;

// How to get the 
//List<object> resultList = (List<object>)result.ReturnValue   ???
//Type type = resultData.ReturnValue.GetType()

// Calling the audit service. IocFactory is the container helper object.
//IAuditService srvAudit = IocFactory.Resolve<IAuditService>();
//srvAudit.RegisterData(methodName,null,null);

}

谢谢。

有帮助吗?

解决方案

真正的问题是,从拦截方法返回的对象的转换不仅仅是拦截本身的问题。我通过将对象序列到XML来解决。我发现的解决方案是在此链接中:

序列化对象到xmldocument

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top