最上位の Type がパブリックとして宣言されているかどうかを示す値を取得します。
Public ReadOnly Property IsPublic As Boolean
[C#]
public bool IsPublic {get;}
[C++]
public: __property bool get_IsPublic();
[JScript]
public function get IsPublic() : Boolean;
プロパティ値
最上位の Type がパブリックとして宣言されている場合は true 。それ以外の場合は false 。
解説
IsPublic と IsNotPublic は、最上位の型だけの参照可能範囲を取得します。
VisibilityMask は、参照可能範囲属性を選択します。
使用例
[Visual Basic, C#, C++] MyTestClass のインスタンスを作成し、 IsPublic プロパティをチェックして、結果を表示する例を次に示します。
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
[C#]
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);
}
}
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
namespace SystemType {
// Declare MyTestClass as public.
public __gc class MyTestClass {
};
public __gc class MyClass {
};
}
int main() {
try {
bool myBool = false;
SystemType::MyTestClass* myTestClassInstance = new SystemType::MyTestClass();
// Get the type of myTestClassInstance.
Type* myType = myTestClassInstance->GetType();
// Get the IsPublic property of the myTestClassInstance.
myBool = myType->IsPublic;
Console::WriteLine(S"\nIs {0} public? {1}.", myType->FullName, myBool.ToString());
} catch (Exception* e) {
Console::WriteLine(S"\nAn exception occurred: {0}", e->Message);
}
}
[Visual Basic, C#, C++] 入れ子になったクラスの場合は、 IsPublic および IsNotPublic の結果は無視し、 IsNestedPublic および IsNestedPrivate の結果だけに注目してください。
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard