Type.IsInterface Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Recebe um valor que indica se o Type é uma interface; ou seja, não uma classe ou um tipo de valor.
public:
property bool IsInterface { bool get(); };
public bool IsInterface { get; }
member this.IsInterface : bool
Public ReadOnly Property IsInterface As Boolean
Valor de Propriedade
true se o Type for uma interface; caso contrário, false.
Implementações
Exemplos
O exemplo seguinte cria uma interface, verifica o tipo de interface e indica se uma classe tem o conjunto de IsInterface propriedades.
using System;
// Declare an interface.
interface myIFace
{
}
class MyIsInterface
{
public static void Main(string []args)
{
try
{
// Get the IsInterface attribute for myIFace.
bool myBool1 = typeof(myIFace).IsInterface;
//Display the IsInterface attribute for myIFace.
Console.WriteLine("Is the specified type an interface? {0}.", myBool1);
// Get the attribute IsInterface for MyIsInterface.
bool myBool2 = typeof(MyIsInterface).IsInterface;
//Display the IsInterface attribute for MyIsInterface.
Console.WriteLine("Is the specified type an interface? {0}.", myBool2);
}
catch(Exception e)
{
Console.WriteLine("\nAn exception occurred: {0}.", e.Message);
}
}
}
/* The example produces the following output:
Is the specified type an interface? True.
Is the specified type an interface? False.
*/
// Declare an interface.
type myIFace = interface end
type MyIsInterface = class end
try
// Get the IsInterface attribute for myIFace.
let myBool1 = typeof<myIFace>.IsInterface
//Display the IsInterface attribute for myIFace.
printfn $"Is the specified type an interface? {myBool1}."
// Get the attribute IsInterface for MyIsInterface.
let myBool2 = typeof<MyIsInterface>.IsInterface
//Display the IsInterface attribute for MyIsInterface.
printfn $"Is the specified type an interface? {myBool2}."
with e ->
printfn $"\nAn exception occurred: {e.Message}."
(* The example produces the following output:
Is the specified type an interface? True.
Is the specified type an interface? False.
*)
' Declare an interface.
Interface myIFace
End Interface
Class MyIsInterface
Public Shared Sub Main()
' Get the IsInterface attribute for myIFace.
Dim myBool1 As Boolean = GetType(myIFace).IsInterface
Console.WriteLine("Is the specified type an interface? {0}.", myBool1)
' Determine whether Example is an interface.
Dim myBool2 As Boolean = GetType(MyIsInterface).IsInterface
Console.WriteLine("Is the specified type an interface? {0}.", myBool2)
Console.ReadLine()
End Sub
End Class
' The example displays the following output:
' Is the specified type an interface? True.
' Is the specified type an interface? False.
Observações
Distingue ClassSemanticsMask uma declaração de tipo como classe, interface ou tipo de valor.
Se a corrente Type representa um parâmetro de tipo na definição de um tipo genérico ou método genérico, esta propriedade devolve falsesempre .
Esta propriedade é somente leitura.