Type.IsNotPublic Właściwość

Definicja

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

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

Wartość właściwości

Boolean

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

Implementuje

Przykłady

W tym IsNotPublic przykładzie użyto właściwości , aby uzyskać widoczność 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

W poniższym przykładzie kodu pokazano, dlaczego nie można używać klas IsPublic IsNotPublic zagnieżdżonych i .

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

W przypadku klas zagnieżdżonych zignoruj wyniki i IsPublic i zwróć uwagę tylko na wyniki i IsNotPublic IsNestedPublic IsNestedPrivate . Dane wyjściowe odbicia dla tego fragmentu kodu będą następujące:

Klasa IsNotPublic Ispublic IsNestedPublic IsNestedPrivate
A Fałsz Prawda Fałsz Fałsz
B Fałsz Fałsz Prawda Fałsz
C Fałsz Fałsz Fałsz Prawda

Uwagi

Nie należy używać tej właściwości z zagnieżdżonych typów; Zamiast tego IsNestedPublic użyj właściwości .

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

Dotyczy

Zobacz też