Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Type.IsPrimitiveImpl Method

When overridden in a derived class, implements the IsPrimitive property and determines whether the Type is one of the primitive types.

[Visual Basic]
Protected MustOverride Function IsPrimitiveImpl() As Boolean
[C#]
protected abstract bool IsPrimitiveImpl();
[C++]
protected: virtual bool IsPrimitiveImpl() = 0;
[JScript]
protected abstract function IsPrimitiveImpl() : Boolean;

Return Value

true if the Type is one of the primitive types; otherwise, false.

Remarks

The primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Char, Double, and Single.

Example

[Visual Basic, C#, C++] The following example determines whether the given type is a primitive type and displays the result.

[Visual Basic] 
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

[C#] 
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);
        }
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;

public __gc class MyTypeDelegatorClass : public TypeDelegator {
public:
   String* myElementType;
private:
   Type* myType;
public:
   MyTypeDelegatorClass(Type* myType) : TypeDelegator(myType) {
      this->myType = myType;
   }
   // Override the IsPrimitiveImpl.
protected:
   bool IsPrimitiveImpl() {
      // Determine whether the type is a primitive type.
      if (myType->IsPrimitive) {
         myElementType = S"primitive";
         return true;
      }
      return false;
   }
};

int main() {
   try {
      Console::WriteLine (S"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(S"{0} is a primitive type.", __typeof(int));
      } else {
         Console::WriteLine(S"{0} is not a primitive type.", __typeof(int));
      }
      Console::WriteLine (S"\nDetermine whether String is a primitive type.");
      myType = new MyTypeDelegatorClass(__typeof(String));
      // Determine if String is a primitive type.
      if (myType->IsPrimitive) {
         Console::WriteLine(S"{0} is a primitive type.", __typeof(String));
      } else {
         Console::WriteLine(S"{0} is not a primitive type.", __typeof(String));
      }
   } catch (Exception* e) {
      Console::WriteLine(S"Exception: {0}", e->Message);
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Type Class | Type Members | System Namespace | Boolean | Byte | SByte | Int16 | UInt16 | Int32 | UInt32 | Int64 | UInt64 | Char | Double | Single | IsPrimitive

Show:
© 2014 Microsoft