Patrik Hägne Patrik Hägne - 1 month ago 7
C# Question

Ref parameters and reflection

I'm not sure if I'm totally missing something here but I can't find any way to determine if a parameter is passed by reference or not by using reflection.

ArgumentInfo has a property "IsOut", but no "IsRef". How would I go about to get all reference parameters in a given MethodInfo?

Answer
ParameterInfo[] parameters = myMethodInfo.GetParameters();
foreach(ParameterInfo parameter in parameters)
{
    bool isRef = parameterInfo.ParameterType.IsByRef;
}
Comments