Type.IsPublic Eigenschap

Definitie

Hiermee wordt een waarde opgehaald die aangeeft of het Type openbaar is gedeclareerd.

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

Waarde van eigenschap

true als het Type openbaar is gedeclareerd en geen genest type is, falseanders.

Implementeringen

Voorbeelden

In het volgende voorbeeld wordt een exemplaar gemaakt van MyTestClass, wordt gecontroleerd op de IsPublic eigenschap en wordt het resultaat weergegeven.

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
type TestClass() = class end

let testClassInstance = TestClass()
// Get the type of myTestClassInstance.
let testType = testClassInstance.GetType()
// Get the IsPublic property of testClassInstance.
let isPublic = testType.IsPublic
printfn $"Is {testType.FullName} public? {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

Voor geneste klassen negeert u de resultaten van IsPublic en IsNotPublic let u alleen op de resultaten van IsNestedPublic en IsNestedPrivate.

Opmerkingen

Niet gebruiken met geneste typen; gebruik IsNestedPublic in plaats daarvan.

Als de huidige Type een typeparameter van een algemeen type vertegenwoordigt, retourneert truedeze eigenschap.

TypeAttributes.VisibilityMask selecteert de zichtbaarheidskenmerken.

Van toepassing op

Zie ook