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.
Argumen
ParameterType.IsByRef
will return true
for both ref
and out
parameters.
If you have a ParameterInfo
object (e.g. from MethodInfo.GetParameters()
), then:
out
if parameterInfo.ParameterType.IsByRef && parameterInfo.IsOut
ref
if parameterInfo.ParameterType.IsByRef && parameterInfo.IsOut == false
If you don't do the IsByRef
check for out
parameters, then you'll incorrectly get members decorated with the [Out]
attribute from System.Runtime.InteropServices
but which aren't actually C# out
parameters.