|
Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
|
Tradução
Original
|
Type.IsPrimitiveImpl Método
.NET Framework 2.0
Assembly: mscorlib (em mscorlib. dll)
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); } } }
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