Type.IsPrimitiveImpl メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
派生クラスによってオーバーライドされるときに、IsPrimitive プロパティを実装し、Type がプリミティブ型の 1 つかどうかを判断します。
protected:
abstract bool IsPrimitiveImpl();
protected abstract bool IsPrimitiveImpl ();
abstract member IsPrimitiveImpl : unit -> bool
Protected MustOverride Function IsPrimitiveImpl () As Boolean
戻り値
true
がプリミティブ型の 1 つである場合は Type。それ以外の場合は false
。
例
次の例では、指定された型がプリミティブ型であるかどうかを判断し、結果を表示します。
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 );
}
}
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);
}
}
}
open System.Reflection
type MyTypeDelegatorClass(myType) =
inherit TypeDelegator(myType)
[<DefaultValue>]
val mutable public myElementType : string
// Override the IsPrimitiveImpl.
override this.IsPrimitiveImpl() =
// Determine whether the type is a primitive type.
if myType.IsPrimitive then
this.myElementType <- "primitive"
true
else
false
try
printfn "Determine whether int is a primitive type."
let myType = MyTypeDelegatorClass typeof<int>
// Determine whether int is a primitive type.
if myType.IsPrimitive then
printfn $"{typeof<int>} is a primitive type."
else
printfn $"{typeof<int>} is not a primitive type."
printfn "\nDetermine whether string is a primitive type."
let myType = MyTypeDelegatorClass typeof<string>
// Determine if string is a primitive type.
if myType.IsPrimitive then
printfn $"{typeof<string>} is a primitive type."
else
printfn $"{typeof<string>} is not a primitive type."
with e ->
printfn $"Exception: {e.Message}"
Imports System.Reflection
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
' 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
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
End Class
注釈
プリミティブ型は、Boolean、Byte、、SByte、、Int16、、UInt16、Int32、CharUInt64DoubleUInt32Int64および Singleです。
適用対象
こちらもご覧ください
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET