次の方法で共有


Type.IsNotPublic プロパティ

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

Public ReadOnly Property IsNotPublic As Boolean
[C#]
public bool IsNotPublic {get;}
[C++]
public: __property bool get_IsNotPublic();
[JScript]
public function get IsNotPublic() : Boolean;

プロパティ値

最上位の Type がパブリックとして宣言されていない場合は true 。それ以外の場合は false

解説

IsPublicIsNotPublic は、最上位の型だけの参照可能範囲を取得します。

VisibilityMask は、参照可能範囲属性を選択します。

使用例

IsNotPublic を使用して、最上位の型の参照可能範囲を取得するコード例を次に示します。

 
Imports System
Imports System.IO
Imports System.Reflection
Imports Microsoft.VisualBasic
Class MyMemberInfo
    Public Shared Sub Main()
        Console.WriteLine(ControlChars.Cr + "Reflection.MemberInfo")
        'Get the Type and MemberInfo.
        Dim MyType As Type = Type.GetType("System.IO.File")
        Dim Mymemberinfoarray As MemberInfo() = MyType.GetMembers()
        'Get and display the DeclaringType method.
        Console.WriteLine(ControlChars.Cr + "There are {0} members in {1}.", _
           Mymemberinfoarray.Length, MyType.FullName)
        Console.WriteLine("Is {0} nonpublic? {1}", MyType.FullName, _
           MyType.IsNotPublic.ToString())
    End Sub
End Class

[C#] 
using System;
using System.IO;
using System.Reflection;
class MyMemberInfo 
{ 
    public static void Main(string[] args) 
    { 
        Console.WriteLine ("\nReflection.MemberInfo");
        //Get the Type and MemberInfo.
        Type MyType =Type.GetType("System.IO.File");
        MemberInfo[] Mymemberinfoarray = MyType.GetMembers();
        //Get and display the DeclaringType method.
        Console.WriteLine("\nThere are {0} members in {1}.", Mymemberinfoarray.Length, MyType.FullName);
        Console.WriteLine("Is {0} nonpublic? {1}", MyType.FullName, MyType.IsNotPublic.ToString());
    }
}

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::IO;
using namespace System::Reflection;

int main() 
{ 
    Console::WriteLine (S"\nReflection.MemberInfo");
    //Get the Type and MemberInfo.
    Type* MyType =Type::GetType(S"System.IO.File");
    MemberInfo* Mymemberinfoarray[] = MyType->GetMembers();
    //Get and display the DeclaringType method.
    Console::WriteLine(S"\nThere are {0} members in {1}.", __box(Mymemberinfoarray->Length), MyType->FullName);
    Console::WriteLine(S"Is {0} nonpublic? {1}",MyType->FullName, __box(MyType->IsNotPublic));
}

このコードによって、次の出力が生成されます。

There are 27 members in System.IO.File.

Is System.IO.File public?False

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

 
Public Class A
    Public Class B
    End Class
    Private Class C
    End Class
End Class

[C#] 
public class A 
{
    public class B { }
    private class C { }
}

[C++] 
public __gc class A 
{
public:
    __gc class B { };
private:
    __gc class C { };
};

[JScript] 
public class A {
   public class B { }
   private class C { }
}

入れ子になったクラスの場合は、 IsPublic および IsNotPublic の結果は無視し、 IsNestedPublic および IsNestedPrivate の結果だけに注目してください。このコード片のリフレクション出力は、たとえば次のようになります。

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

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

Type クラス | Type メンバ | System 名前空間 | TypeAttributes