- linfu_src.zip
- LinFu.Common
- LinFu.Delegates
- LinFu.DynamicProxy
- LinFu.License.txt
- LinFu.Reflection
- NMock2.dll
- nunit.core.dll
- nunit.framework.dll
- Simple.IoC
- Simple.IoC.Loaders
- Simple.IoC.Tests
- Simple.IoC
- linfupart3_samples.zip
- LinFu.Delegates.Examples
- AdaptingClosuresToAnyDelegateSignature
- bin
- LinFu.Common.dll
- LinFu.Delegates.dll
- LinFu.DynamicProxy.dll
- LinFu.Reflection.dll
- BindingAndUnbindingClosureParameters
- CallingDelegatesBoundToClosuresWithClosedArguments
- ClosuresAndDynamicallyGeneratedMethods
- DelegatesAndArgumentBinding
- InstanceMethodBinding
- LinFu.Delegates.Examples.sln
- NestedClosures
- StaticMethodBinding
- UniversalEventHandling
- UsingClosuresWithDynamicObjects
- LinFu.License.txt
- linfu_bin.zip
- LinFu.Common.dll
- LinFu.Delegates.dll
- LinFu.DynamicProxy.dll
- LinFu.License.txt
- LinFu.Reflection.dll
- NMock2.dll
- nunit.core.dll
- nunit.framework.dll
- Simple.IoC.dll
- Simple.IoC.Loaders.dll
|
using System;
using System.Diagnostics;
using System.Reflection;
using System.Text;
namespace LinFu.DynamicProxy
{
public class InvocationInfo
{
private object[] _args;
private object _proxy;
private MethodInfo _targetMethod;
private StackTrace _trace;
private Type[] _typeArgs;
public InvocationInfo(object proxy, MethodInfo targetMethod,
StackTrace trace, Type[] genericTypeArgs, object[] args)
{
_proxy = proxy;
_targetMethod = targetMethod;
_typeArgs = genericTypeArgs;
_args = args;
_trace = trace;
}
public object Target
{
get { return _proxy; }
}
public MethodInfo TargetMethod
{
get { return _targetMethod; }
}
public StackTrace StackTrace
{
get { return _trace; }
}
public MethodInfo CallingMethod
{
get { return (MethodInfo) _trace.GetFrame(0).GetMethod(); }
}
public Type[] TypeArguments
{
get { return _typeArgs; }
}
public object[] Arguments
{
get { return _args; }
}
public void SetArgument(int position, object arg)
{
_args[position] = arg;
}
public override string ToString()
{
StringBuilder builder = new StringBuilder();
builder.AppendFormat("Calling Method: {0,30:G}\n", GetMethodName(CallingMethod));
builder.AppendFormat("Target Method:{0,30:G}\n", GetMethodName(_targetMethod));
builder.AppendLine("Arguments:");
foreach (ParameterInfo info in _targetMethod.GetParameters())
{
object currentArgument = _args[info.Position];
if (currentArgument == null)
currentArgument = "(null)";
builder.AppendFormat("\t{0,10:G}: {1}\n", info.Name, currentArgument.ToString());
}
builder.AppendLine();
return builder.ToString();
}
private string GetMethodName(MethodInfo method)
{
StringBuilder builder = new StringBuilder();
builder.AppendFormat("{0}.{1}", method.DeclaringType.Name, method.Name);
builder.Append("(");
ParameterInfo[] parameters = method.GetParameters();
int parameterCount = parameters != null ? parameters.Length : 0;
int index = 0;
foreach (ParameterInfo param in parameters)
{
index++;
builder.AppendFormat("{0} {1}", param.ParameterType.Name, param.Name);
if (index < parameterCount)
builder.Append(", ");
}
builder.Append(")");
return builder.ToString();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.