{"id":103564,"date":"2020-03-16T07:00:00","date_gmt":"2020-03-16T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=103564"},"modified":"2023-01-03T08:58:49","modified_gmt":"2023-01-03T16:58:49","slug":"20200316-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20200316-00\/?p=103564","title":{"rendered":"The Windows Runtime IDL compiler lets you abbreviate some interface names"},"content":{"rendered":"<p>If you use an unqualified name in a Windows Runtime IDL file, it is looked up in the current namespace. If you need a name from another namespace, you need to provide its full name.<\/p>\n<pre>namespace Contoso.Widgets\r\n{\r\n  runtimeclass Widget\r\n  {\r\n    <u>Windows.Foundation.Collections.IVectorView<\/u>&lt;String&gt; GetNames();\r\n  }\r\n}\r\n<\/pre>\n<p>There is an exception to this rule: If a parameterized type is given without a namespace, then the Windows Runtime IDL compiler will look in the <code>Windows.<wbr \/>Foundation.<wbr \/>Collections<\/code> namespace before giving up. In practice, this means that you can use the following shorthand:<\/p>\n<table class=\"cp3\" style=\"border-collapse: collapse; font-size: 90%;\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n<tbody>\n<tr>\n<th>Shorthand<\/th>\n<th>Expands to<\/th>\n<\/tr>\n<tr>\n<td><tt>IIterable&lt;T&gt;<\/tt><\/td>\n<td><tt>Windows.Foundation.Collections.IIterable&lt;T&gt;<\/tt><\/td>\n<\/tr>\n<tr>\n<td><tt>IIterator&lt;T&gt;<\/tt><\/td>\n<td><tt>Windows.Foundation.Collections.IIterator&lt;T&gt;<\/tt><\/td>\n<\/tr>\n<tr>\n<td><tt>IKeyValuePair&lt;K, V&gt;<\/tt><\/td>\n<td><tt>Windows.Foundation.Collections.IKeyValuePair&lt;K, V&gt;<\/tt><\/td>\n<\/tr>\n<tr>\n<td><tt>IMap&lt;K, V&gt;<\/tt><\/td>\n<td><tt>Windows.Foundation.Collections.IMap&lt;K, V&gt;<\/tt><\/td>\n<\/tr>\n<tr>\n<td><tt>IMapChangedEventArgs&lt;K&gt;<\/tt><\/td>\n<td><tt>Windows.Foundation.Collections.IMapChangedEventArgs&lt;K&gt;<\/tt><\/td>\n<\/tr>\n<tr>\n<td><tt>IMapView&lt;K, V&gt;<\/tt><\/td>\n<td><tt>Windows.Foundation.Collections.IMapView&lt;K, V&gt;<\/tt><\/td>\n<\/tr>\n<tr>\n<td><tt>IObservableMap&lt;K, V&gt;<\/tt><\/td>\n<td><tt>Windows.Foundation.Collections.IObservableMap&lt;K, V&gt;<\/tt><\/td>\n<\/tr>\n<tr>\n<td><tt>IObservableVector&lt;T&gt;<\/tt><\/td>\n<td><tt>Windows.Foundation.Collections.IObservableVector&lt;T&gt;<\/tt><\/td>\n<\/tr>\n<tr>\n<td><tt>IVector&lt;T&gt;<\/tt><\/td>\n<td><tt>Windows.Foundation.Collections.IVector&lt;T&gt;<\/tt><\/td>\n<\/tr>\n<tr>\n<td><tt>IVectorView&lt;T&gt;<\/tt><\/td>\n<td><tt>Windows.Foundation.Collections.IVectorView&lt;T&gt;<\/tt><\/td>\n<\/tr>\n<tr>\n<td><tt>MapChangedEventHandler&lt;K, V&gt;<\/tt><\/td>\n<td><tt>Windows.Foundation.Collections.MapChangedEventHandler&lt;K, V&gt;<\/tt><\/td>\n<\/tr>\n<tr>\n<td><tt>VectorChangedEventHandler&lt;T&gt;<\/tt><\/td>\n<td><tt>Windows.Foundation.Collections.VectorChangedEventHandler&lt;T&gt;<\/tt><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Resulting in<\/p>\n<pre>namespace Contoso.Widgets\r\n{\r\n  runtimeclass Widget\r\n  {\r\n    <u>IVectorView<\/u>&lt;String&gt; GetNames();\r\n  }\r\n}\r\n<\/pre>\n<p>Unfortunately, this courtesy does not apply to the <code>Windows.<wbr \/>Foundation<\/code> namespace. You still have to write the full name <code>Windows.<wbr \/>Foundation.<wbr \/>IAsyncAction<\/code>, for example.<\/p>\n<p><b>Bonus chatter<\/b>: Why does the shorthand work for <code>Windows.<wbr \/>Foundation.<wbr \/>Collections<\/code> but not <code>Windows.<wbr \/>Foundation<\/code>? Simple: When the compiler was being written, nobody asked for a shorthand for the <code>Windows.<wbr \/>Foundation<\/code> namespace.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>But only a few of them.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-103564","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>But only a few of them.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/103564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=103564"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/103564\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=103564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=103564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=103564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}