Type.IsPublic 属性
获取一个值,该值指示 Type 是否声明为公共类型。
**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public ReadOnly Property IsPublic As Boolean
用法
Dim instance As Type
Dim value As Boolean
value = instance.IsPublic
public bool IsPublic { get; }
public:
virtual property bool IsPublic {
bool get () sealed;
}
/** @property */
public final boolean get_IsPublic ()
public final function get IsPublic () : boolean
属性值
如果 Type 声明为公共类型且不是嵌套类型,则为 true;否则为 false。
备注
不要使用嵌套类型,而应使用 IsNestedPublic。
如果当前 Type 表示泛型类型的类型形参,则此属性 (Property) 将返回 true。
TypeAttributes.VisibilityMask 选择可见性属性。
示例
下面的示例创建 MyTestClass 的实例,检查 IsPublic 属性 (Property),然后显示结果。
Imports System
Imports Microsoft.VisualBasic
Namespace SystemType
' Declare MyTestClass as public.
Public Class MyTestClass
End Class 'MyTestClass
Public Class [MyClass]
Public Shared Sub Main()
Try
Dim myBool As Boolean = False
Dim myTestClassInstance As New MyTestClass()
' Get the type of myTestClassInstance.
Dim myType As Type = myTestClassInstance.GetType()
' Get the IsPublic property of myTestClassInstance.
myBool = myType.IsPublic
Console.WriteLine(ControlChars.Cr + "Is {0 public? {1}.", myType.FullName, myBool.ToString())
Catch e As Exception
Console.WriteLine(ControlChars.Cr + "An exception occurred: {0}", e.Message.ToString())
End Try
End Sub 'Main
End Class '[MyClass]
End Namespace 'SystemType
using System;
namespace SystemType
{
// Declare MyTestClass as public.
public class MyTestClass
{
}
public class MyClass
{
public static void Main(string []args)
{
try
{
bool myBool = false;
MyTestClass myTestClassInstance = new MyTestClass();
// Get the type of myTestClassInstance.
Type myType = myTestClassInstance.GetType();
// Get the IsPublic property of the myTestClassInstance.
myBool = myType.IsPublic;
Console.WriteLine("\nIs {0} public? {1}.", myType.FullName, myBool.ToString ());
}
catch (Exception e)
{
Console.WriteLine("\nAn exception occurred: {0}", e.Message);
}
}
}
}
using namespace System;
namespace SystemType
{
// Declare MyTestClass as public.
public ref class MyTestClass{};
public ref class MyClass{};
}
int main()
{
try
{
bool myBool = false;
SystemType::MyTestClass^ myTestClassInstance = gcnew SystemType::MyTestClass;
// Get the type of myTestClassInstance.
Type^ myType = myTestClassInstance->GetType();
// Get the IsPublic property of the myTestClassInstance.
myBool = myType->IsPublic;
Console::WriteLine( "\nIs {0} public? {1}.", myType->FullName, myBool.ToString() );
}
catch ( Exception^ e )
{
Console::WriteLine( "\nAn exception occurred: {0}", e->Message );
}
}
package SystemType;
import System.*;
// Declare MyTestClass as public.
public class MyTestClass
{
} //MyTestClass
public class MyClass
{
public static void main(String[] args)
{
try {
boolean myBool = false;
MyTestClass myTestClassInstance = new MyTestClass();
// Get the type of myTestClassInstance.
Type myType = myTestClassInstance.GetType();
// Get the IsPublic property of the myTestClassInstance.
myBool = myType.get_IsPublic();
Console.WriteLine("\nIs {0} public? {1}.", myType.get_FullName(),
System.Convert.ToString(myBool));
}
catch (System.Exception e) {
Console.WriteLine("\nAn exception occurred: {0}", e.get_Message());
}
} //main
} //MyClass
对于嵌套类,忽略 IsPublic 和 IsNotPublic 的结果,而只注意 IsNestedPublic 和 IsNestedPrivate 的结果。
平台
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