Type.IsAbstract 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.
Obtém um valor que indica se o Type é abstrato e deve ser sobreposto.
public:
property bool IsAbstract { bool get(); };
public bool IsAbstract { get; }
member this.IsAbstract : bool
Public ReadOnly Property IsAbstract As Boolean
Valor de Propriedade
true se o Type for abstrato; caso contrário, false.
Implementações
Exemplos
O exemplo seguinte cria um array de Type objetos que representam os seguintes tipos type:contains type returns true se o objeto especificado for abstract; caso contrário, ele retorna false.
AbstractClass, uma classe abstrata (uma classe marcada comoabstractem C# eMustInheritem Visual Basic).DerivedClass, uma classe que herda deAbstractClass.SingleClass, uma classe não hereditária. é definido comosealedem C# eNotInheritableem Visual Basic.ITypeInfo, uma interface.ImplementingClass, uma classe que implementa aITypeInfointerface.
O método retorna true apenas para AbstractClass, a classe abstrata, e ITypeInfo, a interface.
using System;
public abstract class AbstractClass
{}
public class DerivedClass : AbstractClass
{}
public sealed class SingleClass
{}
public interface ITypeInfo
{
string GetName();
}
public class ImplementingClass : ITypeInfo
{
public string GetName()
{
return this.GetType().FullName;
}
}
delegate string InputOutput(string inp);
public class Example
{
public static void Main()
{
Type[] types= { typeof(AbstractClass),
typeof(DerivedClass),
typeof(ITypeInfo),
typeof(SingleClass),
typeof(ImplementingClass),
typeof(InputOutput) };
foreach (var type in types)
Console.WriteLine("{0} is abstract: {1}",
type.Name, type.IsAbstract);
}
}
// The example displays the following output:
// AbstractClass is abstract: True
// DerivedClass is abstract: False
// ITypeInfo is abstract: True
// SingleClass is abstract: False
// ImplementingClass is abstract: False
// InputOutput is abstract: False
[<AbstractClass>]
type AbstractClass() = class end
type DerivedClass() = inherit AbstractClass()
[<Sealed>]
type SingleClass() = class end
type ITypeInfo =
abstract GetName: unit -> string
type ImplementingClass() =
interface ITypeInfo with
member this.GetName() =
this.GetType().FullName
type DiscriminatedUnion =
| Yes
| No of string
type Record =
{ Name: string
Age: int }
type InputOutput = delegate of inp: string -> string
let types =
[ typeof<AbstractClass>
typeof<DerivedClass>
typeof<ITypeInfo>
typeof<SingleClass>
typeof<ImplementingClass>
typeof<DiscriminatedUnion>
typeof<Record>
typeof<InputOutput> ]
for typ in types do
printfn $"{typ.Name} is abstract: {typ.IsAbstract}"
// The example displays the following output:
// AbstractClass is abstract: True
// DerivedClass is abstract: False
// ITypeInfo is abstract: True
// SingleClass is abstract: False
// ImplementingClass is abstract: False
// DiscriminatedUnion is abstract: True
// Record is abstract: False
// InputOutput is abstract: False
Public MustInherit Class AbstractClass
End Class
Public Class DerivedClass : Inherits AbstractClass
End Class
Public NotInheritable Class SingleClass
End Class
Public Interface ITypeInfo
Function GetName() As String
End Interface
Public Class ImplementingClass : Implements ITypeInfo
Public Function GetName() As String _
Implements ITypeInfo.GetName
Return Me.GetType().FullName
End Function
End Class
Delegate Function InputOutput(inp As String) As String
Module Example
Public Sub Main()
Dim types() As Type = { GetType(AbstractClass),
GetType(DerivedClass),
GetType(ITypeInfo),
GetType(SingleClass),
GetType(ImplementingClass),
GetType(InputOutput) }
For Each type In types
Console.WriteLine("{0} is abstract: {1}",
type.Name, type.IsAbstract)
Next
End Sub
End Module
' The example displays the following output:
' AbstractClass is abstract: True
' DerivedClass is abstract: False
' ITypeInfo is abstract: True
' SingleClass is abstract: False
' ImplementingClass is abstract: False
' InputOutput is abstract: False
Observações
A IsAbstract propriedade retorna true nos seguintes casos:
O tipo atual é abstrato; ou seja, não pode ser instanciada, mas só pode servir como classe base para classes derivadas. Em C#, as classes abstratas são marcadas com a palavra-chave abstract; em F#, são marcados com o atributo AbstractClass; em Visual Basic, estão marcadas com a palavra-chave MustInherit.
O tipo atual é uma interface.
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 .