Type.IsPrimitiveImpl 메서드
파생 클래스에서 재정의된 경우, IsPrimitive 속성을 구현하고 Type이 기본 형식 중 하나인지 여부를 확인합니다.
네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
Protected MustOverride Function IsPrimitiveImpl As Boolean
‘사용 방법
Dim returnValue As Boolean
returnValue = Me.IsPrimitiveImpl
protected abstract bool IsPrimitiveImpl ()
protected:
virtual bool IsPrimitiveImpl () abstract
protected abstract boolean IsPrimitiveImpl ()
protected abstract function IsPrimitiveImpl () : boolean
반환 값
Type이 기본 형식 중 하나이면 true이고, 그렇지 않으면 false입니다.
설명
기본 형식으로는 Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Char, Double 및 Single이 있습니다.
예제
다음 예제에서는 주어진 형식이 기본 형식인지 여부를 확인하여 결과를 표시합니다.
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Public Class MyTypeDelegatorClass
Inherits TypeDelegator
Public myElementType As String = Nothing
Private myType As Type = Nothing
Public Sub New(ByVal myType As Type)
MyBase.New(myType)
Me.myType = myType
End Sub 'New
' Override the IsPrimitiveImpl method.
Protected Overrides Function IsPrimitiveImpl() As Boolean
' Determine whether the type is a primitive type.
If myType.IsPrimitive Then
myElementType = "primitive"
Return True
End If
Return False
End Function 'IsPrimitiveImpl
End Class 'MyTypeDelegatorClass
Public Class MyTypeDemoClass
Public Shared Sub Main()
Try
Console.WriteLine("Determine whether int is a primitive type.")
Dim myType As MyTypeDelegatorClass
myType = New MyTypeDelegatorClass(GetType(Integer))
' Determine whether int is a primitive type.
If myType.IsPrimitive Then
Console.WriteLine(GetType(Integer).ToString() + " is a primitive type.")
Else
Console.WriteLine(GetType(Integer).ToString() + " is not a primitive type.")
End If
Console.WriteLine(ControlChars.NewLine + "Determine whether string is a primitive type.")
myType = New MyTypeDelegatorClass(GetType(String))
' Determine whether string is a primitive type.
If myType.IsPrimitive Then
Console.WriteLine(GetType(String).ToString() + " is a primitive type.")
Else
Console.WriteLine(GetType(String).ToString() + " is not a primitive type.")
End If
Catch e As Exception
Console.WriteLine("Exception: {0}", e.Message.ToString())
End Try
End Sub 'Main
End Class 'MyTypeDemoClass
using System;
using System.Reflection;
public class MyTypeDelegatorClass : TypeDelegator
{
public string myElementType = null;
private Type myType = null ;
public MyTypeDelegatorClass(Type myType) : base(myType)
{
this.myType = myType;
}
// Override the IsPrimitiveImpl.
protected override bool IsPrimitiveImpl()
{
// Determine whether the type is a primitive type.
if(myType.IsPrimitive)
{
myElementType = "primitive";
return true;
}
return false;
}
}
public class MyTypeDemoClass
{
public static void Main()
{
try
{
Console.WriteLine ("Determine whether int is a primitive type.");
MyTypeDelegatorClass myType;
myType = new MyTypeDelegatorClass(typeof(int));
// Determine whether int is a primitive type.
if( myType.IsPrimitive)
{
Console.WriteLine(typeof(int) + " is a primitive type.");
}
else
{
Console.WriteLine(typeof(int) + " is not a primitive type.");
}
Console.WriteLine ("\nDetermine whether string is a primitive type.");
myType = new MyTypeDelegatorClass(typeof(string));
// Determine if string is a primitive type.
if( myType.IsPrimitive)
{
Console.WriteLine(typeof(string) + " is a primitive type.");
}
else
{
Console.WriteLine(typeof(string) + " is not a primitive type.");
}
}
catch( Exception e )
{
Console.WriteLine("Exception: {0}", e.Message);
}
}
}
using namespace System;
using namespace System::Reflection;
public ref class MyTypeDelegatorClass: public TypeDelegator
{
public:
String^ myElementType;
private:
Type^ myType;
public:
MyTypeDelegatorClass( Type^ myType )
: TypeDelegator( myType )
{
this->myType = myType;
}
protected:
// Override the IsPrimitiveImpl.
virtual bool IsPrimitiveImpl() override
{
// Determine whether the type is a primitive type.
if ( myType->IsPrimitive )
{
myElementType = "primitive";
return true;
}
return false;
}
};
int main()
{
try
{
Console::WriteLine( "Determine whether int is a primitive type." );
MyTypeDelegatorClass^ myType;
myType = gcnew MyTypeDelegatorClass( int::typeid );
// Determine whether int is a primitive type.
if ( myType->IsPrimitive )
{
Console::WriteLine( "{0} is a primitive type.", int::typeid );
}
else
{
Console::WriteLine( "{0} is not a primitive type.", int::typeid );
}
Console::WriteLine( "\nDetermine whether String is a primitive type." );
myType = gcnew MyTypeDelegatorClass( String::typeid );
// Determine if String is a primitive type.
if ( myType->IsPrimitive )
{
Console::WriteLine( "{0} is a primitive type.", String::typeid );
}
else
{
Console::WriteLine( "{0} is not a primitive type.", String::typeid );
}
}
catch ( Exception^ e )
{
Console::WriteLine( "Exception: {0}", e->Message );
}
}
import System.*;
import System.Reflection.*;
public class MyTypeDelegatorClass extends TypeDelegator
{
public String myElementType = null;
private Type myType = null;
public MyTypeDelegatorClass(Type myType)
{
super(myType);
this.myType = myType;
} //MyTypeDelegatorClass
// Override the IsPrimitiveImpl.
protected boolean IsPrimitiveImpl()
{
// Determine whether the type is a primitive type.
if (myType.get_IsPrimitive()) {
myElementType = "primitive";
return true;
}
return false;
} //IsPrimitiveImpl
} //MyTypeDelegatorClass
public class MyTypeDemoClass
{
public static void main(String[] args)
{
try {
Console.WriteLine("Determine whether int is a primitive type.");
MyTypeDelegatorClass myType;
myType = new MyTypeDelegatorClass(int.class.ToType());
// Determine whether int is a primitive type.
if (myType.get_IsPrimitive()) {
Console.WriteLine(int.class.ToType() + " is a primitive type.");
}
else {
Console.WriteLine(int.class.ToType()
+ " is not a primitive type.");
}
Console.WriteLine("\nDetermine whether string is a primitive type.");
myType = new MyTypeDelegatorClass(String.class.ToType());
// Determine if string is a primitive type.
if (myType.get_IsPrimitive()) {
Console.WriteLine(String.class.ToType()
+ " is a primitive type.");
}
else {
Console.WriteLine(String.class.ToType()
+ " is not a primitive type.");
}
}
catch (System.Exception e) {
Console.WriteLine("Exception: {0}", e.get_Message());
}
} //main
} //MyTypeDemoClass
플랫폼
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 네임스페이스
Boolean 구조체
Byte 구조체
SByte 구조체
Int16 구조체
UInt16
Int32 구조체
UInt32
Int64 구조체
UInt64
Char 구조체
Double 구조체
Single 구조체
IsPrimitive