Type.IsNotPublic Type.IsNotPublic Type.IsNotPublic Type.IsNotPublic Property

Definition

Ruft einen Wert ab, der angibt, ob der Type nicht als öffentlich deklariert ist.Gets a value indicating whether the Type is not declared public.

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

Eigenschaftswert

true, wenn der Type nicht als öffentlich deklariert und kein geschachtelter Typ ist, andernfalls false.true if the Type is not declared public and is not a nested type; otherwise, false.

Implementiert

Beispiele

In diesem Beispiel wird IsNotPublic die-Eigenschaft verwendet, um die Sichtbarkeit des Typs zu erhalten.This example uses the IsNotPublic property to get the visibility of the type.

using namespace System;
using namespace System::IO;
using namespace System::Reflection;

int main()
{
   //Get the Type and MemberInfo.
   Type^ t = Type::GetType("System.IO.File");
   array<MemberInfo^>^ members = t->GetMembers();
   
   //Get and display the DeclaringType method.
   Console::WriteLine("There are {0} members in {1}.",
                      members->Length, t->FullName );
   Console::WriteLine("Is {0} non-public? {1}",
                      t->FullName, t->IsNotPublic );
}
// The example displays the following output:
//       There are 60 members in System.IO.File.
//       Is System.IO.File non-public? False
using System;
using System.IO;
using System.Reflection;

class Example
{ 
    public static void Main()
    { 
        // Get the Type and MemberInfo.
        Type t = Type.GetType("System.IO.File");
        MemberInfo[] members = t.GetMembers();
        // Get and display the DeclaringType method.
        Console.WriteLine("\nThere are {0} members in {1}.",
                          members.Length, t.FullName);
        Console.WriteLine("Is {0} non-public? {1}",
                          t.FullName, t.IsNotPublic);
    }
}
// The example displays output like the following:
//       There are 60 members in System.IO.File.
//       Is System.IO.File non-public? False
Imports System.IO
Imports System.Reflection

Module Example
    Public Sub Main()
        'Get the Type and MemberInfo.
        Dim t As Type = Type.GetType("System.IO.File")
        Dim members As MemberInfo() = t.GetMembers()
        'Get and display the DeclaringType method.
        Console.WriteLine("There are {0} members in {1}.",
                          members.Length, t.FullName)
        Console.WriteLine("Is {0} non-public? {1}",
                          t.FullName, t.IsNotPublic)
    End Sub
End Module
' The example displays output like the following:
'       There are 60 members in System.IO.File.
'       Is System.IO.File non-public? False

Im folgenden Codebeispiel wird veranschaulicht, warum Sie IsPublic und IsNotPublic nicht für geschlagelte Klassen verwenden können.The following code example demonstrates why you cannot use IsPublic and IsNotPublic for nested classes.

public ref class A
{
public:
   ref class B{};


private:
   ref class C{};


};

public class A 
{
    public class B { }
    private class C { }
}
Public Class A
    Public Class B
    End Class
    Private Class C
    End Class
End Class

Ignorieren Sie bei der-Klasse die Ergebnisse von IsPublic und IsNotPublic , und achten Sie nur auf die Ergebnisse IsNestedPublic von IsNestedPrivateund.For nested classes, ignore the results of IsPublic and IsNotPublic and pay attention only to the results of IsNestedPublic and IsNestedPrivate. Die Reflektionsausgabe für dieses Code Fragment lautet wie folgt:The reflection output for this code fragment would be as follows:

KlasseClass IsNotPublicIsNotPublic IsPublicIsPublic IsNestedPublicIsNestedPublic IsNestedPrivateIsNestedPrivate
AA falseFALSE trueTRUE falseFALSE falseFALSE
BB falseFALSE falseFALSE trueTRUE falseFALSE
CC falseFALSE falseFALSE falseFALSE trueTRUE

Hinweise

Verwenden Sie diese Eigenschaft nicht mit den folgenden Typen: Verwenden Sie IsNestedPublic stattdessen die-Eigenschaft.Do not use this property with nested types; use the IsNestedPublic property instead.

Wenn der aktuelle Type einen Typparameter eines generischen Typs darstellt, gibt diese Eigenschaft falsezurück.If the current Type represents a type parameter of a generic type, this property returns false.

Gilt für:

Siehe auch