{"id":1223,"date":"2020-06-23T16:57:39","date_gmt":"2020-06-23T04:57:39","guid":{"rendered":"https:\/\/www.ronella.xyz\/?p=1223"},"modified":"2020-06-23T16:57:39","modified_gmt":"2020-06-23T04:57:39","slug":"extension-methods","status":"publish","type":"post","link":"https:\/\/www.ronella.xyz\/?p=1223","title":{"rendered":"Extension Methods"},"content":{"rendered":"<p>The method that allows to add methods to existing type without creating a new derived type, recompiling, or otherwise modifying the original type.<\/p>\n<p><strong>A method signature template with a return value and an argument<\/strong><\/p>\n<pre style=\"white-space: pre;\">public static &lt;T_RETURN&gt; &lt;METHOD_NAME&gt;(this &lt;T_TYPE&gt; &lt;VAR_NAME&gt;, &lt;T_ARG1_TYPE&gt; &lt;ARG1_NAME&gt;)\r\n<\/pre>\n<table>\n<tbody>\n<tr>\n<td><strong>Token<\/strong><\/td>\n<td><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td>T_RETURN<\/td>\n<td>The type of the return value.<\/td>\n<\/tr>\n<tr>\n<td>METHOD_NAME<\/td>\n<td>The desired name of the method.<\/td>\n<\/tr>\n<tr>\n<td>T_TYPE<\/td>\n<td>The existing type to extend.<\/td>\n<\/tr>\n<tr>\n<td>VAR_NAME<\/td>\n<td>The holder of an instance of the T_TYPE<\/td>\n<\/tr>\n<tr>\n<td>T_ARG1_TYPE<\/td>\n<td>Type of the first argument.<\/td>\n<\/tr>\n<tr>\n<td>ARG1_NAME<\/td>\n<td>The name of the first argument.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>This method is actually a <strong>static method<\/strong> but the <strong>first argument<\/strong> has the keyword <strong>this<\/strong> and the <strong>target type<\/strong> to extend. Also it holds the <strong>instance of the target type<\/strong>.<\/p>\n<p>The <strong>T_RETURN<\/strong> and the <strong>argument part<\/strong> of the template are optional. Also the argument is not limited to just one, you can have as many as required by your extension.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The method that allows to add methods to existing type without creating a new derived type, recompiling, or otherwise modifying the original type. A method signature template with a return value and an argument public static &lt;T_RETURN&gt; &lt;METHOD_NAME&gt;(this &lt;T_TYPE&gt; &lt;VAR_NAME&gt;, &lt;T_ARG1_TYPE&gt; &lt;ARG1_NAME&gt;) Token Description T_RETURN The type of the return value. METHOD_NAME The desired name [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[53],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1223"}],"collection":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1223"}],"version-history":[{"count":1,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1223\/revisions"}],"predecessor-version":[{"id":1224,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1223\/revisions\/1224"}],"wp:attachment":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}