Type.IsNotPublic Vlastnost

Definice

Načte hodnotu, která označuje, jestli Type není deklarovaný jako Public.

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

Hodnota vlastnosti

Boolean

true Pokud Type není deklarována jako Public a není vnořený typ; v opačném případě false .

Implementuje

Příklady

Tento příklad používá IsNotPublic vlastnost k získání viditelnosti typu.

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

Následující příklad kódu ukazuje, proč nelze použít IsPublic a IsNotPublic pro vnořené třídy.

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

Pro vnořené třídy ignorujte výsledky IsPublic a IsNotPublic a věnujte pozornost pouze výsledkům IsNestedPublic a IsNestedPrivate . Výstup reflexe pro tento fragment kódu by byl následující:

Třída IsNotPublic Veřejné IsNestedPublic IsNestedPrivate
A FALSE TRUE FALSE NEPRAVDA
B FALSE FALSE TRUE FALSE
C FALSE FALSE FALSE TRUE

Poznámky

Nepoužívejte tuto vlastnost s vnořenými typy; IsNestedPublic místo toho použijte vlastnost.

Pokud aktuální Type představuje parametr typu obecného typu, vrátí tato vlastnost false .

Platí pro

Viz také