{"id":828,"date":"2013-11-29T14:10:10","date_gmt":"2013-11-29T14:10:10","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=828"},"modified":"2013-11-29T14:10:55","modified_gmt":"2013-11-29T14:10:55","slug":"attributes-of-return-values-in-c","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/attributes-of-return-values-in-c\/","title":{"rendered":"Attributes on return values in C#"},"content":{"rendered":"<p>What&#8217;s the C# syntax for applying an attribute to a return type ?<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n&#x5B;return: SomeAttribute()]\r\npublic string GatValue()\r\n{\r\n    return&quot;Some Value&quot;;\r\n}\r\n<\/pre>\n<p>Here&#8217;s a simple example of a custom attribute used for return types<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n&#x5B;AttributeUsage(AttributeTargets.ReturnValue, AllowMultiple = false)]\r\nclass MyAttribute : Attribute\r\n{\r\n   public string Description { get; set; }\r\n}\r\n\r\npublic class SomeClass\r\n{\r\n   &#x5B;return: MyAttribute(Description = &quot;A Return Value&quot;)]\r\n   public string GetValue()\r\n   {\r\n      return &quot;Hello World&quot;;\r\n   }\r\n}\r\n\r\nclass Program\r\n{\r\n   static void Main(string&#x5B;] args)\r\n   {\r\n      object&#x5B;] attributes = typeof (SomeClass).\r\n                  GetMethod(&quot;GetValue&quot;).\r\n                  ReturnTypeCustomAttributes.\r\n                  GetCustomAttributes(false);\r\n   }\r\n}\r\n<\/pre>\n<p>This will return a single item in the object[] of type MyAttribute.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What&#8217;s the C# syntax for applying an attribute to a return type ? &#x5B;return: SomeAttribute()] public string GatValue() { return&quot;Some Value&quot;; } Here&#8217;s a simple example of a custom attribute used for return types &#x5B;AttributeUsage(AttributeTargets.ReturnValue, AllowMultiple = false)] class MyAttribute : Attribute { public string Description { get; set; } } public class SomeClass { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-828","post","type-post","status-publish","format-standard","hentry","category-c"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/828","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=828"}],"version-history":[{"count":4,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/828\/revisions"}],"predecessor-version":[{"id":845,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/828\/revisions\/845"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}