Type.IsNotPublic Type.IsNotPublic Type.IsNotPublic Type.IsNotPublic Property

定义

获取一个值,该值指示 Type 是否声明为公共类型。Gets a value indicating whether the Type is not declared public.

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

属性值

如果 true 未声明为公共类型且不是嵌套类型,则为 Type;否则为 falsetrue if the Type is not declared public and is not a nested type; otherwise, false.

实现

示例

此示例使用IsNotPublic要获取类型的可见性属性。This example uses the IsNotPublic property to get the visibility of the type.

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
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的嵌套类。The following code example demonstrates why you cannot use IsPublic and IsNotPublic for nested classes.

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


private:
   ref class C{};


};

public class A 
{
    public class B { }
    private class C { }
}
Public Class A
    Public Class B
    End Class
    Private Class C
    End Class
End Class

对于嵌套类,忽略的结果IsPublicIsNotPublic而且注意到的结果仅IsNestedPublicIsNestedPrivateFor nested classes, ignore the results of IsPublic and IsNotPublic and pay attention only to the results of IsNestedPublic and IsNestedPrivate. 此代码片段的反射输出将如下所示:The reflection output for this code fragment would be as follows:

Class IsNotPublicIsNotPublic IsPublicIsPublic IsNestedPublicIsNestedPublic IsNestedPrivateIsNestedPrivate
包含当前请求的 URL 的A falseFALSE trueTRUE falseFALSE falseFALSE
BB falseFALSE falseFALSE trueTRUE falseFALSE
CC falseFALSE falseFALSE falseFALSE trueTRUE

注解

使用嵌套类型,不使用此属性使用IsNestedPublic属性改为。Do not use this property with nested types; use the IsNestedPublic property instead.

如果当前Type表示类型参数的泛型类型,此属性返回falseIf the current Type represents a type parameter of a generic type, this property returns false.

适用于

另请参阅