-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Conversation
2ceced9
to
65cf088
Compare
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.
65cf088
to
240052b
Compare
| <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. |
There was a problem hiding this comment.
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. | |
There was a problem hiding this comment.
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]` | | |
There was a problem hiding this comment.
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."
Address commnts on dotnet#44513 submitted after it was merged.
Fixes #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 #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.
Fixes #43110: Add a list of attributes that are written by the compiler that shouldn't be added in users' source code.
Internal previews