{"id":1784,"date":"2016-10-17T17:10:09","date_gmt":"2016-10-17T15:10:09","guid":{"rendered":"http:\/\/blog.rabahi.net\/?page_id=1784"},"modified":"2016-10-17T17:10:09","modified_gmt":"2016-10-17T15:10:09","slug":"cs-partial-class-region","status":"publish","type":"page","link":"https:\/\/blog.rabahi.net\/?page_id=1784","title":{"rendered":"cs Partial class \/ region"},"content":{"rendered":"<p>To deal with better visibility you can split your code in multiples partial classes.<br \/>\nAlso, you can deal with region.<\/p>\n<h1>Point of start<\/h1>\n<p>Let&#8217;s deal with the following implementation (MyClass.cs):<\/p>\n<pre lang=\"csharp\">\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading.Tasks;\r\n\r\nnamespace WpfApp.Assets\r\n{\r\n    class MyClass\r\n    {\r\n        internal int param1 { get; set; }\r\n\r\n        internal int param2 { get; set; }\r\n\r\n        private void increaseParam1()\r\n        {\r\n            this.param1++;\r\n        }\r\n\r\n        private void increaseParam2()\r\n        {\r\n            this.param2++;\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>This code is short, but if you add more code, it will be hardest to read it (for example > 10 000 lines !!).<\/p>\n<h2>Region<\/h2>\n<p>You can use region to hide\/show some part of your code :<\/p>\n<pre lang=\"csharp\">\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading.Tasks;\r\n\r\nnamespace WpfApp.Assets\r\n{\r\n    class MyClass\r\n    {\r\n        #region \"param1\"\r\n        internal int param1 { get; set; }        \r\n\r\n        private void increaseParam1()\r\n        {\r\n            this.param1++;\r\n        }\r\n        #endregion\r\n\r\n        #region \"param2\"\r\n        internal int param2 { get; set; }\r\n\r\n        private void increaseParam2()\r\n        {\r\n            this.param2++;\r\n        }\r\n        #endregion\r\n    }\r\n}\r\n<\/pre>\n<h2>You can split your code in partial classes<\/h2>\n<p>MyClass.cs :<\/p>\n<pre lang=\"csharp\">\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading.Tasks;\r\n\r\nnamespace WpfApp.Assets\r\n{\r\n    parial class MyClass\r\n    {\r\n        internal int param1 { get; set; }        \r\n        internal int param2 { get; set; }\r\n    }\r\n}\r\n<\/pre>\n<p>MyClassMethodParam1.cs :<\/p>\n<pre lang=\"csharp\">\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading.Tasks;\r\n\r\nnamespace WpfApp.Assets\r\n{\r\n    parial class MyClass\r\n    {\r\n        private void increaseParam1()\r\n        {\r\n            this.param1++;\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>MyClassMethodParam2.cs :<\/p>\n<pre lang=\"csharp\">\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading.Tasks;\r\n\r\nnamespace WpfApp.Assets\r\n{\r\n    parial class MyClass\r\n    {\r\n        private void increaseParam2()\r\n        {\r\n            this.param2++;\r\n        }\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To deal with better visibility you can split your code in multiples partial classes. Also, you can deal with region. Point of start Let&#8217;s deal with the following implementation (MyClass.cs): using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace WpfApp.Assets { class MyClass { internal int param1 { get; set; } internal int [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1767,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1784","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1784","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1784"}],"version-history":[{"count":2,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1784\/revisions"}],"predecessor-version":[{"id":1786,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1784\/revisions\/1786"}],"up":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1767"}],"wp:attachment":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1784"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}