Type.IsPublic Właściwość

Definicja

Pobiera wartość wskazującą, czy wartość Type jest zadeklarowana jako publiczna.

public:
 property bool IsPublic { bool get(); };
public bool IsPublic { get; }
member this.IsPublic : bool
Public ReadOnly Property IsPublic As Boolean

Wartość właściwości

Boolean

truejeśli obiekt Type jest zadeklarowany jako publiczny i nie jest typem zagnieżdżony; w przeciwnym razie . false

Implementuje

Przykłady

Poniższy przykład tworzy wystąpienie klasy MyTestClass , sprawdza właściwość i wyświetla IsPublic wynik.

using namespace System;

// Declare MyTestClass as public.
public ref class TestClass{};

int main()
{
   TestClass^ testClassInstance = gcnew TestClass;
   
   // Get the type of myTestClassInstance.
   Type^ testType = testClassInstance->GetType();
   
   // Get the IsPublic property of the myTestClassInstance.
   bool isPublic = testType->IsPublic;
   Console::WriteLine( "Is {0} public? {1}", testType->FullName, isPublic);
}
using System;

public class TestClass
{
}

public class Example
{
   public static void Main()
   {
      TestClass testClassInstance = new TestClass();
      // Get the type of myTestClassInstance.
      Type   testType = testClassInstance.GetType();
      // Get the IsPublic property of testClassInstance.
      bool isPublic = testType.IsPublic;
      Console.WriteLine("Is {0} public? {1}", testType.FullName, isPublic);
   }
}
// The example displays the following output:
//        Is TestClass public? True
Public Class TestClass
End Class

Public Class Example
   Public Shared Sub Main()
      Dim testClassInstance As New TestClass()
      
      ' Get the type of testClassInstance.
      Dim testType As Type = testClassInstance.GetType()
      ' Get the IsPublic property of testClassInstance.
      Dim isPublic As Boolean = testType.IsPublic
      Console.WriteLine("Is {0} public? {1}", testType.FullName, isPublic)
   End Sub 
End Class 
' The example displays the following output:
'       Is TestClass public? True

W przypadku klas zagnieżdżonych zignoruj wyniki i i zwróć uwagę tylko IsPublic IsNotPublic na wyniki i IsNestedPublic IsNestedPrivate .

Uwagi

Nie należy używać z zagnieżdżonych typów; Zamiast tego IsNestedPublic użyj .

Jeśli bieżący reprezentuje parametr typu typu Type ogólnego, ta właściwość zwraca wartość true .

TypeAttributes.VisibilityMask Wybiera atrybuty widoczności.

Dotyczy

Zobacz też