{"id":224,"date":"2013-08-20T11:31:17","date_gmt":"2013-08-20T14:31:17","guid":{"rendered":"http:\/\/gianfratti.com\/?p=224"},"modified":"2013-08-20T11:31:17","modified_gmt":"2013-08-20T14:31:17","slug":"propriedades-automaticas","status":"publish","type":"post","link":"https:\/\/gianfratti.com\/index.php\/propriedades-automaticas\/","title":{"rendered":"Propriedades Autom\u00e1ticas"},"content":{"rendered":"<p><span style=\"font-family: Trebuchet MS; font-size: medium;\">A partira da vers\u00e3o 3.0 a linguagem C# introduziu as <strong>propriedades autom\u00e1ticas<\/strong>. Uma propriedade \u00e9 constitu\u00edda basicamente de vari\u00e1vel privada, que \u00e9 exposta ao mundo exterior atrav\u00e9s de <b>getters e setters<\/b>. O exemplo a seguir mostra isso:<!--more--><\/span><\/p>\n<table border=\"0\">\n<tbody>\n<tr>\n<td bgcolor=\"#FFFFBB\"><span style=\"font-family: Trebuchet MS;\">\u00a0\u00a0\u00a0 public class Pessoa<br \/>\n{<br \/>\nprivate string _nome;<br \/>\npublic string Nome<br \/>\n{<br \/>\nget { return _nome; }<br \/>\nset { _nome = value; }<br \/>\n}<br \/>\nprivate string _email;<br \/>\npublic string Email<br \/>\n{<br \/>\nget { return _email; }<br \/>\nset { _email = value; }<br \/>\n}<br \/>\n}<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-family: Trebuchet MS; font-size: medium;\">Usando as propriedades autom\u00e1ticas podemos reduzir o c\u00f3digo acima para:<\/span><\/p>\n<table border=\"0\">\n<tbody>\n<tr>\n<td bgcolor=\"#E8E8E8\"><span style=\"font-family: Trebuchet MS;\">\u00a0\u00a0\u00a0 public class Pessoa<br \/>\n{<br \/>\npublic string Nome { get; set; }<br \/>\npublic string Email { get; set; }<br \/>\n}<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-family: Trebuchet MS; font-size: medium;\">O compilador C # gera automaticamente uma vari\u00e1vel de apoio e as propriedades corretas get e set. <\/span><\/p>\n<p><span style=\"font-family: Trebuchet MS; font-size: medium;\">E da\u00ed ??<\/span><\/p>\n<p><span style=\"font-family: Trebuchet MS; font-size: medium;\">E da\u00ed que definindo a vari\u00e1vel como uma propriedade vai permitir a voc\u00ea adicionar a l\u00f3gica de valida\u00e7\u00e3o para sua classe, numa fase posterior. Como assinatura na mem\u00f3ria da classe n\u00e3o vai mudar o que significa que quaisquer bibliotecas externas compiladas com o seu c\u00f3digo n\u00e3o ter\u00e3o que ser recompiladas.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A partira da vers\u00e3o 3.0 a linguagem C# introduziu as propriedades autom\u00e1ticas. Uma propriedade \u00e9 constitu\u00edda basicamente de vari\u00e1vel privada, que \u00e9 exposta ao mundo exterior atrav\u00e9s de getters e setters. O exemplo a seguir mostra isso: <span class=\"ellipsis\">&hellip;<\/span> <span class=\"more-link-wrap\"><a href=\"https:\/\/gianfratti.com\/index.php\/propriedades-automaticas\/\" class=\"more-link\"><span>Read More &rarr;<\/span><\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-224","post","type-post","status-publish","format-standard","hentry","category-net-framework"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/posts\/224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/comments?post=224"}],"version-history":[{"count":1,"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/posts\/224\/revisions"}],"predecessor-version":[{"id":225,"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/posts\/224\/revisions\/225"}],"wp:attachment":[{"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/media?parent=224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/categories?post=224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/tags?post=224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}