Type.IsValueTypeImpl Method
.NET Framework 3.0
Implements the IsValueType property and determines whether the Type is a value type; that is, not a class or an interface.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly: mscorlib (in mscorlib.dll)
The following code example demonstrates how to use the IsValueTypeImpl method to change the behavior of the IsValueType property in a derived class.
using namespace System; using namespace System::Reflection; public ref class MyTypeDelegator: public TypeDelegator { public: String^ myElementType; private: Type^ myType; public: MyTypeDelegator( Type^ myType ) : TypeDelegator( myType ) { this->myType = myType; } protected: // Override 'IsValueTypeImpl()' method of 'Type' class. virtual bool IsValueTypeImpl() override { // Determine whether the type is a value type. if ( myType->IsValueType ) { myElementType = "value"; return true; } // The type is not value type. return false; } }; public ref class MyClass{}; int main() { try { int myInt = 0; MyClass^ myClass = gcnew MyClass; MyTypeDelegator^ myType = gcnew MyTypeDelegator( myInt.GetType() ); Console::WriteLine( "\nCheck whether a variable refers to a value type.\n" ); // Determine whether 'myType' is a value type. if ( myType->IsValueType ) Console::WriteLine( "\n'myInt' is a {0} type.", myType->myElementType ); else Console::WriteLine( "\n'myInt' is not a value type." ); myType = gcnew MyTypeDelegator( myClass->GetType() ); // Determine whether 'myType' is a value type. if ( myType->IsValueType ) Console::WriteLine( "\n'myClass' is a {0} type.", myType->myElementType ); else Console::WriteLine( "\n'myClass' is not a value type." ); } catch ( Exception^ e ) { Console::WriteLine( "\nThe following exception is raised: {0}", e->Message ); } }
import System.*;
import System.Reflection.*;
public class MyTypeDelegator extends TypeDelegator
{
public String myElementType = null;
private Type myType = null;
public MyTypeDelegator(Type myType)
{
super(myType);
this.myType = myType;
} //MyTypeDelegator
// Override 'IsValueTypeImpl()' method of 'Type' class.
protected boolean IsValueTypeImpl()
{
// Determine whether the type is a value type.
if (myType.get_IsValueType()) {
myElementType = "value";
return true;
}
// The type is not value type.
return false;
} //IsValueTypeImpl
} //MyTypeDelegator
public class Type_IsValueTypeImpl
{
static public class MyClass
{
} //MyClass
public static void main(String[] args)
{
try {
int myInt = 0;
MyClass myClass = new MyClass();
MyTypeDelegator myType = new MyTypeDelegator(((System.
Int32)myInt).GetType());
Console.WriteLine("\nCheck whether a variable refers to"
+ " a value type.\n");
// Determine whether 'myType' is a value type.
if (myType.get_IsValueType()) {
Console.WriteLine("\n'myInt' is a {0} type.",
myType.myElementType);
}
else {
Console.WriteLine("\n'myInt' is not a value type.");
}
myType = new MyTypeDelegator(myClass.GetType());
// Determine whether 'myType' is a value type.
if (myType.get_IsValueType()) {
Console.WriteLine("\n'myClass' is a {0} type.",
myType.myElementType);
}
else {
Console.WriteLine("\n'myClass' is not a value type.");
}
}
catch (System.Exception e)
{
Console.WriteLine("\nThe following exception is raised:"
+ e.get_Message());
}
} //main
} //Type_IsValueTypeImpl
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Community Additions
ADD
Show: