Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit af18a5f

Browse files
kassemsandarusitmat
authored andcommitted
TypeDefinition.IsNested Property (#25963)
* Adding API TypeDefinition.IsNested. Closes #5377 * Adding related tests. * fixing backward asserts. * Switching to expression-bodied syntax. * Adding doc comment. Switching to an assembly that actually has nested types. * Fixing xml doc comment to align with msdn comment style. * Update TypeDefinition.cs Fixing bad grammar in comments.
1 parent 5d71d9e commit af18a5f

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

src/System.Reflection.Metadata/ref/System.Reflection.Metadata.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,6 +2274,7 @@ public enum StandaloneSignatureKind
22742274
public readonly partial struct TypeDefinition
22752275
{
22762276
private readonly object _dummy;
2277+
public bool IsNested { get { throw null; } }
22772278
public System.Reflection.TypeAttributes Attributes { get { throw null; } }
22782279
public System.Reflection.Metadata.EntityHandle BaseType { get { throw null; } }
22792280
public System.Reflection.Metadata.StringHandle Name { get { throw null; } }

src/System.Reflection.Metadata/src/System/Reflection/Metadata/TypeSystem/TypeDefinition.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public TypeAttributes Attributes
5252
}
5353
}
5454

55+
/// <summary>
56+
/// Indicates whether this is a nested type.
57+
/// </summary>
58+
public bool IsNested => Attributes.IsNested();
59+
5560
/// <summary>
5661
/// Name of the type.
5762
/// </summary>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Xunit;
6+
7+
namespace System.Reflection.Metadata.Tests
8+
{
9+
public class TypeDefinitionTests
10+
{
11+
[Fact]
12+
public void ValidateTypeDefinitionIsNestedNoProjection()
13+
{
14+
var reader = MetadataReaderTests.GetMetadataReader(Namespace.NamespaceTests, options: MetadataReaderOptions.None);
15+
16+
foreach (var typeDefHandle in reader.TypeDefinitions)
17+
{
18+
var typeDef = reader.GetTypeDefinition(typeDefHandle);
19+
20+
Assert.Equal(typeDef.Attributes.IsNested(), typeDef.IsNested);
21+
}
22+
}
23+
24+
[Fact]
25+
public void ValidateTypeDefinitionIsNestedWindowsProjection()
26+
{
27+
var reader = MetadataReaderTests.GetMetadataReader(Namespace.NamespaceTests, options: MetadataReaderOptions.ApplyWindowsRuntimeProjections);
28+
29+
foreach (var typeDefHandle in reader.TypeDefinitions)
30+
{
31+
var typeDef = reader.GetTypeDefinition(typeDefHandle);
32+
33+
Assert.Equal(typeDef.Attributes.IsNested(), typeDef.IsNested);
34+
}
35+
}
36+
}
37+
}

src/System.Reflection.Metadata/tests/System.Reflection.Metadata.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<Compile Include="Metadata\PortablePdb\StandalonePortablePdbStreamTests.cs" />
6161
<Compile Include="Metadata\TagToTokenTests.cs" />
6262
<Compile Include="Metadata\PortablePdb\DocumentNameTests.cs" />
63+
<Compile Include="Metadata\TypeSystem\TypeDefinitionTests.cs" />
6364
<Compile Include="PortableExecutable\DebugDirectoryBuilderTests.cs" />
6465
<Compile Include="PortableExecutable\PEHeaderBuilderTests.cs" />
6566
<Compile Include="PortableExecutable\PEMemoryBlockTests.cs" />

0 commit comments

Comments
 (0)