Partager via


Type.IsNotPublic Propriété

Définition

Obtient une valeur indiquant si le Type n’est pas déclaré public.

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

Valeur de propriété

true si l’objet Type n’est pas déclaré public et n’est pas un type imbriqué ; sinon, false.

Implémente

Exemples

Cet exemple utilise la IsNotPublic propriété pour obtenir la visibilité du type.

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

L’exemple de code suivant montre pourquoi vous ne pouvez pas utiliser IsPublic et IsNotPublic pour les classes imbriquées.

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

Pour les classes imbriquées, ignorez les résultats et IsPublicIsNotPublic faites attention uniquement aux résultats de IsNestedPublic et IsNestedPrivate. La sortie de réflexion pour ce fragment de code se présente comme suit :

Classe IsNotPublic IsPublic IsNestedPublic IsNestedPrivate
A FAUX TRUE FAUX FAUX
B FAUX FAUX TRUE FAUX
C FAUX FAUX FAUX TRUE

Remarques

N’utilisez pas cette propriété avec des types imbriqués ; utilisez plutôt la IsNestedPublic propriété.

Si le paramètre actuel Type représente un paramètre de type d’un type générique, cette propriété retourne false.

S’applique à

Voir aussi