{"id":197,"date":"2007-10-04T09:04:45","date_gmt":"2007-10-04T16:04:45","guid":{"rendered":"http:\/\/kennyw.com\/general\/197"},"modified":"2007-10-04T09:04:45","modified_gmt":"2007-10-04T16:04:45","slug":"behind-the-protected-bindingelement-ctor","status":"publish","type":"post","link":"https:\/\/kennyw.com\/?p=197","title":{"rendered":"Behind the protected BindingElement ctor"},"content":{"rendered":"<p>On our <a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/system.servicemodel.channels.bindingelement.aspx\">BindingElement<\/a> class, there is a <a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/ms404915.aspx\">protected ctor<\/a>&nbsp;that takes another BindingElement as its parameter. This constructor exists in order to facilitate a composable implementation of <a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/system.servicemodel.channels.bindingelement.aspx\">BindingElement.Clone<\/a>.&nbsp; When writing a custom binding element, first implement a protected copy constructor as follows (note that for sealed classes this ctor should be private):<\/p>\n<p><code class=\"keyword\">protected <\/code><code>MyBindingElement(<\/code><code class=\"classname\">MyBindingElement<\/code><code> elementToBeCloned)<br \/>&nbsp;&nbsp; : base(elementToBeCloned)<br \/>{<br \/>&nbsp; <\/code><code class=\"comment\">\/\/ copy all fields from elementToBeCloned.XXX to this.XXX<br \/><\/code><code>}<\/code> <\/p>\n<p>Then you should implement your Clone() method as follows:<\/p>\n<p><code class=\"keyword\">public override<\/code><code class=\"classname\"> BindingElement<\/code><code> Clone()<br \/>{<br \/><\/code><code class=\"keyword\">&nbsp; return new<\/code><code> MyBindingElement(<\/code><code class=\"keyword\">this<\/code><code>);<br \/>}<\/code>  <\/p>\n<p>Any BindingElement in your inheritance chain (assuming it has&nbsp;followed this pattern) will then copy over the relevant values in its copy constructor, so that you can be assured a full Clone of your custom binding element.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>On our BindingElement class, there is a protected ctor&nbsp;that takes another BindingElement as its parameter. This constructor exists in order to facilitate a composable implementation of BindingElement.Clone.&nbsp; When writing a custom binding element, first implement a protected copy constructor as follows (note that for sealed classes this ctor should be private): protected MyBindingElement(MyBindingElement elementToBeCloned)&nbsp;&nbsp; : [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-197","post","type-post","status-publish","format-standard","hentry","category-indigo"],"_links":{"self":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts\/197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=197"}],"version-history":[{"count":0,"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts\/197\/revisions"}],"wp:attachment":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}