-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add overload resolution priority #49
Comments
Good point. We should also slap on |
If you want I can contribute these changes. |
That would be great! |
Does |
It can be polyfilled by adding an attribute in the project. Something like this: namespace System.Runtime.CompilerServices;
/// <summary>
/// Specifies the priority of a member in overload resolution. When unspecified, the default priority is 0.
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
internal sealed class OverloadResolutionPriorityAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="OverloadResolutionPriorityAttribute"/> class.
/// </summary>
/// <param name="priority">The priority of the attributed member. Higher numbers are prioritized, lower numbers are deprioritized. 0 is the default if no attribute is present.</param>
public OverloadResolutionPriorityAttribute(int priority)
{
Priority = priority;
}
/// <summary>
/// The priority of the member.
/// </summary>
public int Priority { get; }
} However, So I was thinking of adding a preprocessor condition for these where needed. Alternatively, you could drop support for netstandard, but not sure if you want that. |
Preprocessor condition sounds like the way to go. I bet PolySharp can provide the attribute; feel free to add it if it does. EDIT: Looks like PolySharp provides the other two as well, so a preprocessor directive wouldn't be required. |
…quiresunref-code-attrs Add RequiresUnreferencedCode attribute for reflection code and add OverloadResolutionPriority attribute to prefer non-object methods
It is way too easy to hit the signature for the extension
Format(string pattern, object data)
, since aDictionary
is also anobject
.I suggest that
[OverloadResolutionPriority(-1)]
is added to give it less priority.Additionally, I would warn users that it does reflection in the code behind, which is not compatible with platforms such as net-ios and net-android if you want to use NativeAOT.
The text was updated successfully, but these errors were encountered: