Share via


__typeof 

Note   This topic applies only to version 1 of Managed Extensions for C++. This syntax should only be used to maintain version 1 code. See typeid for information on using the equivalent functionality in the new syntax.

Returns the System::Type of a specified type.

__typeof(typename)

where:

  • typename
    The name of a managed type for which you want the System::Type name. Note that in a managed program, some native types are aliased to types in the common language runtime. For example, int is an alias for System::Int32.

Remarks

The __typeof operator lets you get the System::Type type of a type that you specify. __typeof can also be used to return a value of System::Type in a custom attribute block. See attribute for more information about creating your own attributes.

Example

In the following example, a custom attribute (AtClass) is applied to a __gc class (B). The value of the custom attribute is then retrieved with __typeof:

// keyword__typeof.cpp
// compile with: /clr:oldSyntax
#using <mscorlib.dll>
using namespace System;

public __gc class MyClass {};

[attribute(All)]
__gc class AtClass {
public:
   AtClass(Type*) {
      Console::WriteLine("in Type * constructor");
   }

   AtClass(String*) {}
   AtClass(int) {}
};

[AtClass(__typeof(MyClass))]   // Apply AtClass attribute to class B
__gc class B {};

int main() {
   Type * mytype = __typeof(B);
   Object * myobject __gc[] = mytype -> GetCustomAttributes(true);
   Console::WriteLine(myobject[0]);
}

Output

in Type * constructor
AtClass