Type.IsNotPublic Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan nilai yang menunjukkan apakah Type tidak dinyatakan publik.
public:
property bool IsNotPublic { bool get(); };
public bool IsNotPublic { get; }
member this.IsNotPublic : bool
Public ReadOnly Property IsNotPublic As Boolean
Nilai Properti
true
Type jika tidak dinyatakan publik dan bukan jenis berlapis; jika tidak, false.
Penerapan
Contoh
Contoh ini menggunakan IsNotPublic properti untuk mendapatkan visibilitas jenis.
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
Contoh kode berikut menunjukkan mengapa Anda tidak dapat menggunakan IsPublic dan IsNotPublic untuk kelas berlapis.
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
Untuk kelas berlapis, abaikan hasil IsPublic dan IsNotPublic dan perhatikan hanya hasil IsNestedPublic dan IsNestedPrivate. Output refleksi untuk fragmen kode ini adalah sebagai berikut:
| Kelas | IsNotPublic | IsPublic | IsNestedPublic | IsNestedPrivate |
|---|---|---|---|---|
| A | FALSE | BENAR | FALSE | FALSE |
| B | FALSE | FALSE | BENAR | FALSE |
| C | FALSE | FALSE | FALSE | BENAR |
Keterangan
Jangan gunakan properti ini dengan tipe berlapis; gunakan properti sebagai gantinya IsNestedPublic .
Jika saat ini Type mewakili parameter jenis jenis generik, properti ini mengembalikan false.