B
How do I do __typeof(__box MyValueType) in the new C++/CLI syntax ?
Since the new C++/CLI doesn't use the __box keyword to do the boxing, I am
afraid there seems not existed an one to one translation, my idea is as the
following:
((MyValueType^)MyValueTypeVar)->GetType()
Bern said:But I don't want the System::Type object that represents the type of
MyValueType. I want the System::Type object that represent the boxed
form of MyValueType. So short of using an instance, how do I get it?
But I don't want the System::Type object that represents the type of
MyValueType. I want the System::Type object that represent the boxed
form of MyValueType. So short of using an instance, how do I get it?
Bern said:It is being used it in the overrides of virtual bool Equals(Object
__gc*) in some of our value types:
public: virtual bool Equals(System::Object * obj)
{
if (obj == NULL || __typeof(__box LineStyleID) != obj->GetType())
return false;
public: virtual bool Equals(System::Object * obj)
{
if (obj == NULL || __typeof(__box LineStyleID) != obj->GetType())
return false;
Rory said:They are the same type.
The form is very correct, but perhaps we'd want to test a bit more before
declaring the two instances of the value type equal... (presuming the '=='
operator isn't overloaded):
if (obj == nullptr || LineStyleID::typeid != obj->GetType())
return false;
return this == static_cast<LineStyleID>(obj);
Note that the cast does an implicit unboxing in C++/CLI - no more __unbox
keyword.
Sorry - no problem. Note that this is a confirmation of your post's
correctness, since there has been a bit of noise on this thread, I thought
I'd put in the word for this being correct. I just made additional
observations: that you'd want further checking of actual value equality and
not just a "return true" after the type checking and that you don't need any
__unbox operator since the cast does it (and in general you don't need box
casts in C++/CLI).