Type.IsAbstract 属性
获取一个值,通过该值指示 Type 是否为抽象的并且必须被重写。
**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public ReadOnly Property IsAbstract As Boolean
用法
Dim instance As Type
Dim value As Boolean
value = instance.IsAbstract
public bool IsAbstract { get; }
public:
virtual property bool IsAbstract {
bool get () sealed;
}
/** @property */
public final boolean get_IsAbstract ()
public final function get IsAbstract () : boolean
属性值
如果 Type 是抽象的,则为 true;否则为 false。
备注
如果当前 Type 表示泛型类型的类型形参,则此属性 (Property) 始终返回 true。这是因为不能创建泛型类型形参的实例。
示例
下面的示例在指定的对象为 abstract 时返回 true;否则,它将返回 false。
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Public MustInherit Class MyMustInheritClass
End Class 'MyMustInheritClass
Public Class [MyClass]
End Class '[MyClass]
Public Class Type_IsMustInherit
Public Shared Sub Main()
Try
' Check whether the return type of MyMustInheritClass is MustInherit or not.
Console.WriteLine(ControlChars.NewLine + "Checking whether the type is MustInherit." + ControlChars.NewLine)
If GetType([MyMustInheritClass]).IsAbstract = True Then
Console.WriteLine("MyMustInheritClass is {0}", "a MustInherit class.")
Else
Console.WriteLine("MyMustInheritClass is {0}", "not a MustInherit class.")
End If
' Check whether the return type of MyClass is MustInherit or not.
If GetType([MyClass]).IsAbstract = True Then
Console.WriteLine("MyClass is {0}", "a MustInherit class.")
Else
Console.WriteLine("MyClass is {0}", "not a MustInherit class.")
End If
Catch e As Exception
Console.WriteLine("Exception: {0} " + ControlChars.Cr, e.Message.ToString())
End Try
End Sub 'Main
End Class 'Type_IsMustInherit
using System;
using System.Reflection;
public abstract class MyAbstractClass
{
}
public class MyClass
{
}
public class Type_IsAbstract
{
public static void Main()
{
try
{
// Check whether the return type of MyAbstractClass is abstract or not.
Console.WriteLine("\nChecking whether the type is abstract.\n");
Console.WriteLine("MyAbstractClass is {0}", (typeof(MyAbstractClass).IsAbstract) ? "an abstract class." : "not an abstract class.");
// Check whether the return type of MyClass is abstract or not.
Console.WriteLine("MyClass is {0}", (typeof(MyClass).IsAbstract) ? "an abstract class." : "not an abstract class.");
}
catch( Exception e )
{
Console.WriteLine( "Exception: {0} \n", e.Message );
}
}
}
using namespace System;
using namespace System::Reflection;
public ref class AbstractClass abstract
{
};
public ref class NonAbstractClass
{
};
int main()
{
// Check whether the return type of MyAbstractClass is abstract or not.
Console::WriteLine("\nChecking whether the type is abstract.\n");
if ((AbstractClass::typeid->IsAbstract))
{
Console::WriteLine("The AbstractClass is an abstract class.");
}
else
{
Console::WriteLine("The AbstractClass is not an abstract class.");
}
// Check whether the return type of MyClass is abstract or not.
if ((NonAbstractClass::typeid->IsAbstract))
{
Console::WriteLine("The NonAbstractClass is an abstract class.");
}
else
{
Console::WriteLine("The NonAbstractClass is not an abstract class.");
}
};
import System.*;
import System.Reflection.*;
abstract public class MyAbstractClass
{
} //MyAbstractClass
public class MyClass
{
} //MyClass
public class Type_IsAbstract
{
public static void main(String[] args)
{
try {
// Check whether the return type of MyAbstractClass is
// abstract or not.
Console.WriteLine("\nChecking whether the type is abstract.\n");
Console.WriteLine("MyAbstractClass is {0}", (MyAbstractClass.class.
ToType().get_IsAbstract()) ? "an abstract class." :
"not an abstract class.");
// Check whether the return type of MyClass is abstract or not.
Console.WriteLine("MyClass is {0}", (MyClass.class.ToType().
get_IsAbstract()) ? "an abstract class." :
"not an abstract class.");
}
catch (System.Exception e) {
Console.WriteLine("Exception: {0} \n", e.get_Message());
}
} //main
} //Type_IsAbstract
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0