Type.IsPublic Eigenschaft
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Ruft einen Wert ab, der angibt, ob die Type Deklaration öffentlich ist.
public:
property bool IsPublic { bool get(); };
public bool IsPublic { get; }
member this.IsPublic : bool
Public ReadOnly Property IsPublic As Boolean
Eigenschaftswert
truewenn die Type öffentlich deklariert ist und kein geschachtelter Typ ist; andernfalls . false
Implementiert
Beispiele
Das folgende Beispiel erstellt eine Instanz von MyTestClass, überprüft auf die IsPublic Eigenschaft und zeigt das Ergebnis an.
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
Ignorieren Sie bei geschachtelten Klassen die Ergebnisse IsPublic und IsNotPublic achten Sie nur auf die Ergebnisse und IsNestedPublicIsNestedPrivatedie .
Hinweise
Verwenden Sie nicht mit geschachtelten Typen; verwenden Sie IsNestedPublic stattdessen.
Wenn der aktuelle Type Parameter einen Typparameter eines generischen Typs darstellt, gibt diese Eigenschaft zurück true.
TypeAttributes.VisibilityMask wählt die Sichtbarkeitsattribute aus.