July 17th, 2025
heart1 reaction

If the Window Runtime PropertyValue is for boxing non-inspectables, why is there a PropertyValue.CreateInspectable?

The Windows Runtime provides a class named Property­Value which is a helper class for boxing non-inspectables. “Boxing” means taking a value type and wrapping inside an object so it can be used as an object type, and in the Windows Runtime, “objects” are represented by the IInspectable interface.

There are a variety of static methods of the form Property­Value.Create­Something(), like Create­Int32() or Create­Date­Time­Array(). These take values and wrap them inside an object that implements the IPropertyValue interface,¹ and then you can use the Type property to see the type of the value hiding inside, and the corresponding Get­Something() method to retrieve the value.

One of the static methods is Property­Value.Create­Inspectable(). What does this even mean? Does it wrap an IInspectable inside another Property­Value, which is itself an IInspectable?

No. There is no wrapping of IInspectables.

The Create­Inspectable() method merely returns its non-null parameter² unchanged. It doesn’t return a wrapper.

This means that if your original object does not implement IProperty­Value (and there’s no reason to expect it to), then the object that comes out of Property­Value.Create­Inspectable() is not an IProperty­Value. In practice, it means that no IProperty­Values will ever return Property­Type::Inspectable. That enum field is just a mirage.³

So why does Property­Value.Create­Inspectable() even exist?

I’m not sure. Perhaps it was added for completeness.

¹ The object also implements the corresponding IReference<T> interface, where T is the wrapped value.

² If the parameter is null, then it fails with an invalid argument exception.

³ I guess you could use it in your own code to mean that “The thing you have is already an IInspectable, not a PropertyValue wrapper around a value type.”

PropertyType WhatIsThisThing(IInspectable const& thing)
{
    if (auto propertyValue = thing.try_as<IPropertyValue>()) {
        return propertyValue.Type();
    }
    return PropertyType::Inspectable;
}
Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments