Type objT = typeof(Program);
Type fromBodyT = typeof(FromBodyAttribute);
MethodInfo method = objT.GetMethod("Test");
ParameterInfo[] paramsInfo = method.GetParameters();
var parameters= new List<object>(paramsInfo.Length);
foreach (ParameterInfo parameterInfo in paramsInfo)
{
var parameter = new object();
if (parameterInfo.CustomAttributes.Any(i => i.AttributeType == fromBodyT))
parameter = message.Body;
parameters.Add(parameter);
}
object result = method.Invoke(null, parameters.ToArray());
Console.WriteLine(result);
}
public class FromBodyAttribute : Attribute
{
}
public static string Test([FromBody] string body)
{
return body;
}
class MessageData
{
public string Body { get; set; }
public string Header { get; set; }
public string Footer { get; set; }