Type.IsNested Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets a value indicating whether the current Type object represents a type whose definition is nested inside the definition of another type.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

Syntax

Public ReadOnly Property IsNested As Boolean
public bool IsNested { get; }

Property Value

Type: System..::.Boolean
true if the Type is nested inside another type; otherwise, false.

Remarks

The IsNested property returns true for all nested types, regardless of visibility. To test for nesting and visibility at the same time, use the related properties IsNestedAssembly, IsNestedFamily, IsNestedFamANDAssem, IsNestedFamORAssem, IsNestedPrivate, or IsNestedPublic.

Note

The VisibilityMask enumeration member selects the visibility attributes for a type.

Examples

The following code example displays the value of the IsNested property for both a protected nested class and a public nested class.


Public Class Example
   Protected Class NestedProtected
   End Class

   Public Class NestedPublic
   End Class

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      With GetType(NestedProtected)
         outputBlock.Text &= "Is " & .FullName & " nested? " & .IsNested & vbCrLf
      End With
      With GetType(NestedPublic)
         outputBlock.Text &= "Is " & .FullName & " nested? " & .IsNested & vbCrLf
      End With
   End Sub
End Class

' This example produces the following output:
'
'Is Example+NestedProtected nested? True
'Is Example+NestedPublic nested? True 
using System;

public class Example
{
   protected class NestedProtected
   {
   }

   public class NestedPublic
   {
   }

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      Type t = typeof(NestedProtected);
      outputBlock.Text += String.Format("Is {0} nested? {1}", t.FullName, t.IsNested) + "\n";
      t = typeof(NestedPublic);
      outputBlock.Text += String.Format("Is {0} nested? {1}", t.FullName, t.IsNested) + "\n";
   }
}

/* This example produces the following output:

Is Example+NestedProtected nested? True
Is Example+NestedPublic nested? True 
 */

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Platforms

Windows Phone

See Also

Reference

Type Class

System Namespace

IsNestedAssembly

IsNestedFamily

IsNestedFamANDAssem

IsNestedFamORAssem

IsNestedPrivate

IsNestedPublic