{"id":425,"date":"2011-04-22T09:00:00","date_gmt":"2011-04-22T15:00:00","guid":{"rendered":"http:\/\/jameskovacs.com\/2011\/04\/22\/resharper-import-symbol-completion-xml-files-and-you\/"},"modified":"2011-04-22T09:00:00","modified_gmt":"2011-04-22T15:00:00","slug":"resharper-import-symbol-completion-xml-files-and-you","status":"publish","type":"post","link":"https:\/\/www.jameskovacs.com\/index.php\/2011\/04\/22\/resharper-import-symbol-completion-xml-files-and-you\/","title":{"rendered":"ReSharper, Import Symbol Completion, XML files, and You"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"image\" border=\"0\" alt=\"image\" align=\"right\" src=\"https:\/\/www.jameskovacs.com\/wp-content\/uploads\/2011\/04\/image14.png\" width=\"204\" height=\"204\" \/>System.Type and XML are the nuts and gum of the development world. You can stuff a System.Type into an XML file, but it leaves a bad taste in your mouth. Sometimes you don\u2019t have much choice. For example:<\/p>\n<ul>\n<li>Custom configuration sections in App.config\/Web.config <\/li>\n<li>Handlers and modules in Web.config <\/li>\n<li>ProxyFactoryFactory, 2nd-level cache provider, database dialect, and other pieces of configuration in hibernate.cfg.xml* <\/li>\n<li>XML-based IoC configuration** <\/li>\n<\/ul>\n<p>* <a href=\"http:\/\/jameskovacs.com\/2011\/01\/21\/loquacious-configuration-in-nhibernate-3\/\">NHibernate Loquacious configuration<\/a> is now a better option for configuring NHibernate IMHO and I use it in all my new apps rather than hibernate.cfg.xml.<\/p>\n<p>** For IoC containers, convention-over-configuration is a better choice followed by code-based configuration. I use XML-based configuration only as a last resort, but it can sometimes be useful for configurable overrides.<\/p>\n<p>When you do need to encode a System.Type into a XML file, <a href=\"http:\/\/jetbrains.com\/resharper\">JetBrains ReSharper<\/a> makes your life a lot easier. (This is a little-known feature of ReSharper shown to me by <a href=\"http:\/\/twitter.com\/orangy\">Ilya \u201cOrangy\u201d Ryzhenkov<\/a>, ReSharper Product Manager.) I decided to create a completely silly, contrived example where we need to display a list of hot peppers and their <a href=\"http:\/\/en.wikipedia.org\/wiki\/Scoville_scale\">Scoville heat units<\/a> and the information is stored in App.config. (Yes, I know. A database or flat file would be a better place. I told you that it was a contrived example.) I have created a PeppersConfigurationSection class that is defines the &lt;peppers&gt; configuration section. I need to specify the type name in the &lt;configurationSections&gt; where it says &lt;INSERT_TYPE_NAME_HERE&gt;<\/p>\n<pre class=\"brush: xml; highlight: [4];\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;\n&lt;configuration&gt;\n  &lt;configSections&gt;\n    &lt;section name=&quot;peppers&quot; type=&quot;&lt;INSERT_TYPE_NAME_HERE&gt;&quot; \/&gt;\n  &lt;\/configSections&gt;\n  &lt;peppers&gt;\n    &lt;pepper name=&quot;Crazy Jerry's Brain Damage&quot; scovilles=&quot;11000&quot; type=&quot;sauce&quot;\/&gt;\n    &lt;!-- more peppers --&gt;\n  &lt;\/peppers&gt;\n&lt;\/configuration&gt;<\/pre>\n<p>Rather than typing out the namespace-qualified type name, I simply type PCS for PeppersConfigurationSection and press ReSharper\u2019s <strong>Import Symbol Completion (IDEA: CTRL-ALT-Space; VS: ALT-SHIFT-Space)<\/strong>.<\/p>\n<p><a href=\"https:\/\/www.jameskovacs.com\/wp-content\/uploads\/2011\/04\/ImportTypeCompletion.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px\" title=\"Import Type Completion\" border=\"0\" alt=\"Import Type Completion\" src=\"https:\/\/www.jameskovacs.com\/wp-content\/uploads\/2011\/04\/ImportTypeCompletion_thumb.png\" width=\"918\" height=\"171\" \/><\/a><\/p>\n<p>You can see the normal ReSharper completion pop-up appear. Selecting the first one, I get:<\/p>\n<p><a href=\"https:\/\/www.jameskovacs.com\/wp-content\/uploads\/2011\/04\/ImportTypeCompletion2.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px\" title=\"Type Completed\" border=\"0\" alt=\"Type Completed\" src=\"https:\/\/www.jameskovacs.com\/wp-content\/uploads\/2011\/04\/ImportTypeCompletion2_thumb.png\" width=\"918\" height=\"171\" \/><\/a><\/p>\n<p>This is fine and dandy if the custom configuration section is defined in your project, but what if you need to specify the assembly name too? ReSharper once again comes to our rescue with a <strong>Quick Fix (ALT-Enter)<\/strong>.<\/p>\n<p><a href=\"https:\/\/www.jameskovacs.com\/wp-content\/uploads\/2011\/04\/ImportTypeCompletion3.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px\" title=\"Add module qualification\" border=\"0\" alt=\"Add module qualification\" src=\"https:\/\/www.jameskovacs.com\/wp-content\/uploads\/2011\/04\/ImportTypeCompletion3_thumb.png\" width=\"918\" height=\"171\" \/><\/a><\/p>\n<p>Selecting the <strong>Add module qualitication<\/strong> Quick Fix and we end up with this. (I added linebreaks between the parts of the fully qualified type name for ease of readability in the screenshot.)<\/p>\n<p><a href=\"https:\/\/www.jameskovacs.com\/wp-content\/uploads\/2011\/04\/ImportTypeCompletion4.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px\" title=\"ImportTypeCompletion4\" border=\"0\" alt=\"ImportTypeCompletion4\" src=\"https:\/\/www.jameskovacs.com\/wp-content\/uploads\/2011\/04\/ImportTypeCompletion4_thumb.png\" width=\"918\" height=\"171\" \/><\/a><\/p>\n<p><strong>Add module qualification<\/strong> is even handier if the assembly has a public key token as those are a hassle to look up. Once again, ReSharper does the hard work of inserting the type name \u2013 I only typed NVSH CTRL-ALT-Space \u2013 and then the quick fix to get the qualification with assembly name, version, culture, and public key token:<\/p>\n<p><a href=\"https:\/\/www.jameskovacs.com\/wp-content\/uploads\/2011\/04\/ImportTypeCompletion5.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px\" title=\"ImportTypeCompletion5\" border=\"0\" alt=\"ImportTypeCompletion5\" src=\"https:\/\/www.jameskovacs.com\/wp-content\/uploads\/2011\/04\/ImportTypeCompletion5_thumb.png\" width=\"918\" height=\"171\" \/><\/a><\/p>\n<p>I hope this little ReSharper gem makes your coding lives just a little bit easier\u2026<\/p>\n<p>N.B. ReSharper 5.1 and 6.0 EAP (up to at least build 2136) has a <a href=\"http:\/\/youtrack.jetbrains.net\/issue\/RSRP-256900\">bug<\/a> that causes Import Symbol Completion to fail for files named Web.config in a ASP.NET project. If you rename Web.config to Foo.config \u2013 no other changes necessary \u2013 you can use Import Symbol Completion. Just remember to rename the file back to Web.config when you\u2019re done. Another option is to copy Web.config to another project type (Console and Class Library both work), make your changes, and then copy back. I have reported the issue to JetBrains <a href=\"http:\/\/youtrack.jetbrains.net\/issue\/RSRP-256900\">here<\/a> and the team is working on a fix.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>System.Type and XML are the nuts and gum of the development world. You can stuff a System.Type into an XML file, but it leaves a bad taste in your mouth. Sometimes you don\u2019t have much choice. For example: Custom configuration sections in App.config\/Web.config Handlers and modules in Web.config ProxyFactoryFactory, 2nd-level cache provider, database dialect, and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3],"tags":[],"class_list":["post-425","post","type-post","status-publish","format-standard","hentry","category-dotnetgeneral","category-dotnettools"],"_links":{"self":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/posts\/425","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/comments?post=425"}],"version-history":[{"count":0,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/posts\/425\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/media?parent=425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/categories?post=425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/tags?post=425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}