Type.IsPublic プロパティ
アセンブリ: mscorlib (mscorlib.dll 内)
構文
解説
入れ子にされた型で使用しないでください。代わりに、IsNestedPublic を使用してください。
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
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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
_Type.IsPublic プロパティ
アセンブリ: mscorlib (mscorlib.dll 内)
構文
解説
このプロパティは、アンマネージ コードからマネージ クラスにアクセスするためのプロパティであるため、マネージ コードからは呼び出さないでください。
Type.IsPublic プロパティは、最上位の Type がパブリックとして宣言されているかどうかを示す値を取得します。
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- Type.IsPublic プロパティのページへのリンク