Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Here's an example of some of the new features that **PolySharp** can enable down
- `[OverloadResolutionPriority]` (needed for [overload resolution priority](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-13#overload-resolution-priority))
- `[ParamsCollection]` (needed for [params collection](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-13#params-collections))
- `[ConstantExpected]` (see [proposal](https://github.com/dotnet/runtime/issues/33771))
- `[CompilerLoweringPreserve]` (see [proposal](https://github.com/dotnet/runtime/issues/103430))
- `[ExtensionMarker]` (needed for [extensions](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-14#extension-members))

To leverage them, make sure to bump your C# language version. You can do this by setting the `<LangVersion>` MSBuild property in your project. For instance, by adding `<LangVersion>13.0</LangVersion>` (or your desired C# version) to the first `<PropertyGroup>` of your .csproj file. For more info on this, [see here](https://sergiopedri.medium.com/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb), but remember that you don't need to manually copy polyfills anymore: simply adding a reference to **PolySharp** will do this for you automatically.

Expand Down Expand Up @@ -84,6 +86,7 @@ It also includes the following optional runtime-supported polyfills:
- `[FeatureGuard]`
- `[FeatureSwitchDefinition]`
- `[WasmImportLinkage]` (see [here](https://github.com/dotnet/runtime/pull/93823))
- `[UnsafeAccessorType]` (see [here](https://github.com/dotnet/runtime/issues/90081))

# Options ⚙️

Expand Down
3 changes: 3 additions & 0 deletions src/PolySharp.Package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Here's an example of some of the new features that **PolySharp** can enable down
- `[OverloadResolutionPriority]` (needed for [overload resolution priority](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-13#overload-resolution-priority))
- `[ParamsCollection]` (needed for [params collection](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-13#params-collections))
- `[ConstantExpected]` (see [proposal](https://github.com/dotnet/runtime/issues/33771))
- `[CompilerLoweringPreserve]` (see [proposal](https://github.com/dotnet/runtime/issues/103430))
- `[ExtensionMarker]` (needed for [extensions](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-14#extension-members))

To leverage them, make sure to bump your C# language version. You can do this by setting the `<LangVersion>` MSBuild property in your project. For instance, by adding `<LangVersion>13.0</LangVersion>` (or your desired C# version) to the first `<PropertyGroup>` of your .csproj file. For more info on this, [see here](https://sergiopedri.medium.com/enabling-and-using-c-9-features-on-older-and-unsupported-runtimes-ce384d8debb), but remember that you don't need to manually copy polyfills anymore: simply adding a reference to **PolySharp** will do this for you automatically.

Expand Down Expand Up @@ -82,6 +84,7 @@ It also includes the following optional runtime-supported polyfills:
- `[FeatureGuard]`
- `[FeatureSwitchDefinition]`
- `[WasmImportLinkage]` (see [here](https://github.com/dotnet/runtime/pull/93823))
- `[UnsafeAccessorType]` (see [here](https://github.com/dotnet/runtime/issues/90081))

# Options ⚙️

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// <auto-generated/>
#pragma warning disable
#nullable enable annotations

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Runtime.CompilerServices
{
/// <summary>
/// When applied to an attribute class, instructs the compiler to flow applications of that attribute,
/// from source code down to compiler-generated symbols. This can help IL-based analysis tools.
/// </summary>
/// <remarks>
/// One example where this attribute applies is in C# primary constructor parameters. If an attribute
/// marked with <see cref="global::System.Runtime.CompilerServices.CompilerLoweringPreserveAttribute"/> gets applied to a primary constructor
/// parameter, the attribute will also be applied to any compiler-generated fields storing that parameter.
/// </remarks>
[global::System.AttributeUsage(global::System.AttributeTargets.Class, Inherited = false)]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::Microsoft.CodeAnalysis.Embedded]
internal sealed class CompilerLoweringPreserveAttribute : global::System.Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="global::System.Runtime.CompilerServices.CompilerLoweringPreserveAttribute"/> class.
/// </summary>
public CompilerLoweringPreserveAttribute() { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// <auto-generated/>
#pragma warning disable
#nullable enable annotations

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;

namespace System.Runtime.CompilerServices
{
/// <summary>
/// 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).
/// This attribute should not be used by developers in source code.
/// </summary>
[global::System.ComponentModel.EditorBrowsable(EditorBrowsableState.Never)]
[global::System.AttributeUsage(
global::System.AttributeTargets.Class |
global::System.AttributeTargets.Struct |
global::System.AttributeTargets.Enum |
global::System.AttributeTargets.Method |
global::System.AttributeTargets.Property |
global::System.AttributeTargets.Field |
global::System.AttributeTargets.Event |
global::System.AttributeTargets.Interface |
global::System.AttributeTargets.Delegate,
Inherited = false)]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::Microsoft.CodeAnalysis.Embedded]
internal sealed class ExtensionMarkerAttribute : global::System.Attribute
{
/// <summary>Initializes a new instance of the <see cref="global::System.Runtime.CompilerServices.ExtensionMarkerAttribute"/> class.</summary>
/// <param name="name">The name of the marker type this extension member is associated with.</param>
public ExtensionMarkerAttribute(string name)
=> Name = name;

/// <summary>The name of the marker type this extension member is associated with.</summary>
public string Name { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public DynamicDependencyAttribute(global::System.Diagnostics.CodeAnalysis.Dynami
/// <summary>
/// Gets or sets the condition in which the dependency is applicable, e.g. "DEBUG".
/// </summary>
[global::System.Obsolete("This property is no longer supported.")]
[global::System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public string? Condition { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace System.Diagnostics.CodeAnalysis
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::Microsoft.CodeAnalysis.Embedded]
[global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
[global::System.Runtime.CompilerServices.CompilerLoweringPreserveAttribute]
internal sealed class DynamicallyAccessedMembersAttribute : global::System.Attribute
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// <auto-generated/>
#pragma warning disable
#nullable enable annotations

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Runtime.CompilerServices
{
/// <summary>
/// Provides access to an inaccessible type.
/// </summary>
[global::System.AttributeUsage(
global::System.AttributeTargets.Parameter |
global::System.AttributeTargets.ReturnValue,
AllowMultiple = false,
Inherited = false)]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::Microsoft.CodeAnalysis.Embedded]
[global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class UnsafeAccessorTypeAttribute : global::System.Attribute
{
/// <summary>
/// Instantiates an <see cref="UnsafeAccessorTypeAttribute"/> providing access to a type supplied by <paramref name="typeName"/>.
/// </summary>
/// <param name="typeName">A fully qualified or partially qualified type name.</param>
/// <remarks>
/// <paramref name="typeName"/> is expected to follow the same rules as if it were being
/// passed to <see name="global::System.Type.GetType(global::System.String)"/>. When unbound generics are involved they
/// should follow the IL syntax of referencing a type or method generic variables using
/// the syntax of <c>!N</c> or <c>!!N</c> respectively, where N is the zero-based index of the
/// generic parameters. The generic rules defined for <see cref="global::System.Diagnostics.CodeAnalysis.UnsafeAccessorAttribute"/>
/// apply to this attribute as well, meaning the arity and type of generic parameter must match
/// the target type.
///
/// This attribute only has behavior on parameters or return values of methods marked with <see cref="global::System.Diagnostics.CodeAnalysis.UnsafeAccessorAttribute"/>.
///
/// This attribute should only be applied to parameters or return types of methods that are
/// typed as follows:
///
/// <ul>
/// <li>References should be typed as <lang>object</lang>.</li>
/// <li>Byref arguments should be typed with <lang>in</lang>, <lang>ref</lang>, or <lang>out</lang> to <lang>object</lang>.</li>
/// <li>Unmanaged pointers should be typed as <lang>void*</lang>.</li>
/// <li>Byref arguments to reference types or arrays should be typed with <lang>in</lang>, <lang>ref</lang>, or <lang>out</lang> to <lang>object</lang>.</li>
/// <li>Byref arguments to unmanaged pointer types should be typed with <lang>in</lang>, <lang>ref</lang>, or <lang>out</lang> to <lang>void*</lang>.</li>
/// </ul>
///
/// Value types are not supported.
///
/// Due to lack of variance for byrefs, returns involving byrefs are not supported. This
/// specifically means that accessors for fields of inaccessible types are not supported.
/// </remarks>
public UnsafeAccessorTypeAttribute(string typeName)
{
TypeName = typeName;
}

/// <summary>
/// Fully qualified or partially qualified type name to target.
/// </summary>
public string TypeName { get; }
}
}