Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean edit pass on attributes #44513

Merged
merged 11 commits into from
Jan 27, 2025
Merged

Conversation

BillWagner
Copy link
Member

@BillWagner BillWagner commented Jan 24, 2025

@BillWagner BillWagner force-pushed the more-attribute-reference branch from 2ceced9 to 65cf088 Compare January 27, 2025 16:28
BillWagner and others added 10 commits January 27, 2025 16:18
Fixes dotnet#42850:  Add a new page to reference attributes that cause the compiler to emit different IL modifiers instead of putting the attribute in the emitted IL.
Fixes dotnet#43109

Most of these have been added to the general page. A few are expressed in source differently, and were added to the new pseudo-attributes page.
Add a list of attributes that are written by the compiler that shouldn't be added in users' source code.
Some attributes weren't in the `displayName` element for the TOC. Review all of them and add them again.
Mostly fix anchors.

The one C# 9 spec was never intended to be published.
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
Link between the C# attribute page and the .NET fundamentals article on experimental attributes in the runtime.
@BillWagner BillWagner force-pushed the more-attribute-reference branch from 65cf088 to 240052b Compare January 27, 2025 21:35
@BillWagner BillWagner enabled auto-merge (squash) January 27, 2025 21:35
@BillWagner BillWagner merged commit 6303b18 into dotnet:main Jan 27, 2025
8 checks passed
@BillWagner BillWagner deleted the more-attribute-reference branch January 27, 2025 21:54
| <xref:System.Runtime.CompilerServices.SpecialNameAttribute?displayProperty=fullName> | Specifies the IL `specialname` modifier. The compiler automatically adds this modifier for methods that require it. |
| <xref:System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute?displayProperty=nameWithType> | This attribute is required for the `delegate*` feature. The compiler adds it to any [`delegate*`](../unsafe-code.md#function-pointers) that requires its use. |

The following custom attributes are generally disallowed in C# source. They're listed here to aid library authors who use reflection, and to ensure you don't create custom attributes with the same name.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though, creating custom attributes with the same name in a different namespace is okay, and custom attributes don't go in the System namespace.

| <xref:System.Runtime.InteropServices.DefaultParameterValueAttribute?displayProperty=fullName> | Specifies the default value for the parameter. Use the [default parameter syntax](../../methods.md#optional-parameters-and-arguments). |
| <xref:System.Runtime.InteropServices.InAttribute?displayProperty=fullName> | Specifies the IL `[in]` modifier. Use the [`in`](../keywords/method-parameters.md#in-parameter-modifier) or [`ref readonly`](../keywords/method-parameters.md#ref-readonly-modifier). |
| <xref:System.Runtime.CompilerServices.SpecialNameAttribute?displayProperty=fullName> | Specifies the IL `specialname` modifier. The compiler automatically adds this modifier for methods that require it. |
| <xref:System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute?displayProperty=nameWithType> | This attribute is required for the `delegate*` feature. The compiler adds it to any [`delegate*`](../unsafe-code.md#function-pointers) that requires its use. |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[UnmanagedCallersOnly] is actually something the user must apply in code in order to use the unmanaged calling convention specifically with the delegate* feature:

using System.Runtime.InteropServices;

unsafe
{
    delegate* unmanaged<void> someFuncPointer = &SomeMethod;
}

[UnmanagedCallersOnly] // Compilation fails if this is removed
static void SomeMethod() { }

| <xref:System.Runtime.CompilerServices.MethodImplAttribute?displayProperty=fullName> | `flag` | Constructor arguments specify specific named flags such as `aggressiveinlining` or `forwardref`. These flags also specify the `native`, `managed`, or `optil` modifiers for the <xref:System.Runtime.CompilerServices.MethodCodeType?displayProperty=fullName> field. |
| <xref:System.NonSerializedAttribute?displayProperty=fullName> | `notserialized` | |
| <xref:System.Runtime.InteropServices.OptionalAttribute?displayProperty=fullName> | `[opt]` | |
| <xref:System.Runtime.InteropServices.OutAttribute?displayProperty=fullName> | `[out]` | |
Copy link
Contributor

@jnm2 jnm2 Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one could have a note parallel to the note added for InAttribute, saying "Use the out modifier."

BillWagner added a commit to BillWagner/docs that referenced this pull request Jan 28, 2025
Address commnts on dotnet#44513 submitted after it was merged.
BillWagner added a commit that referenced this pull request Jan 28, 2025
Address commnts on #44513 submitted after it was merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants