Skip to content

Commit ebde052

Browse files
authored
Add ExtensionMarkerAttribute (#118188)
1 parent b9bdc40 commit ebde052

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@
853853
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\DiscardableAttribute.cs" />
854854
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\EnumeratorCancellationAttribute.cs" />
855855
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ExtensionAttribute.cs" />
856+
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ExtensionMarkerAttribute.cs" />
856857
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\FixedAddressValueTypeAttribute.cs" />
857858
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\FixedBufferAttribute.cs" />
858859
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\FormattableStringFactory.cs" />
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
4+
using System.ComponentModel;
5+
6+
namespace System.Runtime.CompilerServices
7+
{
8+
/// <summary>
9+
/// This attribute is used to mark extension members and associate them with a specific marker type (which provides detailed information about an extension block and its receiver parameter).
10+
/// This attribute should not be used by developers in source code.
11+
/// </summary>
12+
[EditorBrowsable(EditorBrowsableState.Never)]
13+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)]
14+
public sealed class ExtensionMarkerAttribute : Attribute
15+
{
16+
/// <summary>Initializes a new instance of the <see cref="ExtensionMarkerAttribute"/> class.</summary>
17+
/// <param name="name">The name of the marker type this extension member is associated with.</param>
18+
public ExtensionMarkerAttribute(string name)
19+
=> Name = name;
20+
21+
/// <summary>The name of the marker type this extension member is associated with.</summary>
22+
public string Name { get; }
23+
}
24+
}

src/libraries/System.Runtime/ref/System.Runtime.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13495,6 +13495,13 @@ public sealed partial class ExtensionAttribute : System.Attribute
1349513495
{
1349613496
public ExtensionAttribute() { }
1349713497
}
13498+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
13499+
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Enum | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Event | System.AttributeTargets.Interface | System.AttributeTargets.Delegate, Inherited = false)]
13500+
public sealed partial class ExtensionMarkerAttribute : System.Attribute
13501+
{
13502+
public ExtensionMarkerAttribute(string name) { }
13503+
public string Name { get { throw null; } }
13504+
}
1349813505
[System.AttributeUsageAttribute(System.AttributeTargets.Field)]
1349913506
public sealed partial class FixedAddressValueTypeAttribute : System.Attribute
1350013507
{

src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/AttributesTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,15 @@ public static void RefSafetyRulesAttributeTests(int version)
235235
Assert.Equal(version, attr.Version);
236236
}
237237

238+
[Theory]
239+
[InlineData("1")]
240+
[InlineData("2")]
241+
public static void ExtensionMarkerAttributeTests(string name)
242+
{
243+
var attr = new ExtensionMarkerAttribute(name);
244+
Assert.Equal(name, attr.Name);
245+
}
246+
238247
[Fact]
239248
public static void ReferenceAssemblyAttributeTests()
240249
{

0 commit comments

Comments
 (0)