Expandir Minimizar
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
Este tópico ainda não foi avaliado como - Avalie este tópico

Type.IsPrimitiveImpl Método

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 (em mscorlib. dll)
protected abstract bool IsPrimitiveImpl()

Valor de retorno

Tipo: System.Boolean
true if the Type is one of the primitive types; otherwise, false.

O exemplo a seguir determina se o tipo fornecido é um tipo primitivo e exibe o resultado.

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


Isso foi útil para você?
(1500 caracteres restantes)

Contribuições da comunidade

ADICIONAR
A Microsoft está realizando uma pesquisa online para saber sua opinião sobre o site do MSDN. Se você optar por participar, a pesquisa online lhe será apresentada quando você sair do site do MSDN.

Deseja participar?
© 2013 Microsoft. Todos os direitos reservados.