{"id":63,"date":"2011-02-02T12:33:00","date_gmt":"2011-02-02T12:33:00","guid":{"rendered":"https:\/\/wdev-blog.azurewebsites.net\/index.php\/2011\/02\/02\/logging-properties-of-an-instance-object\/"},"modified":"2011-02-02T12:33:00","modified_gmt":"2011-02-02T12:33:00","slug":"logging-properties-of-an-instance-object","status":"publish","type":"post","link":"http:\/\/www.panahy.nl\/index.php\/2011\/02\/02\/logging-properties-of-an-instance-object\/","title":{"rendered":"Logging Properties of an instance object"},"content":{"rendered":"<p>Logging is an ongoing subject that I had some posts about it. In this post I am adding two methods to my beloved Logger class.<br \/>The first one shows the values of each property where the property is readable while the second method tries to show the signature of the method.<\/p>\n<pre><span style=\"color: #808080;\">\/\/\/<\/span><span style=\"color: #008000;\"> <\/span><span style=\"color: #808080;\">&lt;summary&gt;<\/span><span style=\"color: #008000;\"><br \/><\/span><span style=\"color: #808080;\">\/\/\/<\/span><span style=\"color: #008000;\"> Shows the public properties<br \/><\/span><span style=\"color: #808080;\">\/\/\/<\/span><span style=\"color: #008000;\"> <\/span><span style=\"color: #808080;\">&lt;\/summary&gt;<\/span><span style=\"color: #008000;\"><br \/><\/span><span style=\"color: #808080;\">\/\/\/<\/span><span style=\"color: #008000;\"> <\/span><span style=\"color: #808080;\">&lt;param name=\"instance\"&gt;&lt;\/param&gt;<\/span><span style=\"color: #008000;\"><br \/><\/span><span style=\"color: #0000FF;\">public<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">static<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">void<\/span><span style=\"color: #000000;\"> ShowPropertyValues(<\/span><span style=\"color: #0000FF;\">object<\/span><span style=\"color: #000000;\">  instance)<br \/>{<br \/> var  instanceType = instance.GetType();<br \/> Information(<\/span><span style=\"color: #800000;\">\"&gt;&gt;&gt; Showing Instance Properties: \"<\/span><span style=\"color: #000000;\">  + instanceType.Name);<br \/><br \/> var  props = instanceType.GetProperties();<br \/> <\/span><span style=\"color: #0000FF;\">foreach<\/span><span style=\"color: #000000;\">  (var  property <\/span><span style=\"color: #0000FF;\">in<\/span><span style=\"color: #000000;\">  props)<br \/> {<br \/>   <\/span><span style=\"color: #0000FF;\">if<\/span><span style=\"color: #000000;\">  (!property.CanRead) <\/span><span style=\"color: #0000FF;\">continue<\/span><span style=\"color: #000000;\"> ; <\/span><span style=\"color: #008000;\">\/\/'t read! <\/span><span style=\"color: #000000;\"><br \/>   Information(<\/span><span style=\"color: #0000FF;\">string<\/span><span style=\"color: #000000;\"> .Format(<\/span><span style=\"color: #800000;\">\"Instance.{0} ='{1}'\"<\/span><span style=\"color: #000000;\"> , property.Name, property.GetValue(instance, <\/span><span style=\"color: #0000FF;\">null<\/span><span style=\"color: #000000;\"> )));<br \/> }<br \/>}<br \/><br \/><\/span><span style=\"color: #808080;\">\/\/\/<\/span><span style=\"color: #008000;\"> <\/span><span style=\"color: #808080;\">&lt;summary&gt;<\/span><span style=\"color: #008000;\"><br \/><\/span><span style=\"color: #808080;\">\/\/\/<\/span><span style=\"color: #008000;\"> Shows the public properties<br \/><\/span><span style=\"color: #808080;\">\/\/\/<\/span><span style=\"color: #008000;\"> <\/span><span style=\"color: #808080;\">&lt;\/summary&gt;<\/span><span style=\"color: #008000;\"><br \/><\/span><span style=\"color: #808080;\">\/\/\/<\/span><span style=\"color: #008000;\"> <\/span><span style=\"color: #808080;\">&lt;param name=\"instance\"&gt;&lt;\/param&gt;<\/span><span style=\"color: #008000;\"><br \/><\/span><span style=\"color: #0000FF;\">public<\/span><span style=\"color: #000000;\">  <\/span><span style=\"color: #0000FF;\">static<\/span><span style=\"color: #000000;\">  <\/span><span style=\"color: #0000FF;\">void<\/span><span style=\"color: #000000;\">  ShowPropertySignature(<\/span><span style=\"color: #0000FF;\">object<\/span><span style=\"color: #000000;\">  instance)<br \/>{<br \/> var  instanceType = instance.GetType();<br \/> Information(<\/span><span style=\"color: #800000;\">\"&gt;&gt;&gt; Showing Type Properties: \"<\/span><span style=\"color: #000000;\">  + instanceType.Name);<br \/><br \/> var  props = TypeDescriptor .GetProperties(instance);<br \/> <\/span><span style=\"color: #0000FF;\">foreach<\/span><span style=\"color: #000000;\">  (PropertyDescriptor  prop <\/span><span style=\"color: #0000FF;\">in<\/span><span style=\"color: #000000;\">  props)<br \/> {<br \/>   Information(<\/span><span style=\"color: #800000;\">\"----------------------------------------------------\"<\/span><span style=\"color: #000000;\"> );<br \/>   Information(<\/span><span style=\"color: #0000FF;\">string<\/span><span style=\"color: #000000;\"> .Format(<\/span><span style=\"color: #800000;\">\"Name ='\"<\/span><span style=\"color: #000000;\"> , prop.Name));<br \/>   Information(<\/span><span style=\"color: #0000FF;\">string<\/span><span style=\"color: #000000;\"> .Format(<\/span><span style=\"color: #800000;\">\"DisplayName ='\"<\/span><span style=\"color: #000000;\"> , prop.DisplayName));<br \/>   Information(<\/span><span style=\"color: #0000FF;\">string<\/span><span style=\"color: #000000;\"> .Format(<\/span><span style=\"color: #800000;\">\"Description ='\"<\/span><span style=\"color: #000000;\"> , prop.Description));<br \/>   Information(<\/span><span style=\"color: #0000FF;\">string<\/span><span style=\"color: #000000;\"> .Format(<\/span><span style=\"color: #800000;\">\"ComponentType ='\"<\/span><span style=\"color: #000000;\"> , prop.ComponentType.Name));<br \/>   Information(<\/span><span style=\"color: #0000FF;\">string<\/span><span style=\"color: #000000;\"> .Format(<\/span><span style=\"color: #800000;\">\"Category ='\"<\/span><span style=\"color: #000000;\"> , prop.Category));<br \/>   Information(<\/span><span style=\"color: #0000FF;\">string<\/span><span style=\"color: #000000;\"> .Format(<\/span><span style=\"color: #800000;\">\"IsBrowsable ='\"<\/span><span style=\"color: #000000;\"> , prop.IsBrowsable));<br \/>   Information(<\/span><span style=\"color: #0000FF;\">string<\/span><span style=\"color: #000000;\"> .Format(<\/span><span style=\"color: #800000;\">\"IsLocalizable ='\"<\/span><span style=\"color: #000000;\"> , prop.IsLocalizable));<br \/>   Information(<\/span><span style=\"color: #0000FF;\">string<\/span><span style=\"color: #000000;\"> .Format(<\/span><span style=\"color: #800000;\">\"IsReadOnly ='\"<\/span><span style=\"color: #000000;\"> , prop.IsReadOnly));<br \/>   Information(<\/span><span style=\"color: #0000FF;\">string<\/span><span style=\"color: #000000;\"> .Format(<\/span><span style=\"color: #800000;\">\"PropertyType ='\"<\/span><span style=\"color: #000000;\"> , prop.PropertyType.Name));<br \/>   Information(<\/span><span style=\"color: #0000FF;\">string<\/span><span style=\"color: #000000;\"> .Format(<\/span><span style=\"color: #800000;\">\"SerializationVisibility ='\"<\/span><span style=\"color: #000000;\"> , prop.SerializationVisibility));<br \/>   Information(<\/span><span style=\"color: #0000FF;\">string<\/span><span style=\"color: #000000;\"> .Format(<\/span><span style=\"color: #800000;\">\"SupportsChangeEvents ='\"<\/span><span style=\"color: #000000;\"> , prop.SupportsChangeEvents));<br \/> }<br \/>}<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Logging is an ongoing subject that I had some posts about it. In this post I am adding two methods to my beloved Logger class.The first one shows the values of each property where the property is readable while the second method tries to show the signature of the method. \/\/\/ &lt;summary&gt;\/\/\/ Shows the public &hellip; <a href=\"http:\/\/www.panahy.nl\/index.php\/2011\/02\/02\/logging-properties-of-an-instance-object\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Logging Properties of an instance object&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[59,60],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"post-thumbnail":false},"uagb_author_info":{"display_name":"Pouya Panahy","author_link":"http:\/\/www.panahy.nl\/index.php\/author\/pouya\/"},"uagb_comment_info":0,"uagb_excerpt":"Logging is an ongoing subject that I had some posts about it. In this post I am adding two methods to my beloved Logger class.The first one shows the values of each property where the property is readable while the second method tries to show the signature of the method. \/\/\/ &lt;summary&gt;\/\/\/ Shows the public&hellip;","_links":{"self":[{"href":"http:\/\/www.panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/63"}],"collection":[{"href":"http:\/\/www.panahy.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.panahy.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.panahy.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.panahy.nl\/index.php\/wp-json\/wp\/v2\/comments?post=63"}],"version-history":[{"count":0,"href":"http:\/\/www.panahy.nl\/index.php\/wp-json\/wp\/v2\/posts\/63\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.panahy.nl\/index.php\/wp-json\/wp\/v2\/media?parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.panahy.nl\/index.php\/wp-json\/wp\/v2\/categories?post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.panahy.nl\/index.php\/wp-json\/wp\/v2\/tags?post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}