{"id":478,"date":"2015-11-27T23:22:29","date_gmt":"2015-11-27T23:22:29","guid":{"rendered":"cfee398643cbc3dc5eefc89334cacdc1"},"modified":"2015-11-27T23:22:29","modified_gmt":"2015-11-27T23:22:29","slug":"","status":"publish","type":"post","link":"https:\/\/www.xiaobo.li\/notes\/archives\/478","title":{"rendered":"ParameterInfo properties, attributes and out ref parameters of the methods"},"content":{"rendered":"<div class=\"post-text\" itemprop=\"text\">\n<p>\u5f15\u7528: http:\/\/stackoverflow.com\/questions\/15636969\/parameterinfo-properties-attributes-and-out-ref-parameters-of-the-methods<\/p>\n<p>Well, I'm confused by the properties of the <code>ParameterInfo<\/code> class.<br \/>\nUnfortunately documentation is not very clear: examples show how to build methods but don't show how these methods look in C#.<\/p>\n<p>Cane somebody tell more about these properties:<\/p>\n<ul>\n<li><code>DefaultValue<\/code><\/li>\n<li><code>HasDefaultValue<\/code><\/li>\n<li><code>IsIn<\/code><\/li>\n<li><code>IsLcid<\/code><\/li>\n<li><code>IsOptional<\/code><\/li>\n<li><code>IsOut<\/code><\/li>\n<li><code>IsRetval<\/code><\/li>\n<\/ul>\n<p>And which combination leads to what method params.<br \/>\nI made a simple program which gives the following output:<\/p>\n<p><em>Method name M1<\/em> <code>void M1(object param)<\/code><br \/>\nIL signature: <code>.method public hidebysig instance void  M1(object param) cil managed<\/code><br \/>\nMethod parameter description:<br \/>\nIs passed by reference False<br \/>\nHasDefaultValue=False<br \/>\nIsIn=False<br \/>\nIsLcid=False<br \/>\nIsOptional=False<br \/>\nIsOut=False<br \/>\nIsRetVal=False<\/p>\n<p>\n<em>Method name M2<\/em>  <code>void M2(object param = null)<\/code><br \/>\nIL signature <code>.method public hidebysig instance void  M2([opt] object param) cil managed<\/code><br \/>\nMethod parameter description:<br \/>\nIs passed by reference False<br \/>\n<strong>HasDefaultValue=True<\/strong><br \/>\nDefaultValue=null<br \/>\nIsIn=False<br \/>\nIsLcid=False<br \/>\n<strong>IsOptional=True<\/strong><br \/>\nIsOut=False<br \/>\nIsRetVal=False<\/p>\n<p>\n<em>Method name M3<\/em> <code>void M3(out object param)<\/code><br \/>\nIL signature <code>.method public hidebysig instance void  M3([out] object&amp; param) cil managed<\/code><br \/>\nMethod parameter description:<br \/>\nIs passed <strong>by reference True<\/strong><br \/>\nHasDefaultValue=False<br \/>\nIsIn=False<br \/>\nIsLcid=False<br \/>\nIsOptional=False<br \/>\n<strong>IsOut=True<\/strong><br \/>\nIsRetVal=False<\/p>\n<p>\n<em>Method name M4<\/em> <code>void M4(ref object param)<\/code><br \/>\nIL signature <code>.method public hidebysig instance void  M4(object&amp; param) cil managed<\/code><br \/>\nMethod parameter description:<br \/>\nIs passed <strong>by reference True<\/strong><br \/>\nHasDefaultValue=False<br \/>\nIsIn=False<br \/>\nIsLcid=False<br \/>\nIsOptional=False<br \/>\nIsOut=False<br \/>\nIsRetVal=False<\/p>\n<p>\n<em>Method name M5<\/em> <code>void M5([In] object param)<\/code><br \/>\nIL signature <code>.method public hidebysig instance void  M5([in] object param) cil managed<\/code><br \/>\nMethod parameter description:<br \/>\nIs passed by reference False<br \/>\nHasDefaultValue=False<br \/>\n<strong>IsIn=True<\/strong><br \/>\nIsLcid=False<br \/>\nIsOptional=False<br \/>\nIsOut=False<br \/>\nIsRetVal=False<\/p>\n<p>\n<em>Method name M6<\/em> <code>void M6([Out] object param)<\/code><br \/>\nIL signature <code>.method public hidebysig instance void  M6([out] object param) cil managed<\/code><br \/>\nMethod parameter description:<br \/>\nIs passed by reference False<br \/>\nHasDefaultValue=False<br \/>\nIsIn=False<br \/>\nIsLcid=False<br \/>\nIsOptional=False<br \/>\n<strong>IsOut=True<\/strong><br \/>\nIsRetVal=False<\/p>\n<p>\n<em>Method name M7<\/em> <code>void M7([Out] out object param)<\/code><br \/>\nIL signature <code>.method public hidebysig instance void  M7([out] object&amp; param) cil managed<\/code><br \/>\nMethod parameter description:<br \/>\nIs passed <strong>by reference True<\/strong><br \/>\nHasDefaultValue=False<br \/>\nIsIn=False<br \/>\nIsLcid=False<br \/>\nIsOptional=False<br \/>\n<strong>IsOut=True<\/strong><br \/>\nIsRetVal=False<\/p>\n<p>\n<em>Method name M8<\/em> <code>void M8([DefaultValue(null)] object param)<\/code><br \/>\nIL signature <code>.method public hidebysig instance void  M8(object param) cil managed<\/code><br \/>\nMethod parameter description:<br \/>\nIs passed by reference False<br \/>\nHasDefaultValue=False<br \/>\nIsIn=False<br \/>\nIsLcid=False<br \/>\nIsOptional=False<br \/>\nIsOut=False<br \/>\nIsRetVal=False<\/p>\n<p>\n<em>Method name M9<\/em> <code>void M9([DefaultValue(-10)] int param = 10)<\/code><br \/>\nIL signature <code>.method public hidebysig instance void  M9([opt] int32 param) cil managed<\/code><br \/>\nMethod parameter description:<br \/>\nParameter name param<br \/>\nIs passed by reference False<br \/>\n<strong>HasDefaultValue=True<\/strong><br \/>\nDefaultValue=10<br \/>\nIsIn=False<br \/>\nIsLcid=False<br \/>\n<strong>IsOptional=True<\/strong><br \/>\nIsOut=False<br \/>\nIsRetVal=False<\/p>\n<p>\n<em>Method name M10<\/em> <code>void M10([Optional] int param)<\/code><br \/>\nIL signature <code>.method public hidebysig instance void  M10([opt] int32 param) cil managed<\/code><br \/>\nMethod parameter description:<br \/>\nIs passed by reference False<br \/>\nHasDefaultValue=False<br \/>\nIsIn=False<br \/>\nIsLcid=False<br \/>\n<strong>IsOptional=True<\/strong><br \/>\nIsOut=False<br \/>\nIsRetVal=False<\/p>\n<p>I guess <code>In<\/code>, <code>Out<\/code> and <code>Optional<\/code> attributes relate to COM as they are located in System.Runtime.InteropServices namesapce.<br \/>\nBut again documentation is quite poor. \ud83d\ude41<\/p>\n<p>And what is RetVal and where it is used?<\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<div class=\"post-text\" itemprop=\"text\">\n<p>\u5f15\u7528: http:\/\/stackoverflow.com\/questions\/15636969\/parameterinfo-properties-attributes-and-out-ref-parameters-of-the-methods<\/p>\n<p>Well, I'm confused by the properties of the <code>ParameterInfo<\/code> class.<br \/>\nUnfortunately documentation is not very clear: examples show how to build methods but don't show how these meth...<\/p>\n<\/div>\n<p> <a href=\"https:\/\/www.xiaobo.li\/notes\/archives\/478\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[279],"tags":[],"class_list":["post-478","post","type-post","status-publish","format-standard","hentry","category-dotnet"],"_links":{"self":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts\/478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/comments?post=478"}],"version-history":[{"count":0,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts\/478\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/media?parent=478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/categories?post=478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/tags?post=478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}