-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Developers using Reflection should be able to use pointers and function pointers #44327
Comments
What about |
Any common use case that is not supported is being considered. @BreyerW can you share an example so this is properly captured here? Thanks |
@steveharter im not expert on reflection but i remember having trouble with ref return methods when generating dynamic methods it simply fails (dont remember exact exception since its year ago by now). Although theres workaround by defining entire assembly then generating ref return method inside that assembly but it isnt easy to discover i myself found that solution on accident in stackoverflow thread. Ref prop probably has similar issue since its method behind the scene. Also frontline reflection API (or in other words most easily discoverable API) like Last gripe is in |
@steveharter not anymore due to this bug i simply moved away from However i would consider it a bug in |
If I see this S.L.E issue discusses it in more detail. It should also be basing it on whether the return type is a reference or byref type. Similar logic would be needed for parameter (not just return value). For example the code below outputs:
internal class Program
{
private static void Main(string[] args)
{
CanModify(typeof(MyClass).GetProperty("RefInt")!);
CanModify(typeof(MyClass).GetProperty("RefType")!);
CanModify(typeof(MyClass).GetProperty("Int")!);
static void CanModify(PropertyInfo info)
{
// Sample logic; not complete since they don't check if value type is readonly via [IsReadOnlyAttribute]
bool canModify = info.CanWrite || !info.PropertyType.IsValueType || info.PropertyType.IsByRef;
Console.WriteLine($"{info.Name} CanModify: {canModify}");
}
}
}
public class MyClass
{
private int _refInt;
public ref int RefInt => ref _refInt;
public MyClass RefType => this;
public int Int { get; set; }
} |
@steveharter i see too bad but makes sense |
Moving to 7.0; many of the features require language support while others were not funded. |
Note the "fast invoke" and "ref struct" feature was moved to it's own user story at #45152. |
cc @tannergooding in case of interest, since it came up this morning. |
Closing for 8.0 since the remaining functionality is now tracked by #75358 |
Treatment of pointers in general is hit-and-miss especially with the newer function pointer (
delegate*
) feature.Currently with function pointers, an
IntPtr
orfnptr*
types are returned, so it is not possible today to distinguish between function pointers and other uses ofIntPtr
, for example. It is also not possible to determine the parameter types, return type or the calling convention.The text was updated successfully, but these errors were encountered: