{"id":433,"date":"2011-09-27T10:50:00","date_gmt":"2011-09-27T10:50:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vbteam\/2011\/09\/27\/announcement-namespace-global\/"},"modified":"2024-07-05T12:39:18","modified_gmt":"2024-07-05T19:39:18","slug":"announcement-namespace-global","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/vbteam\/announcement-namespace-global\/","title":{"rendered":"Announcement: Namespace Global"},"content":{"rendered":"<p>There&rsquo;s a new feature coming to VB, and already included in the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/vstudio\/hh127353\">Visual Studio 11 Developer Preview<\/a>. The feature is called <b>Namespace Global<\/b> and it&rsquo;ll make your life easier&hellip;<\/p>\n<ul>\n<li>if you part of your code belongs in a different namespace from the rest of your project,<\/li>\n<li>if you use code-generating tools, which need to choose which namespace they write into.<\/li>\n<\/ul>\n<p>The MSDN reference on namespaces (including Namespace Global) is here: <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/zt9tafza(v=VS.110).aspx\">Namespaces in Visual Basic<\/a>.<\/p>\n<p>As an aside, I&rsquo;d like to thank Shimmy Wietzhandler for requesting this feature in <a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/552264\/allow-escaping-to-the-global-namespace-scope-in-vb-net\">Microsoft Connect<\/a>, and also the people who emailed or who wrote in with comments to Lucian Wischik&rsquo;s <a href=\"http:\/\/blogs.msdn.com\/b\/lucian\/archive\/2010\/01\/29\/core10-namespace-global.aspx\">VB language-design blog<\/a>. It&rsquo;s from user feedback like these that we decide which features to prioritize. For the future, we&rsquo;ve launched the <a href=\"http:\/\/visualstudio.uservoice.com\/forums\/121579-visual-studio\">Visual Studio UserVoice<\/a> site to gather together these kinds of feature requests.<\/p>\n<p>Release note: the Visual Studio 11 Developer Preview doesn&rsquo;t yet have full IDE support for the Namespace Global feature (e.g. NavigateTo doesn&rsquo;t work). This in the works.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/09\/3755.image001_thumb_3D1E2854.png\"><img decoding=\"async\" style=\"padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px\" title=\"image001\" border=\"0\" alt=\"image001\" src=\"https:\/\/devblogs.microsoft.com\/vbteam\/wp-content\/uploads\/sites\/7\/2011\/09\/3755.image001_thumb_3D1E2854.png\" width=\"606\" height=\"287\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>Background<\/h2>\n<p>This feature is tied to the project&rsquo;s Root Namespace, pictured above, which you find by double-clicking on &ldquo;My Project&rdquo; in the Solution Explorer. <b><i>Every single class and namespace<\/i><\/b><i> <b>you write <\/b><\/i>is implicitly placed inside that Root Namespace. Here&rsquo;s an example class library I wrote:<span style=\"font-family: Consolas\"><span><span style=\"color: #2b91af;font-size: 9.5pt\"> <br \/><\/span><\/span><\/span><\/p>\n<p><span style=\"font-family: courier new,courier\"><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; <span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">Public<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">Class<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><\/span><span><span style=\"color: #2b91af;font-size: 9.5pt\">InsulinData <br \/>&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span>End<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><\/span><span><span style=\"color: #0000ff;font-size: 9.5pt\">Class <\/p>\n<p>&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">Public<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">Class<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><\/span><span><span style=\"color: #2b91af;font-size: 9.5pt\">PatientID <br \/>&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">End<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><\/span><span><span style=\"color: #0000ff;font-size: 9.5pt\">Class <\/p>\n<p>&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span><span style=\"color: #0000ff;font-size: 9.5pt\">Names<\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">pace<\/span><\/span><\/span><span><span style=\"color: #000000;font-size: 9.5pt\"> Utils <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">Public<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">Class<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><\/span><span><span style=\"color: #2b91af;font-size: 9.5pt\">LinearRegressionSolver <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">End<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><\/span><span><span style=\"color: #0000ff;font-size: 9.5pt\">Class <br \/>&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">End<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><\/span><span><span style=\"color: #0000ff;font-size: 9.5pt\">Namespace<\/span><\/span><\/span><\/span><\/p>\n<p>The fully-qualified names of my classes are like these (note that you never actually need to write the prefix &ldquo;Global&rdquo; &ndash; I put it in here for completeness):<\/p>\n<p style=\"line-height: normal;list-style-type: disc;margin-bottom: 0pt\"><span style=\"font-family: courier new,courier\"><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; Dim<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> x <\/span><\/span><span><span style=\"color: #0000ff\">As<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">New<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">Global<\/span><\/span><span><span style=\"color: #000000\">.MedicalDeviceAnalysis.<\/span><\/span><\/span><span><span style=\"color: #2b91af;font-size: 9.5pt\">InsulinData <br \/><\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; Dim<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> y <\/span><\/span><span><span style=\"color: #0000ff\">As<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">New<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">Global<\/span><\/span><span><span style=\"color: #000000\">.MedicalDeviceAnalysis.<\/span><\/span><\/span><span><span style=\"color: #2b91af;font-size: 9.5pt\">PatientID <br \/><\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; Dim<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> z <\/span><\/span><span><span style=\"color: #0000ff\">As<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">New<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">Global<\/span><\/span><span><span style=\"color: #000000\">.MedicalDeviceAnalysis.Utils.<\/span><\/span><\/span><span><span style=\"color: #2b91af;font-size: 9.5pt\">LinearRegressionSolver<\/span><\/span><\/span><\/span><\/p>\n<p>Most of the time, this is exactly what you want.<\/p>\n<p>&nbsp;<\/p>\n<h3>Problem<\/h3>\n<p>But in this particular case, I didn&rsquo;t want &ldquo;<span style=\"font-family: Consolas\"><span style=\"line-height: 11pt;list-style-type: disc\"><span style=\"color: #000000\"><span style=\"font-size: 9.5pt\">Utils.<\/span><\/span><\/span><span style=\"line-height: 11pt;list-style-type: disc\"><span style=\"color: #2b91af;font-size: 9.5pt\">LinearRegressionSolver<\/span><\/span><\/span>&rdquo; to come under <span style=\"color: #000000\"><span style=\"line-height: 11pt;list-style-type: disc\"><span style=\"font-family: Consolas\"><span style=\"font-size: 9.5pt\">MedicalDeviceAnalysis<\/span><\/span><\/span><span style=\"font-family: Times New Roman\"><span style=\"font-size: 12pt\"> <\/span><\/span><\/span>&ndash; because it&rsquo;s a general-purpose utility, and not specific to medical device analysis at all.<\/p>\n<p>Fixing my code in VS2010 is awkward. I have to set MyProject &gt; RootNamespace to nothing, and then go through my entire project manually putting every single class inside &ldquo;<span style=\"font-family: Consolas\"><span style=\"line-height: 11pt;list-style-type: disc\"><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">Namespace<\/span><\/span><\/span><span style=\"line-height: 11pt;list-style-type: disc\"><span style=\"color: #000000;font-size: 9.5pt\"> MedicalDeviceAnalysis<\/span><\/span><\/span>&rdquo;.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>Namespace Global<\/h2>\n<p>We have introduced a new way to &ldquo;escape&rdquo; your classes out of the project&rsquo;s Root Namespace. It works like this:<\/p>\n<p><span style=\"font-family: courier new,courier\"><span><span><span style=\"color: #000000;font-size: 9.5pt\"><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; Namespace<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff;background-color: #ffff00\">Global<\/span><\/span><\/span><span><span style=\"color: #000000;font-size: 9.5pt\">.Utils<\/span><\/span><\/span> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">Public<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">Class<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><\/span><span><span style=\"color: #2b91af;font-size: 9.5pt\">LinearRegressionSolver <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">End<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><\/span><span><span style=\"color: #0000ff;font-size: 9.5pt\">Class <br \/>&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span style=\"line-height: 11pt\"><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">End<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span style=\"line-height: 11pt\"><span style=\"color: #000000\"> <\/span><\/span><\/span><span style=\"line-height: 11pt\"><span style=\"color: #0000ff;font-size: 9.5pt\">Namespace<\/span><\/span><\/span><\/span><\/p>\n<p>By writing &ldquo;Namespace Global&rdquo; explicitly, I get the classes where I want &ndash; regardless of the project&rsquo;s Root Namespace:<\/p>\n<p><span style=\"font-family: courier new,courier\"><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; Dim<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> x <\/span><\/span><span><span style=\"color: #0000ff\">As<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">New<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">Global<\/span><\/span><span><span style=\"color: #000000\">.MedicalDeviceAnalysis.<\/span><\/span><\/span><span><span style=\"color: #2b91af;font-size: 9.5pt\">InsulinData <br \/><\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; Dim<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> y <\/span><\/span><span><span style=\"color: #0000ff\">As<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">New<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">Global<\/span><\/span><span><span style=\"color: #000000\">.MedicalDeviceAnalysis.<\/span><\/span><\/span><span><span style=\"color: #2b91af;font-size: 9.5pt\">PatientID <br \/><\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; Dim<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> z <\/span><\/span><span><span style=\"color: #0000ff\">As<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">New<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">Global<\/span><\/span><span><span style=\"color: #000000\">.Utils.<\/span><\/span><\/span><span><span style=\"color: #2b91af;font-size: 9.5pt\">LinearRegressionSolver<\/span><\/span><\/span><\/span><\/p>\n<p>&nbsp;<\/p>\n<h2>Namespace Global: extension-method scenario<\/h2>\n<p>Here&rsquo;s another scenario where Namespace Global will help. Let&rsquo;s say that my MedicalDevice library has become quite large, composed of several class libraries and namespaces &ndash; for instance, one of the class libraries will have Root Namespace set to &ldquo;MedicalDevice.Analysis&rdquo;.<\/p>\n<p>But I also established the convention that users merely need to &ldquo;<span style=\"font-family: Consolas\"><span style=\"list-style-type: disc\"><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">Imports<\/span><\/span><\/span><span style=\"list-style-type: disc\"><span style=\"color: #000000;font-size: 9.5pt\"> MedicalDevice<\/span><\/span><\/span>&rdquo; to get all the extension methods. Here&rsquo;s how:<\/p>\n<p style=\"line-height: normal;list-style-type: disc;margin-bottom: 0pt\"><span style=\"font-family: courier new,courier\"><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">Namespace<\/span><\/span><span style=\"font-size: 9.5pt\"><span style=\"color: #000000\"> <\/span><span><span style=\"color: #0000ff;background-color: #ffff00\">Global<\/span><\/span><\/span><span><span style=\"color: #000000;font-size: 9.5pt\">.MedicalDevice <br \/>&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">Public<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">Module<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><\/span><span><span style=\"color: #2b91af;font-size: 9.5pt\">Extensions <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span style=\"color: #000000\"><span style=\"font-size: 9.5pt\">&lt;<\/span><\/span><span style=\"font-size: 9.5pt\"><span style=\"color: #2b91af\">Extension<\/span><span style=\"color: #000000\">&gt; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">Public<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">Function<\/span><\/span><span><span style=\"color: #000000\"> AsPatientID(this <\/span><\/span><span><span style=\"color: #0000ff\">As<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">String<\/span><\/span><span><span style=\"color: #000000\">) <\/span><\/span><span><span style=\"color: #0000ff\">As<\/span><\/span><span><span style=\"color: #000000\"> MedicalDeviceAnalysis.<\/span><\/span><\/span><span><span style=\"color: #2b91af;font-size: 9.5pt\">PatientID <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">Return<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">New<\/span><\/span><span><span style=\"color: #000000\"> MedicalDeviceAnalysis.<\/span><\/span><span><span style=\"color: #2b91af\">PatientID<\/span><\/span><\/span><span><span style=\"color: #000000;font-size: 9.5pt\">(this) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">End<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><\/span><span><span style=\"color: #0000ff;font-size: 9.5pt\">Function <br \/>&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">End<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><\/span><span><span style=\"color: #0000ff;font-size: 9.5pt\">Module <br \/><\/span><\/span><\/span><span><span style=\"line-height: 11pt\"><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">End<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span style=\"line-height: 11pt\"><span style=\"color: #000000\"> <\/span><\/span><\/span><span style=\"line-height: 11pt\"><span style=\"color: #0000ff;font-size: 9.5pt\">Namespace<\/span><\/span><\/span><\/span><\/p>\n<p>We actually used this technique in the recent Async CTP. We wanted our extensions to be defined <i>in the global namespace<\/i> so that people could use them without having to import anything. (This design is generally frowned upon, but it made sense in this case). Again, we used the Namespace Global feature:<\/p>\n<p style=\"line-height: normal;list-style-type: disc;margin-bottom: 0pt\"><span style=\"font-family: courier new,courier\"><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">Namespace<\/span><\/span><span style=\"font-size: 9.5pt\"><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff;font-size: 9.5pt;background-color: #ffff00\">Global <br \/><\/span><\/span><\/span><span><span><span style=\"color: #0000ff;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span><span style=\"color: #0000ff;font-size: 9.5pt;background-color: #ffff00\"><\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">Public<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">Module<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><\/span><span><span style=\"color: #2b91af;font-size: 9.5pt\">AsyncCtpExtensions <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span style=\"color: #000000\"><span style=\"font-size: 9.5pt\">&lt;<\/span><\/span><span style=\"font-size: 9.5pt\"><span style=\"color: #2b91af\">Extension<\/span><span style=\"color: #000000\">&gt; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">Public<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">Function<\/span><\/span><span><span style=\"color: #000000\"> DownloadStringTaskAsync(this <\/span><\/span><span><span style=\"color: #0000ff\">As<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #2b91af\">WebClient<\/span><\/span><span><span style=\"color: #000000\">) <\/span><\/span><span><span style=\"color: #0000ff\">As<\/span><\/span><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #2b91af\">Task<\/span><\/span><span><span style=\"color: #000000\">(<\/span><\/span><span><span style=\"color: #0000ff\">Of String<\/span><\/span><\/span><span><span style=\"color: #000000;font-size: 9.5pt\">) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span style=\"color: #008000;font-size: 9.5pt\">&#8216; &#8230; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">End<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><\/span><span><span style=\"color: #0000ff;font-size: 9.5pt\">Function <br \/>&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">End<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><\/span><span><span style=\"color: #0000ff;font-size: 9.5pt\">Module <br \/><\/span><\/span><\/span><span><span style=\"line-height: 11pt\"><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">End<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span style=\"line-height: 11pt\"><span style=\"color: #000000\"> <\/span><\/span><\/span><span style=\"line-height: 11pt\"><span style=\"color: #0000ff;font-size: 9.5pt\">Namespace<\/span><\/span><\/span><\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>Namespace Global: codegen scenario<\/h2>\n<p>One important behind-the-scenes use of Namespace Global is for code-generation tools. Let&rsquo;s say (for instance) that you wrote a T4 template which automatically spits out code, but it needs the code to go inside a particular namespace. The T4 template can&rsquo;t make any assumptions about Root Namespace.<\/p>\n<p>Now, using Namespace Global, the T4 template can chose precisely which namespace to use for its generated code.<\/p>\n<p>&nbsp;<\/p>\n<h2>Namespace Global: under the hood of VB-Core<\/h2>\n<p>We in the VB team used Namespace Global for a powerful new feature that came in VS2010 SP1 called &ldquo;<a href=\"http:\/\/blogs.msdn.com\/b\/vbteam\/archive\/2011\/01\/10\/vb-core-new-compilation-mode-in-visual-studio-2010-sp1.aspx\">VB-Core<\/a>&rdquo;. The point of VB-Core is to <i>embed<\/i> a small part of Microsoft.VisualBasic.dll inside your own assembly, so you can produce a stand-alone executable that works even on platforms which lack the DLL such as the <a href=\"http:\/\/blogs.msdn.com\/b\/vbteam\/archive\/2011\/06\/08\/micro-framework-v4-2-support-for-visual-basic.aspx\">Micro Framework<\/a>.<\/p>\n<p>The VB compiler actually embeds that small part of Microsoft.VisualBasic as a &ldquo;ghost&rdquo; .vb source file which it implicitly adds to your project. The classes defined in that file <i>must<\/i> go inside the namespace Global.Microsoft.VisualBasic: they cannot be nested inside the project&rsquo;s Root Namespace. I&rsquo;m sure you can guess how the ghost file starts&hellip;<\/p>\n<p style=\"line-height: normal;list-style-type: disc;margin-bottom: 0pt\"><span style=\"font-family: Consolas\"><span><span style=\"color: #a31515\"><span style=\"font-size: 9.5pt\">&#8220;Namespace Global.Microsoft.VisualBasic&#8221;<\/span><\/span><\/span><span><span style=\"color: #000000;font-size: 9.5pt\"> &amp; vbCrLf &amp; <br \/><\/span><\/span><\/span><span style=\"font-family: Consolas\"><span><span style=\"color: #a31515\"><span style=\"font-size: 9.5pt\">&#8221;&nbsp; Namespace CompilerServices&#8221;<\/span><\/span><\/span><span><span style=\"color: #000000;font-size: 9.5pt\"> &amp; vbCrLf &amp; <br \/><\/span><\/span><\/span><span style=\"font-family: Consolas\"><span><span style=\"color: #a31515\"><span style=\"font-size: 9.5pt\">&#8221;&nbsp;&nbsp;&nbsp; Friend Class Operators&#8221;<\/span><\/span><\/span><span><span style=\"color: #000000;font-size: 9.5pt\"> &amp; vbCrLf &amp; <br \/><\/span><\/span><\/span><span style=\"font-family: Consolas\"><span><span style=\"color: #a31515\"><span style=\"font-size: 9.5pt\">&#8221;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Public Shared Function CompareString(Left As String, Right As String, TextCompare As Boolean) As Integer&#8221;<\/span><\/span><\/span><span><span style=\"color: #000000;font-size: 9.5pt\"> &amp; vbCrLf &amp; <br \/><\/span><\/span><\/span><span style=\"font-family: Consolas\"><span><span style=\"color: #a31515\"><span style=\"font-size: 9.5pt\">&#8221;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Left Is Right Then Return 0&#8243;<\/span><\/span><\/span><span><span style=\"color: #000000;font-size: 9.5pt\"> &amp; vbCrLf &amp;<\/span><\/span><\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>Namespace Global: specification<\/h2>\n<p>In addition to the existing VS2010 namespace declarations, VB will allow two new forms of namespace declaration:<\/p>\n<p style=\"line-height: normal;list-style-type: disc;margin-bottom: 0pt\"><span style=\"font-family: Consolas\"><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">Namespace<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><\/span><span><span style=\"color: #0000ff;font-size: 9.5pt\">Global <br \/><\/span><\/span><\/span><span style=\"font-family: Consolas\"><span><span style=\"color: #0000ff\"><span style=\"font-size: 9.5pt\">Namespace<\/span><\/span><\/span><span style=\"font-size: 9.5pt\"><span><span style=\"color: #000000\"> <\/span><\/span><span><span style=\"color: #0000ff\">Global<\/span><\/span><\/span><span><span style=\"color: #000000;font-size: 9.5pt\">.&lt;NamespaceName&gt;<\/span><\/span><\/span><\/p>\n<p>These are both only allowed at top level in a source file (i.e. not nested inside any other Namespace declaration). The first form declares that its contents will go inside the global namespace. The second form declares a namespace within the global namespace, and puts its contents there.<\/p>\n<p>Full details are at MSDN: <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/zt9tafza(v=VS.110).aspx\">Namespaces in Visual Basic<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There&rsquo;s a new feature coming to VB, and already included in the Visual Studio 11 Developer Preview. The feature is called Namespace Global and it&rsquo;ll make your life easier&hellip; if you part of your code belongs in a different namespace from the rest of your project, if you use code-generating tools, which need to choose [&hellip;]<\/p>\n","protected":false},"author":260,"featured_media":8818,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[195],"tags":[99],"class_list":["post-433","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-visual-basic","tag-lucian-wischik"],"acf":[],"blog_post_summary":"<p>There&rsquo;s a new feature coming to VB, and already included in the Visual Studio 11 Developer Preview. The feature is called Namespace Global and it&rsquo;ll make your life easier&hellip; if you part of your code belongs in a different namespace from the rest of your project, if you use code-generating tools, which need to choose [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/users\/260"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/comments?post=433"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/433\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media\/8818"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media?parent=433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/categories?post=433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/tags?post=433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}