-
Notifications
You must be signed in to change notification settings - Fork 499
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
metadata Reader::attribute_args
enhancements
#2329
Conversation
Reader::attribute args
enhancementsReader::attribute_args
enhancements
Don't believe metadata is using these attributes. Are you by any chance using ILSpy? (It automatically/annoyingly loads in unrelated .NET reference assemblies.) |
No, just the metadata reader. A simplified example: let files = metadata::reader::File::with_default(&[]).unwrap();
let reader = &metadata::reader::Reader::new(&files);
let tree = reader.tree("Windows", &[]).unwrap();
for tree in tree.flatten() {
for ty in reader.namespace_types(tree.namespace) {
for attr in reader.type_def_attributes(ty) {
let name = reader.attribute_name(attr);
if name == "UnmanagedFunctionPointerAttribute" {
reader.attribute_args(attr);
}
}
}
} Panics with the message:
|
I think I'm having a moment. Are you saying the reader is pulling in default metadata with references to |
I mean, they do appear to exist in the generated C# as well. E.g. https://github.com/microsoft/win32metadata/search?q=UnmanagedFunctionPointer |
If you need full reflection support, then you'll likely need to include metadata for system types. Generally, I avoid that as that's a dependency I don't want to be responsible to track down. 😊 |
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.
Looks good - thanks!
I've been playing with reading attribute metadata and wanted to help fix a couple of issues I encountered:
ComVisibleAttribute
has a bool argument, so it's useful to be able to read it. I also added a panic if the blob bool value is not either 0 or 1 (as per the spec). Admittedly this may be overkill but I figured it'd help detect if something has gone wrong somewhere.UnmanagedFunctionPointerAttribute
requiresSystem.Runtime.InteropServices.CallingConvention
andAttributeUsageAttribute
requiresSystem.AttributeTargets
. Neither of which are part of the default metadata files. I've added the type name to the panic message to make this easier to diagnose but I guess this is a win32metadata issue?