Windows Store Apps and System.Type - Equivalent to ==?

As per the accepted answer to this StackOverflow question, there is a difference between a method System.Type.Equals

and System.Type operator ==

:

a runtime type (represented by the internal type RuntimeType), managed by 
the CLR is not always the same as a Type, which can be extended. Equals 
will check the underlying system type, whereas == will check the type itself.

      

In .NET for Windows Store Apps, the System.Type == operator is not available.

How can I fully replicate the functionality System.Type operator ==

in the Windows Store app? Or, is the specific function of the equality operator for being System.Type

irrelevant in Windows Store apps?

+3


source to share


1 answer


So the basic principle is that Equals

is a virtual instance method of each type, that is, it will use a vtable to determine the implementation to use at runtime based on the type of the actual object that is named Equals

(without regard to the type of the variable).

operator ==

can be thought of as a static method (with a lot of overloads). It is not virtual, so the mentioned implementation will be based on the compile-time type of the variable containing the object and will not be based on what the actual type of the object is at runtime.



This behavior can be replicated by simply creating your own methods static

Equals

(on whatever type or types you prefer) that behave based on the types of the two arguments. This is a little less convenient to type than to use operator ==

, but it does the same thing as it does after compilation.

+5


source







All Articles