On your request; this should work:
public override void OnActionExecuting(HttpActionContext actionContext)
{
var dictionary = actionContext.ActionArguments;
//key will contain the key, for convenience.
foreach (var key in dictionary.Keys)
{
//the value
var val = dictionary[key];
if (val is string)
{
//the value is runtime type of string
//do what you want with it.
}
}
}
As for the follow up, have a look at this:
https://stackoverflow.com/a/20554262/2416958 . Combine with the "PrintProperties" method, and you should get somewhere.
Be aware of cyclic references though ;-)
Modified version (credits: https://stackoverflow.com/a/20554262/2416958):
note: is not protected against cyclic references.
public void ScanProperties(object obj)
{
if (obj == null) return;
Type objType = obj.GetType();
PropertyInfo[] properties = objType.GetProperties();
foreach (PropertyInfo property in properties)
{
object propValue = property.GetValue(obj, null);
var elems = propValue as IEnumerable;
if (elems != null)
{
foreach (var item in elems)
{
ScanProperties(item);
}
}
else
{
// This will not cut-off System.Collections because of the first check
if (propValue is string)
{
//do you validation routine
}
ScanProperties(propValue);
}
}
}
And call it like:
public override void OnActionExecuting(HttpActionContext actionContext)
{
var dictionary = actionContext.ActionArguments;
//key will contain the key, for convenience.
foreach (var key in dictionary.Keys)
{
//the value
ScanProperties(dictionary[key]);
}
}