Type.IsNotPublic 屬性

定義

取得值,指出 Type 是否未宣告為公用。

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

屬性值

如果 Type 尚未宣告為公用而且不是巢狀型別,則為 true,否則為 false

實作

範例

這個範例會 IsNotPublic 使用 屬性來取得型別的可見度。

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

下列程式碼範例示範為何您無法針對巢狀類別使用 IsPublicIsNotPublic

public ref class A
{
public:
   ref class B{};


private:
   ref class C{};


};
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

對於巢狀類別,請忽略 和 IsNotPublic 的結果 IsPublic ,並只注意 和 IsNestedPrivate 的結果 IsNestedPublic 。 此程式碼片段的反映輸出如下所示:

類別 IsNotPublic IsPublic IsNestedPublic IsNestedPrivate
A FALSE true FALSE FALSE
B FALSE FALSE true false
C FALSE FALSE FALSE true

備註

請勿將此屬性與巢狀類型搭配使用;請改用 IsNestedPublic 屬性。

如果目前的 Type 表示泛型型別的型別參數,這個屬性會傳 false 回 。

適用於

另請參閱