Type.IsNotPublic プロパティ

定義

Type がパブリックとして宣言されていないかどうかを示す値を取得します。

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

プロパティ値

true がパブリックとして宣言されていなくて、入れ子にされた型でない場合は Type。それ以外の場合は 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

次のコード例は、入れ子になったクラスに と IsNotPublic を使用IsPublicできない理由を示しています。

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

入れ子になったクラスの場合は、 と IsNotPublicIsPublic結果を無視し、 と IsNestedPrivateIsNestedPublic結果にのみ注意してください。 このコード フラグメントのリフレクション出力は次のようになります。

クラス IsNotPublic IsPublic IsNestedPublic IsNestedPrivate
A FALSE TRUE FALSE FALSE
B FALSE FALSE TRUE false
C FALSE FALSE FALSE TRUE

注釈

入れ子になった型では、このプロパティを使用しないでください。代わりに プロパティを IsNestedPublic 使用してください。

現在 Type の がジェネリック型の型パラメーターを表す場合、このプロパティは を返します false

適用対象

こちらもご覧ください