Type.IsNotPublic Eigenschap

Definitie

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

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

Waarde van eigenschap

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

Implementeringen

Voorbeelden

In dit voorbeeld wordt de IsNotPublic eigenschap gebruikt om de zichtbaarheid van het type te krijgen.

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
open System

// Get the Type and MemberInfo.
let t = Type.GetType "System.IO.File"
let members = t.GetMembers()
// Get and display the DeclaringType method.
printfn $"\nThere are {members.Length} members in {t.FullName}."
printfn $"Is {t.FullName} non-public? {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

In het volgende codevoorbeeld ziet u waarom u deze niet kunt gebruiken IsPublic en IsNotPublic voor geneste klassen.

public class A
{
    public class B { }
    private class C { }
}
module A =
    type B() = class end
    type C() = class end
Public Class A
    Public Class B
    End Class
    Private Class C
    End Class
End Class

Voor geneste klassen negeert u de resultaten van IsPublic en IsNotPublic let u alleen op de resultaten van IsNestedPublic en IsNestedPrivate. De weerspiegelingsuitvoer voor dit codefragment is als volgt:

Class IsNotPublic IsPublic IsNestedPublic IsNestedPrivate
A FALSE TRUE FALSE FALSE
B FALSE FALSE TRUE FALSE
C FALSE FALSE FALSE TRUE

Opmerkingen

Gebruik deze eigenschap niet met geneste typen; gebruik in plaats daarvan de IsNestedPublic eigenschap.

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

Van toepassing op

Zie ook