Type.IsValueTypeImpl 메서드

IsValueType 속성을 구현하고 Type이 값 형식인지 여부, 즉 클래스 또는 인터페이스가 아닌지 여부를 확인합니다.

네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Protected Overridable Function IsValueTypeImpl As Boolean
‘사용 방법
Dim returnValue As Boolean

returnValue = Me.IsValueTypeImpl
protected virtual bool IsValueTypeImpl ()
protected:
virtual bool IsValueTypeImpl ()
protected boolean IsValueTypeImpl ()
protected function IsValueTypeImpl () : boolean

반환 값

Type이 값 형식이면 true이고, 그렇지 않으면 false입니다.

설명

값 형식은 비트 시퀀스로 표시되는 값을 설명하며, 클래스 또는 인터페이스가 아닙니다. 일부 프로그래밍 언어에서는 값 형식을 "구조체"라고 합니다. 열거형은 값 형식입니다.

예제

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

Public Class MyTypeDelegator
   Inherits TypeDelegator
   Public myElementType As String = Nothing
   Private myType As Type = Nothing
   
   Public Sub New(myType As Type)
      MyBase.New(myType)
      Me.myType = myType
   End Sub 'New
   
   ' Override the IsValueTypeImpl() method of the Type class.
   Protected Overrides Function IsValueTypeImpl() As Boolean
      ' Determine whether the type is a value type.
      If myType.IsValueType Then
         myElementType = "value"
         Return True
      End If
      ' The type is not a value type.
      Return False
   End Function 'IsValueTypeImpl
End Class 'MyTypeDelegator

Public Class Type_IsValueTypeImpl

   Public Class MyClass1
   End Class 'MyClass1
   
   Public Shared Sub Main()
      Try
         Dim myInt As Integer = 0
         Dim myClass1 As New MyClass1()
         
         Dim myType As New MyTypeDelegator(myInt.GetType())
         Console.WriteLine(ControlChars.NewLine + "Determine whether a variable refers to a value type." + ControlChars.NewLine)
         
         ' Determine whether 'myType' is a value type.  
         If myType.IsValueType Then
            Console.WriteLine(ControlChars.NewLine + "'myInt' is a {0} type.", myType.myElementType)
         Else
            Console.WriteLine(ControlChars.NewLine + "'myInt' is not a value type.")
         End If 
         myType = New MyTypeDelegator(myClass1.GetType())
         
         ' Determine whether 'myType' is a value type.  
         If myType.IsValueType Then
            Console.WriteLine(ControlChars.NewLine + "'myClass1' is a {0} type.", myType.myElementType)
         Else
            Console.WriteLine(ControlChars.NewLine + "'myClass1' is not a value type.")
         End If 
      Catch e As Exception
         Console.WriteLine(ControlChars.NewLine + "The following exception is raised:" + e.Message.ToString())
      End Try
   End Sub 'Main
End Class 'Type_IsValueTypeImpl
using System;
using System.Reflection;

public class MyTypeDelegator : TypeDelegator
{
   public string myElementType = null;
   private Type myType = null ; 

   public MyTypeDelegator(Type myType) : base(myType)
   {
      this.myType = myType;
   }

   // Override 'IsValueTypeImpl()' method of 'Type' class.
   protected override bool IsValueTypeImpl()
   {
      // Determine whether the type is a value type.
      if(myType.IsValueType)
      {
         myElementType = "value";
         return true;
      }
      // The type is not value type.
      return false;
   }  
}
public class Type_IsValueTypeImpl 
{
   public class MyClass
   {
   }
   public static void Main()
   {
      try
      {
         int myInt = 0 ; 
         MyClass myClass = new MyClass ();

         MyTypeDelegator myType = new 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 = new 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:" +e.Message);
      }
   }
}
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 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

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

Type 클래스
Type 멤버
System 네임스페이스
TypeAttributes
IsClass
IsInterface
ValueType
IsValueType