2013-01-31 179 views
0

從一個服務方法的參數給定一個ParameterInfo,我想檢查這個參數是否是一個輸出類型。是否足以檢查ParameterType最後是否包含&符號?我注意到像System.String這樣的對象在輸出類型時變成了System.String&,或者,有沒有更好的方法來檢查它?如何檢查服務方法的參數類型是否爲給定參數的ParameterInfo的輸出類型?

+0

你的意思是該屬性使用'out'關鍵字嗎? http://msdn.microsoft.com/en-us/library/system.reflection.parameterinfo.isout.aspx –

回答

1

ParameterInfo p = ...;

bool isOutParam =(p.Attributes & System.Reflection.ParameterAttributes.Out)== System.Reflection.ParameterAttributes.Out;

+2

或者:'bool isOutParam = p.IsOut;'http://msdn.microsoft.com/en-gb /library/system.reflection.parameterinfo.isout.aspx –

+0

謝謝,這是完美的傢伙。正是我想要的。 – Alexandru

相關問題