Type.IsPrimitiveImpl メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Type.IsPrimitiveImpl メソッドの意味・解説 

Type.IsPrimitiveImpl メソッド

派生クラスによってオーバーライドされるときに、IsPrimitive プロパティ実装し、Typeプリミティブ型1 つかどうか判断します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

プリミティブ型には、BooleanByte、SByte、Int16、UInt16、Int32、UInt32、Int64、UInt64、CharDouble、および 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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

Type.IsPrimitiveImpl メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Type.IsPrimitiveImpl メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS