Type.IsPrimitiveImpl Method
.NET Framework 4.5
When overridden in a derived class, implements the IsPrimitive property and determines whether the Type is one of the primitive types.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
The following example determines whether the given type is a primitive type and displays the result.
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); } } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.