﻿
{"id":4078,"date":"2016-04-20T12:26:05","date_gmt":"2016-04-20T12:26:05","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=4078"},"modified":"2016-04-20T12:26:06","modified_gmt":"2016-04-20T12:26:06","slug":"c-6-0-nameof-expressions","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/c-6-0-nameof-expressions\/","title":{"rendered":"C# 6.0 nameof Expressions"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Kod yazarken class tiplerini yahut metod, property veya field isimlerini string olarak ifade etmemiz gereken noktalar olabilir. \u0130\u015fte b\u00f6yle durumlar i\u00e7in geli\u015ftirilmi\u015f olan C# 6.0 ile gelen nameof keyword\u00fcne de\u011finece\u011fiz.<\/p>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/c-6-0-nameof-expressions\/c-6-0-nameof-expressions\/\" rel=\"attachment wp-att-4079\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4079\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/04\/C-6.0-nameof-Expressions.png\" alt=\"C# 6.0 nameof Expressions\" width=\"442\" height=\"115\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/04\/C-6.0-nameof-Expressions.png 442w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/04\/C-6.0-nameof-Expressions-300x78.png 300w\" sizes=\"auto, (max-width: 442px) 100vw, 442px\" \/><\/a><\/p>\n<p>\u00d6rnek olarak ArgumentNullException s\u0131n\u0131f\u0131n\u0131 ele alabiliriz. Bu s\u0131n\u0131ftan bir nesne olu\u015ftururken constructer\u0131nda &#8220;paramName&#8221; isimli parametre ile, kontrol edilen parametrenin ismini string olarak vermekteyiz.<\/p>\n<p>Benzer \u015fekilde,<\/p>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/c-6-0-nameof-expressions\/c-6-0-nameof-expressions-2\/\" rel=\"attachment wp-att-4080\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4080\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/04\/C-6.0-nameof-Expressions-1.png\" alt=\"C# 6.0 nameof Expressions\" width=\"607\" height=\"368\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/04\/C-6.0-nameof-Expressions-1.png 607w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/04\/C-6.0-nameof-Expressions-1-300x182.png 300w\" sizes=\"auto, (max-width: 607px) 100vw, 607px\" \/><\/a><\/p>\n<p>INotifyPropertyChanged interfaceini ele al\u0131rsak e\u011fer olay\u0131n tetiklenme esnas\u0131nda ilgili propertynin ad\u0131n\u0131 yukar\u0131da g\u00f6rd\u00fc\u011f\u00fcn\u00fcz gibi string olarak almaktad\u0131r.<\/p>\n<p>\u0130\u015fte bu tarz \u00f6rnek olaylara benzer durumlarda ilgili property, metod, class, field, parametre yahut de\u011fi\u015fken(ki art\u0131k hangi eleman\u0131n ismini string belirtmemiz gerektiren durumsa) ismi de\u011fi\u015fti\u011finde string olarak belirtilen ifadenin i\u00e7erisindeki isim de\u011fi\u015fmeyece\u011finden dolay\u0131 hatayla kar\u015f\u0131la\u015faca\u011f\u0131z.<\/p>\n<p>C# 6.0 ile gelen nameof anahtar s\u00f6zc\u00fc\u011f\u00fc ile ilgili memberlar\u0131n\u00a0hardcoded isimlerini kullanma zorunlulu\u011funu ortadan kald\u0131rd\u0131\u011f\u0131 i\u00e7in bu olas\u0131 durumda bir member\u0131n ismi de\u011fi\u015firse o membera ba\u011fl\u0131 nameof tan\u0131mlamar\u0131 derleyici hatalar\u0131n\u0131 verecek ve biz yaz\u0131l\u0131mc\u0131lar\u0131 samanl\u0131kta i\u011fne aramaktan kurtacakt\u0131r.<\/p>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/c-6-0-nameof-expressions\/c-6-0-nameof-expressions-3\/\" rel=\"attachment wp-att-4082\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4082\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/04\/C-6.0-nameof-Expressions.gif\" alt=\"C# 6.0 nameof Expressions\" width=\"360\" height=\"92\" \/><\/a><\/p>\n<p>G\u00f6rd\u00fc\u011f\u00fcn\u00fcz gibi eski kullan\u0131m tarz\u0131nda string ifade i\u00e7erisindeki\u00a0hardcoded olarak tutulan member ismini unutma olas\u0131l\u0131\u011f\u0131ndan olas\u0131 hatay\u0131 alma oran\u0131m\u0131z y\u00fcksekken,<\/p>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/c-6-0-nameof-expressions\/c-6-0-nameof-expressions-4\/\" rel=\"attachment wp-att-4083\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4083\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/04\/C-6.0-nameof-Expressions-1.gif\" alt=\"C# 6.0 nameof Expressions\" width=\"360\" height=\"87\" \/><\/a><\/p>\n<p>nameof anahtar s\u00f6zc\u00fc\u011f\u00fc sayesinde de\u011fi\u015fen member ismi an\u0131nda edit\u00f6r arac\u0131l\u0131\u011f\u0131yla de\u011fi\u015ftirilebilmektedir. Edit\u00f6r kullanarak de\u011fi\u015ftirmesenizde derleyici hatas\u0131 size an\u0131nda ilgili hatay\u0131 g\u00f6sterecektir.<\/p>\n<p>Compiler nameof keyword\u00fcn\u00fc g\u00f6rd\u00fc\u011f\u00fc yerlerde ilgili ismi hardcoded ediyor ve ilgili noktaya string olarak bas\u0131yor. Bu mant\u0131kta a\u015fa\u011f\u0131daki kod blo\u011fu \u00f6rnek te\u015fkil etmektedir.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    class OrnekClass\r\n    {\r\n        public string OrnekField;\r\n        public decimal OrnekField2;\r\n        public int OrnekProperty { get; set; }\r\n        public bool OrnekProperty2 { get; set; }\r\n        public void OrnekMetod() { }\r\n        public int OrnekMetod2() =&gt; 1;\r\n    }\r\n\r\n    class Program\r\n    {\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            OrnekClass o = new OrnekClass();\r\n            Console.WriteLine(nameof(o));\r\n            Console.WriteLine(nameof(o.OrnekField));\r\n            Console.WriteLine(nameof(o.OrnekField2));\r\n            Console.WriteLine(nameof(o.OrnekProperty));\r\n            Console.WriteLine(nameof(o.OrnekProperty2));\r\n            Console.WriteLine(nameof(o.OrnekMetod));\r\n            Console.WriteLine(nameof(o.OrnekMetod2));\r\n        \r\n            Console.Read();\r\n        }\r\n    }\r\n<\/pre>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/c-6-0-nameof-expressions\/c-6-0-nameof-expressions-5\/\" rel=\"attachment wp-att-4085\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2016\/04\/C-6.0-nameof-Expressions-2.png\" alt=\"C# 6.0 nameof Expressions\" width=\"132\" height=\"150\" class=\"aligncenter size-full wp-image-4085\" \/><\/a><\/p>\n<p>nameof anahtar s\u00f6zc\u00fc\u011f\u00fc her ne kadar ufak bir i\u015flev gibi g\u00f6z\u00fcksede biz yaz\u0131l\u0131mc\u0131lar i\u00e7in olas\u0131 hatal\u0131 kodlardan kurtarmakta ve C# dilini kullan\u0131\u015fl\u0131l\u0131k a\u00e7\u0131s\u0131ndan bir ad\u0131m daha ileri ta\u015f\u0131maktad\u0131r.<\/p>\n<p>Sonraki yaz\u0131lar\u0131mda g\u00f6r\u00fc\u015fmek \u00fczere&#8230;<\/p>\n<p>\u0130yi \u00e7al\u0131\u015fmalar&#8230;<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Merhaba, Kod yazarken class tiplerini yahut metod, property veya field isimlerini string olarak ifade etmemiz gereken noktalar olabilir. \u0130\u015fte b\u00f6yle durumlar i\u00e7in geli\u015ftirilmi\u015f olan C# 6.0 ile gelen nameof keyword\u00fcne de\u011finece\u011fiz. \u00d6rnek olarak ArgumentNullException&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":3223,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,720],"tags":[1106,27,724,1105,1103,1104],"class_list":["post-4078","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-sharp-c","category-c-6-0","tag-argumentnullexception","tag-c","tag-c-6-0","tag-inotifypropertychanged","tag-nameof","tag-nameof-expressions"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/4078","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=4078"}],"version-history":[{"count":0,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/4078\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/3223"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=4078"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=4078"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=4078"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}