{"id":111388,"date":"2025-07-17T07:00:00","date_gmt":"2025-07-17T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=111388"},"modified":"2025-07-17T06:44:44","modified_gmt":"2025-07-17T13:44:44","slug":"20250717-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20250717-00\/?p=111388","title":{"rendered":"If the Window Runtime PropertyValue is for boxing non-inspectables, why is there a PropertyValue.CreateInspectable?"},"content":{"rendered":"<p>The Windows Runtime provides a class named <code>Property\u00adValue<\/code> which is a helper class for boxing non-inspectables. &#8220;Boxing&#8221; means taking a value type and wrapping inside an object so it can be used as an object type, and in the Windows Runtime, &#8220;objects&#8221; are represented by the <code>IInspectable<\/code> interface.<\/p>\n<p>There are a variety of static methods of the form <code>Property\u00adValue.<wbr \/>Create\u00adSomething()<\/code>, like <code>Create\u00adInt32()<\/code> or <code>Create\u00adDate\u00adTime\u00adArray()<\/code>. These take values and wrap them inside an object that implements the <code>IPropertyValue<\/code> interface,\u00b9 and then you can use the <code>Type<\/code> property to see the type of the value hiding inside, and the corresponding <code>Get\u00adSomething()<\/code> method to retrieve the value.<\/p>\n<p>One of the static methods is <code>Property\u00adValue.<wbr \/>Create\u00adInspectable()<\/code>. What does this even mean? Does it wrap an <code>IInspectable<\/code> inside another <code>Property\u00adValue<\/code>, which is itself an <code>IInspectable<\/code>?<\/p>\n<p>No. There is no wrapping of <code>IInspectable<\/code>s.<\/p>\n<p>The <code>Create\u00adInspectable()<\/code> method merely returns its non-null parameter\u00b2 unchanged. It doesn&#8217;t return a wrapper.<\/p>\n<p>This means that if your original object does not implement <code>IProperty\u00adValue<\/code> (and there&#8217;s no reason to expect it to), then the object that comes out of <code>Property\u00adValue.<wbr \/>Create\u00adInspectable()<\/code> is not an <code>IProperty\u00adValue<\/code>. In practice, it means that no <code>IProperty\u00adValue<\/code>s will ever return <code>Property\u00adType::<wbr \/>Inspectable<\/code>. That enum field is just a mirage.\u00b3<\/p>\n<p>So why does <code>Property\u00adValue.<wbr \/>Create\u00adInspectable()<\/code> even exist?<\/p>\n<p>I&#8217;m not sure. Perhaps it was added for completeness.<\/p>\n<p>\u00b9 The object also implements the corresponding <code>IReference&lt;T&gt;<\/code> interface, where <code>T<\/code> is the wrapped value.<\/p>\n<p>\u00b2 If the parameter is null, then it fails with an invalid argument exception.<\/p>\n<p>\u00b3 I guess you could use it in your own code to mean that &#8220;The thing you have is already an <code>IInspectable<\/code>, not a <code>PropertyValue<\/code> wrapper around a value type.&#8221;<\/p>\n<pre>PropertyType WhatIsThisThing(IInspectable const&amp; thing)\r\n{\r\n    if (auto propertyValue = thing.try_as&lt;IPropertyValue&gt;()) {\r\n        return propertyValue.Type();\r\n    }\r\n    return PropertyType::Inspectable;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>For completeness, but not for functionality.<\/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-111388","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>For completeness, but not for functionality.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111388","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=111388"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111388\/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=111388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=111388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=111388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}