英語で読む

次の方法で共有


Type.IsVisible プロパティ

定義

Type にアセンブリの外側のコードからアクセスできるかどうかを示す値を取得します。

C#
public bool IsVisible { get; }

プロパティ値

Boolean

現在のtrue がパブリック型である場合、またはすべての包含する型がパブリックであるような入れ子にされたパブリック型である場合は Type。それ以外の場合は false

次のコード例では、2つのクラスをテストします。そのうちの1つのみがアセンブリの外部で参照できます。

C#
using System;

internal class InternalOnly 
{
    public class Nested {}
}

public class Example
{
    public class Nested {}

    public static void Main()
    {
        Type t = typeof(InternalOnly.Nested);
        Console.WriteLine(
            "Is the {0} class visible outside the assembly? {1}", 
            t.FullName, 
            t.IsVisible
        );

        t = typeof(Example.Nested);
        Console.WriteLine(
            "Is the {0} class visible outside the assembly? {1}", 
            t.FullName, 
            t.IsVisible
        );
    }
}

/* This example produces the following output:

Is the InternalOnly+Nested class visible outside the assembly? False
Is the Example+Nested class visible outside the assembly? True
 */

注釈

このプロパティを使用して、型がコンポーネントアセンブリのパブリックインターフェイスの一部であるかどうかを判断します。

適用対象

製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1