Ref parameters and reflection

前端 未结 5 1953
北恋
北恋 2020-12-29 02:51

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

5条回答
  •  时光取名叫无心
    2020-12-29 03:15

    You need to examine the type of your parameter further. For example if you have

    void Foo(ref int bar)
    

    then the name of the parameter wouldn't be int or Int32 (as you might have expected) but instead Int32&. For every type there is a correspondent by-ref-type where the original type is suffixed by a '&'. You can check this via the IsByRef property of the Type class.

提交回复
热议问题