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.
, 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.
. 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 IInspectable
s.
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.
is not an IPropertyÂValue
. In practice, it means that no IPropertyÂValue
s will ever return PropertyÂType::
. That enum field is just a mirage.³
So why does PropertyÂValue.
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; }
0 comments
Be the first to start the discussion.