Type.IsVisible 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个指示 Type 是否可由程序集之外的代码访问的值。
public:
property bool IsVisible { bool get(); };
public bool IsVisible { get; }
member this.IsVisible : bool
Public ReadOnly Property IsVisible As Boolean
属性值
如果当前 true
是公共类型或公共嵌套类型从而使所有封闭类型都是公共类型,则为 Type;否则为 false
。
示例
下面的代码示例测试两个类,其中只有一个类在程序集外可见。
using namespace System;
private ref class InternalOnly
{
public:
ref class Nested {};
};
public ref class Example
{
public:
ref class Nested {};
};
// Entry point of example
int main()
{
Type^ classType = InternalOnly::Nested::typeid;
Console::WriteLine(
"Is the {0} class visible outside the assembly? {1}",
classType->FullName, classType->IsVisible);
classType = Example::Nested::typeid;
Console::WriteLine(
"Is the {0} class visible outside the assembly? {1}",
classType->FullName, classType->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
*/
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
*/
Friend Class InternalOnly
Public Class Nested
End Class
End Class
Public Class Example
Public Class Nested
End Class
Public Shared Sub Main()
With GetType(InternalOnly.Nested)
Console.WriteLine("Is the " & .FullName _
& " class visible outside the assembly? " & .IsVisible)
End With
With GetType(Example.Nested)
Console.WriteLine("Is the " & .FullName _
& " class visible outside the assembly? " & .IsVisible)
End With
End Sub
End Class
' 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
注解
使用此属性确定类型是否为组件程序集的公共接口的一部分。