I am using postsharp to log method call and i need to log the parameter values also.
my problem comes in when i have parameters that are generic lists and i cant iterate through the list to get the values in it.
i know how to check if the parameter is a list but i just cant read through the values in it…
is it possible to read through the list and how would i go about doing this?
for (int i = 0; i < args.Arguments.Count; i++)
{
if (methodName == "LogonUser" && i == 1)
{
sb.Append(",********");
break;
}
else if (i > 0)
{
sb.Append(", ");
}
if (args.Arguments[i] is IList && args.Arguments[i].GetType().IsGenericType)
{
//here is where i need to read through the list
}
sb.Append(args.Arguments.GetArgument(i) ?? "null");
}
If you only want to iterate through the argument, when its a (generic) list you can
check the argument if it implements the interface IEnumerable and then loop the values
in the list with a foreach statement.