﻿
{"id":1308,"date":"2013-01-26T14:59:05","date_gmt":"2013-01-26T14:59:05","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=1308"},"modified":"2013-01-26T15:03:50","modified_gmt":"2013-01-26T15:03:50","slug":"c-5-0-caller-information","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/c-5-0-caller-information\/","title":{"rendered":"C# 5.0 Caller Information"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Bu yaz\u0131mda C# 5.0 ile gelen Caller Information \u00f6zelli\u011fine de\u011finece\u011fiz.Caller Information(\u00c7a\u011f\u0131ran \u00d6zellikleri) nedir k\u0131saca \u00f6zetlemek gerekirse, c\u00fcmlenin T\u00fcrk\u00e7e telafuzu bir nevi ip ucu vermektedir.Bir metodun nereden(hangi metod taraf\u0131ndan) \u00e7a\u011fr\u0131ld\u0131\u011f\u0131 bilgisine ula\u015fabilmemizi sa\u011flayan yap\u0131d\u0131r.Bu yap\u0131n\u0131n kullan\u0131m alanlar\u0131na de\u011findikten sonra programatik yap\u0131s\u0131n\u0131 inceleyelim.<br \/>\n<!--more--><\/p>\n<p>Herhangi bir i\u015flem i\u00e7in olu\u015fturdu\u011fumuz bir fonksiyonu projemizin \u00e7o\u011fu yerinde \u00e7a\u011f\u0131r\u0131p kulland\u0131\u011f\u0131m\u0131z\u0131 farz edelim.Proje derlenip \u00e7al\u0131\u015ft\u0131\u011f\u0131 a\u015famada fornksiyonumuz i\u00e7erisinde bir hata verirse e\u011fer, nerede hata ald\u0131\u011f\u0131m\u0131z\u0131 zor kestirebiliriz.\u00c7\u00fcnk\u00fc \u00e7o\u011fu yerde bu fonksiyonu kulland\u0131\u011f\u0131m\u0131zdan dolay\u0131 hangi kod dosyas\u0131nda oldu\u011funu, hangi metod da ya da hangi sat\u0131rda oldu\u011funu bulabilmek i\u00e7in debug modunda \u00e7al\u0131\u015ft\u0131r\u0131p sat\u0131r sat\u0131r incelemeniz gerekmektedir.<\/p>\n<p>\u0130\u015fte bu gibi durumlar\u0131n \u00fcstesinden rahat bir \u015fekilde gelebilmek i\u00e7in Caller Informations ile fonksiyonumuzu tam olarak sat\u0131r numaras\u0131ndan tutun dosya yoluna kadar, nereden(hangi metoddan) \u00e7a\u011fr\u0131ld\u0131\u011f\u0131 bilsine ula\u015fabiliriz.<\/p>\n<p>\u015eimdi programatik olarak konuyu irdelememize devam edelim.<\/p>\n<p>Caller Info \u00f6z niteli\u011fine eklenmi\u015f 3 farkl\u0131 \u00f6zellik bulunmaktad\u0131r.Bu \u00f6zellikler; &#8220;CallerMemberName&#8221;, &#8220;CallerFilePath&#8221; ve &#8220;CallerLineNumber&#8221; \u00f6zellikleridir.<\/p>\n<p>Bu \u00f6zellikleri a\u00e7\u0131klayal\u0131m.<\/p>\n<p><span style=\"color: #000080;\">CallerMemberName :<\/span> Bu \u00f6zelli\u011fin kullan\u0131ld\u0131\u011f\u0131 metod, hangi metod taraf\u0131ndan \u00e7a\u011fr\u0131l\u0131yorsa, o metodun ismini d\u00f6ner.<br \/>\n<span style=\"color: #000080;\">CallerFilePath :<\/span> Bu \u00f6zelli\u011fin kullan\u0131ld\u0131\u011f\u0131 metod, hangi metod taraf\u0131ndan \u00e7a\u011fr\u0131l\u0131yorsa, o metodun dosya yolunu g\u00f6nderir.<br \/>\n<span style=\"color: #000080;\">CallerLineNumber :<\/span> Bu \u00f6zelli\u011fin kullan\u0131ld\u0131\u011f\u0131 metodun, sat\u0131r numaras\u0131n\u0131 d\u00f6ner.<\/p>\n<p>Bu \u00fc\u00e7 \u00f6zelli\u011fi kullanarak, fonksiyonumuzun parametrelerine Attribute olarak tan\u0131mlamam\u0131z bu bilgilere eri\u015fmemiz i\u00e7in yeterlidir.Bu \u00f6zellikler, &#8220;System.Runtime.CompilerServices&#8221; k\u00fct\u00fcphanesi alt\u0131nda bulunmaktad\u0131r.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            OrnekMetod(&quot;\u00d6rnek \u00e7al\u0131\u015fan metod.&quot;);\r\n        }\r\n        static void OrnekMetod(string GelenDeger, &#x5B;CallerMemberName]string MetodAdi = &quot;&quot;, &#x5B;CallerFilePath]string MetodYolu = &quot;&quot;, &#x5B;CallerLineNumber]int MetodSatirYolu = 0)\r\n        {\r\n            Console.WriteLine(&quot;\u00c7a\u011f\u0131ran Metodun Ad\u0131 : &quot; + MetodAdi);\r\n            Console.WriteLine(&quot;\u00c7a\u011f\u0131ran Metodun Yolu : &quot; + MetodYolu);\r\n            Console.WriteLine(&quot;\u00c7a\u011f\u0131ran Metodun Sat\u0131r Numaras\u0131 : &quot; + MetodSatirYolu);\r\n            Console.WriteLine(&quot;Gelen De\u011ferimiz : &quot; + GelenDeger);\r\n            Console.Read();\r\n        }\r\n<\/pre>\n<p>Yukar\u0131daki kodu derleyip \u00e7al\u0131\u015ft\u0131rd\u0131ktan sonra a\u015fa\u011f\u0131daki gibi \u00e7\u0131kt\u0131 al\u0131yoruz.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/c-5-0-caller-information.html\/caller-information\" rel=\"attachment wp-att-1311\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1311\" alt=\"Caller Information\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/01\/Caller-Information.jpg\" width=\"645\" height=\"82\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/01\/Caller-Information.jpg 645w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/01\/Caller-Information-300x38.jpg 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/01\/Caller-Information-624x79.jpg 624w\" sizes=\"auto, (max-width: 645px) 100vw, 645px\" \/><\/a><\/p>\n<p>G\u00f6rd\u00fc\u011f\u00fcn\u00fcz gibi &#8220;OrnekMetod&#8221; ad\u0131ndaki metodum &#8220;Main&#8221; metodu i\u00e7erisinden \u00e7a\u011fr\u0131l\u0131yor.Caller Info \u00f6znitelikleri bizlere &#8220;Main&#8221; metoduyla ilgili istedi\u011fimiz bilgileri sunuyor.<\/p>\n<p>Son olarak dikkat etmemiz gereken bir husus var.Olu\u015fturdu\u011fumuz metod, basit bir \u015fekilde bir property(\u00f6zellik) ya da bir metod i\u00e7inde kullan\u0131l\u0131yorsa, o metodlar\u0131n isimleri neyse g\u00f6nderecektir.E\u011fer Constructor(Yap\u0131c\u0131 metod) gibi \u00f6zel metodlar i\u00e7erisinde \u00e7a\u011f\u0131r\u0131l\u0131rsa, bu sefer &#8220;CallerMemberName&#8221; \u00f6zellikleri &#8220;.ctor&#8221; ismini geri d\u00f6necektir.<\/p>\n<p>\u00d6rnek olarak, &#8220;Matematik.cs&#8221; ad\u0131nda bir s\u0131n\u0131f olu\u015fturdum ve i\u00e7ini a\u015fa\u011f\u0131daki gibi olu\u015fturuyorum.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    class Matematik\r\n    {\r\n        public Matematik()\r\n        {\r\n            Topla(2, 4);\r\n        }\r\n        static void Topla(int Sayi1, int Sayi2, &#x5B;CallerMemberName]string MetodAdi = &quot;&quot;, &#x5B;CallerFilePath]string MetodYolu = &quot;&quot;, &#x5B;CallerLineNumber]int MetodSatirYolu = 0)\r\n        {\r\n            Console.WriteLine(&quot;\u00c7a\u011f\u0131ran Metodun Ad\u0131 : &quot; + MetodAdi);\r\n            Console.WriteLine(&quot;\u00c7a\u011f\u0131ran Metodun Yolu : &quot; + MetodYolu);\r\n            Console.WriteLine(&quot;\u00c7a\u011f\u0131ran Metodun Sat\u0131r Numaras\u0131 : &quot; + MetodSatirYolu);\r\n            Console.WriteLine(&quot;Toplam : &quot; + (Sayi1 + Sayi2));\r\n            Console.Read();\r\n        }\r\n    }\r\n<\/pre>\n<p>G\u00f6rd\u00fc\u011f\u00fcn\u00fcz gibi, &#8220;Matematik&#8221; s\u0131n\u0131f\u0131n\u0131n Constructor&#8217;\u0131ndan Topla metodumuz \u00e7a\u011fr\u0131lmaktad\u0131r.\u015eimdi &#8220;Program.cs&#8221; s\u0131n\u0131f\u0131nda &#8220;Main&#8221; metodu \u00fczerinde bu s\u0131n\u0131ftan bir nesne olu\u015ftural\u0131m.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        static void Main(string&#x5B;] args)\r\n        {\r\n            Matematik Topla = new Matematik();\r\n        }\r\n<\/pre>\n<p>Matematik s\u0131n\u0131f\u0131ndan bir nesne olu\u015fur olu\u015fmaz yap\u0131c\u0131 metod devreye girecek ve &#8220;Topla&#8221; metodu \u00e7al\u0131\u015ft\u0131r\u0131lacakt\u0131r.<br \/>\n\u00c7\u0131kan sonu\u00e7 a\u015fa\u011f\u0131daki gibi olacakt\u0131r.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/c-5-0-caller-information.html\/ctor\" rel=\"attachment wp-att-1313\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1313\" alt=\"ctor\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/01\/ctor.jpg\" width=\"641\" height=\"73\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/01\/ctor.jpg 641w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/01\/ctor-300x34.jpg 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/01\/ctor-624x71.jpg 624w\" sizes=\"auto, (max-width: 641px) 100vw, 641px\" \/><\/a><\/p>\n<p>G\u00f6rd\u00fc\u011f\u00fcn\u00fcz gibi &#8220;.ctor&#8221; ismi gelmektedir.<\/p>\n<p>Constructor gibi di\u011fer \u00f6zel metodlar\u0131n da, &#8220;CallerMemberName&#8221; Attribute&#8217;unun yakalayaca\u011f\u0131 isimler i\u00e7in a\u015fa\u011f\u0131daki tabloya g\u00f6z atal\u0131m.<\/p>\n<table style=\"width: 100%;\" border=\"1\">\n<tbody>\n<tr>\n<td>\n<h3><strong>\u00c7a\u011f\u0131r\u0131lan yap\u0131<\/strong><\/h3>\n<\/td>\n<td>\n<h3><strong>Gelen isim<\/strong><\/h3>\n<\/td>\n<\/tr>\n<tr>\n<td><strong>\u00a0Metod, \u00f6zellik(property), olay(metod)<\/strong><\/td>\n<td>\u00a0Direkt kullan\u0131lan yap\u0131n\u0131n ismi d\u00f6ner.<\/td>\n<\/tr>\n<tr>\n<td><strong>\u00a0Constructor(Yap\u0131c\u0131 metod)<\/strong><\/td>\n<td>\u00a0&#8220;.ctor&#8221; ismi d\u00f6ner.<\/td>\n<\/tr>\n<tr>\n<td><strong>\u00a0Static Constructor(Static yap\u0131c\u0131 metod)<\/strong><\/td>\n<td>\u00a0&#8220;.cctor&#8221; ismi d\u00f6ner.<\/td>\n<\/tr>\n<tr>\n<td><strong>\u00a0Yok edici metod.<\/strong><\/td>\n<td>\u00a0&#8220;Finalize&#8221; ismi d\u00f6ner.<\/td>\n<\/tr>\n<tr>\n<td><strong>\u00a0Kullan\u0131c\u0131 tan\u0131ml\u0131 operat\u00f6r ya da bir \u00e7evirme i\u015flemi<\/strong><\/td>\n<td>&#8220;op_Addition&#8221;\u00a0ismi d\u00f6ner.<\/td>\n<\/tr>\n<tr>\n<td><strong>\u00a0Attribute\u00a0Constructor(\u00d6znitelik Yap\u0131c\u0131s\u0131)<\/strong><\/td>\n<td>\u00a0\u00d6z niteli\u011fin uyguland\u0131\u011f\u0131 yani kullan\u0131ld\u0131\u011f\u0131 \u00fcyenin ad\u0131 d\u00f6necektir. E\u011fer \u00f6znitelik bir \u00fcyenin i\u00e7indeki bir eleman ise (bir parametre, geri d\u00f6n\u00fc\u015f de\u011feri veya bir generic tip parametresi) yine \u00fcyenin ad\u0131 sonu\u00e7 olarak \u00fcretilecektir.<\/td>\n<\/tr>\n<tr>\n<td><strong>\u00a0Tiplere uygulanm\u0131\u015f bir \u00f6znitelik veya bir assanbly-level taraf\u0131ndan \u00e7a\u011fr\u0131lm\u0131\u015f ise<\/strong><\/td>\n<td>\u00a0Parametrenin varsay\u0131lan de\u011feri d\u00f6nd\u00fcr\u00fclecektir.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>C# 5.0 ile\u00a0Caller Information&#8217;\u0131n programlama hayat\u0131m\u0131za katt\u0131\u011f\u0131 g\u00fczellikleri incelemi\u015f olduk.Bol bol faydalanman\u0131z dile\u011fiyle&#8230;<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar..<\/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>Bu yaz\u0131mda C# 5.0 ile gelen Caller Information \u00f6zelli\u011fine de\u011finece\u011fiz.Caller Information(\u00c7a\u011f\u0131ran \u00d6zellikleri) nedir k\u0131saca \u00f6zetlemek gerekirse, c\u00fcmlenin T\u00fcrk\u00e7e telafuzu bir nevi ip ucu vermektedir.Bir metodun nereden(hangi metod taraf\u0131ndan) \u00e7a\u011fr\u0131ld\u0131\u011f\u0131 bilgisine ula\u015fabilmemizi sa\u011flayan yap\u0131d\u0131r.Bu yap\u0131n\u0131n&#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":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,338],"tags":[27,754,339],"class_list":["post-1308","post","type-post","status-publish","format-standard","hentry","category-c-sharp-c","category-c-5-0","tag-c","tag-c-5-0","tag-caller-information"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/1308","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=1308"}],"version-history":[{"count":0,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/1308\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=1308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=1308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=1308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}