-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
UnsafeAccessor
and static classes
#90048
Comments
Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices Issue DetailsAs per #81741:
This requirement however makes Is there any way to specify the type there today? If not, could the api maybe be changed to take a
|
Alternatively, this could be an additional motivation for allowing static classes to be used as type parameters (part of dotnet/csharplang#5783). |
How would that relate to this? |
I was thinking that this was implemented with a generic parameter for the static class, my mistake. I misinterpreted it, sorry. I don't think allowing the first parameter to be a |
It would just be a property on the attribute. |
@AaronRobinsonMSFT Should we reconsider the design for StaticMethod and StaticField and specify the owning type via an optional Attribute argument instead of the dummy parameter? |
(The problem was mentioned in #81741 (comment), but I have missed it somehow.) |
Ah, I remember now after reading the whole discussion in #81741. The idea was to cover this case using |
Yes, that was the design. I don't think this is needed for the primary stakeholders for @jkotas Do you have an opinion here about .NET 8 or .NET 9? |
If there's a simple design you're confident in and you want it in for 8, we can make it happen. |
If we decide to do this for .NET 8 we would need the following done.
|
A straw man proposal for namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public sealed class UnsafeAccessorTypeAttribute : Attribute
{
public UnsafeAccessorTypeAttribute(Type target)
{
Target = target;
}
public Type Target { get; init; }
}
} We could also make this a generic attribute. |
The challenge with this design is that it would not extend to the type visibility skipping using
Nit: That would not work for the static classes. C# does not allow static classes to be used as generic type arguments.
I think what we have is good to .NET 8. We should open a tracking issue for the type visibility skipping using |
Yeah I'd say that this can wait for .Net 9, I'd rather see #89439 be prioritized first. |
Closing in lieu of #90081. |
As per #81741:
This requirement however makes
StaticMethod
andStaticField
impossible to use with static classes, since you can't have a parameter of their type.Is there any way to specify the type there today? If not, could the api maybe be changed to take a
typeof
in the attribute fields to allow specifying the type that way?The text was updated successfully, but these errors were encountered: