Get Unity intercepted method information (Unity Interception, IMethodReturn)
I'm using unity interception to audit a method call. Everything works fine: the method is intercepted and I can get the method name and other thinks. I also want to get the result of my method. For example, if my method returns a List<CustomerDto> object I'm only able to access the IMethodReturn.ReturnValue, whose type is an object. In my case, the underlying type of the result is List<CustomerDto> so I can cast the IMethodReturn.ReturnValue return object like this. 
(List<CustomerDto>)IMethodReturn.ReturnValue
Problem:
I have to make this work when I don't know the return type of the intercepted method. That is, the execution of the intercepted method sometimes can return a string type, other a List<CustomerDto>, other a List<CenterDto> and so on. The posibilities are huge.
I need, if possible, a way to convert the IMethodReturn.ReturnValue to the underlying type of the return value of the intercepted method.
The final target is to transform the method result to xml and to save the data in a database. For audit purposes.

Here is the code (sorry for format...)

/// Invoke method
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
    IMethodReturn resultData = getNext()(input, getNext);
    // Injection after method execution.
    this.InjectionCall(input, resultData);          
    return resultData;
}

// Here is the problem...
private void InjectionCall(IMethodInvocation input, IMethodReturn result)
{
    string 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);
}

Thanks.
Get Unity intercepted method information (Unity Interception, IMethodReturn)
===

I'm using unity interception to audit a method call. Everything works fine: the method is intercepted and I can get the method name and other thinks. I also want to get the result of my method. For example, if my method returns a List<CustomerDto> object I'm only able to access the IMethodReturn.ReturnValue, whose type is an object. In my case, the underlying type of the result is List<CustomerDto> so I can cast the IMethodReturn.ReturnValue return object like this. 
(List<CustomerDto>)IMethodReturn.ReturnValue
Problem:
I have to make this work when I don't know the return type of the intercepted method. That is, the execution of the intercepted method sometimes can return a string type, other a List<CustomerDto>, other a List<CenterDto> and so on. The posibilities are huge.
I need, if possible, a way to convert the IMethodReturn.ReturnValue to the underlying type of the return value of the intercepted method.
The final target is to transform the method result to xml and to save the data in a database. For audit purposes.

Here is the code (sorry for format...)

/// Invoke method
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
    IMethodReturn resultData = getNext()(input, getNext);
    // Injection after method execution.
    this.InjectionCall(input, resultData);          
    return resultData;
}

// Here is the problem...
private void InjectionCall(IMethodInvocation input, IMethodReturn result)
{
    string 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);
}

Thanks.