{"id":1207,"date":"2012-12-01T04:07:11","date_gmt":"2012-12-01T04:07:11","guid":{"rendered":"http:\/\/nestor.nestasoft.fr\/?p=1207"},"modified":"2012-12-18T04:20:24","modified_gmt":"2012-12-18T04:20:24","slug":"utiliser-la-cia-lorsquon-cible-une-version-plus-ancienne-du-framework","status":"publish","type":"post","link":"https:\/\/nestasoft.fr\/?p=1207","title":{"rendered":"Utiliser la \u00ab\u00a0CIA\u00a0\u00bb lorsqu&rsquo;on cible une version plus ancienne du Framework"},"content":{"rendered":"<p>Dans ce billet, nous verrons comment utiliser les attributs d\u2019informations de l\u2019appelant (Caller Info Attributes \u2013 CIA <img decoding=\"async\" src=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/12\/rire.png\" \/>) lorsqu\u2019on cible une version plus ancienne du Framework. <\/p>\n<p>Dans le billet pr\u00e9c\u00e9dent, j\u2019ai parl\u00e9 des attributs d\u2019informations de l\u2019appelant&#160; comme l\u2019une des nouveaut\u00e9s de C# 5 et disponible sous le Framework 4.5. <\/p>\n<p>\u00c0 supposer que l\u2019on souhaite cibler une version du Framework plus ancien (Par exemple 4), les attributs d\u2019informations de l\u2019appelant ne sont disponibles que dans la version 4.5, que faire? Y a t-il une astuce qui permettrait l\u2019utilisation des attributs d\u2019informations de l\u2019appelant si l\u2019on cible une version ancienne du Framework? Et bien, oui!<\/p>\n<p>Si on d\u00e9finit nos propres attributs et qu\u2019on les placent dans l\u2019espace de noms o\u00f9 le compilateur s\u2019attend \u00e0 les trouver, on ferra croire au compilateur que nos attributs sont bien pr\u00e9sents.<\/p>\n<p>&#160;<\/p>\n<p>D\u00e9mo :<\/p>\n<ul>\n<li>Ajoutons un nouveau projet dans la solution \u201cCallerInformation&quot; <\/li>\n<\/ul>\n<p><a href=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/12\/1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin: 0px auto; display: block; padding-right: 0px; border-top-width: 0px\" border=\"0\" src=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/12\/1.png\" width=\"600\" height=\"300\" \/><\/a><\/p>\n<p>&#160;<\/p>\n<p><a href=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/12\/2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin: 0px auto; display: block; padding-right: 0px; border-top-width: 0px\" border=\"0\" src=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/12\/2.png\" width=\"600\" height=\"415\" \/><\/a><\/p>\n<p>&#160;<\/p>\n<ul>\n<li>Affichons les propri\u00e9t\u00e9s de notre projet et modifions la cible du Framework (Dans notre cas la version 4) <\/li>\n<\/ul>\n<p><a href=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/12\/3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin: 0px auto; display: block; padding-right: 0px; border-top-width: 0px\" border=\"0\" src=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/12\/3.png\" width=\"600\" height=\"690\" \/><\/a><\/p>\n<p><a href=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/12\/4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin: 0px auto; display: block; padding-right: 0px; border-top-width: 0px\" border=\"0\" src=\"http:\/\/nestor.nestasoft.fr\/wp-content\/uploads\/2012\/12\/4.png\" width=\"600\" height=\"441\" \/><\/a><\/p>\n<p>&#160;<\/p>\n<ul>\n<li>Ajoutons notre classe d\u2019attributs : <\/li>\n<\/ul>\n<pre class=\"brush:csharp\"> \r\nnamespace System.Runtime.CompilerServices\r\n{\r\n    class CallerInfoAttributes\r\n    {\r\n        \/\/CallerMemberNameAttribute\r\n        [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]\r\n        public sealed class CallerMemberNameAttribute : Attribute\r\n        {\r\n        }\r\n\r\n        \/\/ CallerFilePathAttribute\r\n        [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]\r\n        public sealed class CallerFilePathAttribute : Attribute\r\n        {\r\n        }\r\n\r\n        \/\/ CallerLineNumberAttribute\r\n        [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]\r\n        public sealed class CallerLineNumberAttribute : Attribute\r\n        {\r\n        }\r\n    }\r\n}<\/pre>\n<p>&#160;<\/p>\n<p>Apr\u00e8s compilation et ex\u00e9cution, l\u2019on s\u2019aper\u00e7oit que nos attributs ont \u00e9t\u00e9 pris en compte par le compilateur.<\/p>\n<p>Cette fonctionnalit\u00e9 peut \u00eatre utilis\u00e9e pour cibler les versions 2.0, 3.0, 3.5 et 4 du Framework, bien \u00e9videmment sous Visual Studio 2012. <\/p>\n<p>N.B. : Le compilateur v\u00e9rifie uniquement que les trois types d\u2019attributs existent, peu importe la DLL dans laquelle ils se trouvent.<\/p>\n<p>&#160;<\/p>\n<p>Be connected!<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_1207\" class=\"pvc_stats all  \" data-element-id=\"1207\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/nestasoft.fr\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Dans ce billet, nous verrons comment utiliser les attributs d\u2019informations de l\u2019appelant (Caller Info Attributes \u2013 CIA ) lorsqu\u2019on cible une version plus ancienne du Framework. Dans le billet pr\u00e9c\u00e9dent, j\u2019ai parl\u00e9 des attributs d\u2019informations de l\u2019appelant&#160; comme l\u2019une des nouveaut\u00e9s de C# 5 et disponible sous le Framework 4.5. \u00c0 supposer que l\u2019on souhaite [&hellip;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_1207\" class=\"pvc_stats all  \" data-element-id=\"1207\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/nestasoft.fr\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":1212,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-1207","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/posts\/1207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1207"}],"version-history":[{"count":10,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/posts\/1207\/revisions"}],"predecessor-version":[{"id":1238,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/posts\/1207\/revisions\/1238"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=\/wp\/v2\/media\/1212"}],"wp:attachment":[{"href":"https:\/\/nestasoft.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nestasoft.fr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}