-
Notifications
You must be signed in to change notification settings - Fork 5k
Add GetDeclaringType
to PropertyDefinition
and EventDefinition
.
#111646
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
Conversation
Note regarding the
|
Note regarding the
|
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.
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (4)
src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/TypeSystem/PropertyDefinition.cs:72
- The new method GetDeclaringType should be covered by tests to ensure its correctness.
public TypeDefinitionHandle GetDeclaringType()
src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/MetadataReader.cs:1370
- Ensure that the new method
GetDeclaringType
forPropertyDefinitionHandle
is covered by tests.
return PropertyMapTable.FindTypeContainingProperty(propertyDef.RowId, PropertyTable.NumberOfRows);
src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/MetadataReader.cs:1360
- Ensure that the new method
GetDeclaringType
forEventDefinitionHandle
is covered by tests.
return EventMapTable.FindTypeContainingEvent(eventDef.RowId, EventTable.NumberOfRows);
src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/TypeSystem/EventDefinition.cs:60
- The new method GetDeclaringType should be covered by tests to ensure it works as expected.
public TypeDefinitionHandle GetDeclaringType()
We have to return the value of the parent type column in the map table, not the row to the map table itself.
74a48f0
to
4779643
Compare
@dotnet/area-system-reflection-metadata this is ready for review. |
src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Internal/Tables.cs
Outdated
Show resolved
Hide resolved
foreach (var typeDefHandle in reader.TypeDefinitions) | ||
{ | ||
var typeDef = reader.GetTypeDefinition(typeDefHandle); | ||
foreach (var nestedTypeHandle in typeDef.GetNestedTypes()) |
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.
Can we add a sanity check here to make sure that these foreach statement actually loop through at least one? Like:
Assert.True(typeDef.GetNestedTypes().Length > 0);
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.
The test assembly actually dosen't have any nested types. I tried to add some but after recompiling it this assert failed.
Your suggested assert wouldn't currently work, because not all types have all kinds of members each.
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.
Added asserts that GetTypesWithEvents()
and GetTypesWithProperties()
are not empty, and commented out the asserts on the nested classes.
We assert that the test assembly has types with events and properties, and acknowledge that it does not have nested types.
foreach (var typeDefHandle in reader.TypeDefinitions) | ||
{ | ||
var typeDef = reader.GetTypeDefinition(typeDefHandle); | ||
// The assembly does not declare any nested types yet. |
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.
Would it be better to add some nested types to this assembly instead?
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.
Added a test.
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.
LGTM
@MichalStrehovsky Do you know on top your head where there any places in the AOT compilers that can use these APIs? If yes, we should create an issue to adopt these APIs once they make it into the tools runtime refence assemblies. |
src/libraries/System.Reflection.Metadata/tests/Metadata/TypeSystem/TypeDefinitionTests.cs
Outdated
Show resolved
Hide resolved
This reverts commit 2013a59.
/ba-g unrelated timeout |
Thank you! |
Nothing comes to mind. We ran into lack of this API in the ILTrim hackathon. |
* main: (41 commits) Automated bump of chrome version (dotnet#112309) Add `GetDeclaringType` to `PropertyDefinition` and `EventDefinition`. (dotnet#111646) Update the System.ComponentModel.Annotations solution to build in VS (dotnet#112313) JIT: initial support for stack allocating arrays of GC type (dotnet#112250) [main] Update dependencies from dotnet/roslyn (dotnet#112260) Update Xcode casing (dotnet#112307) update the location of assert for REG_ZR check (dotnet#112294) Enable `SA1206`: Keyword ordering (dotnet#112303) Address feedback on dense FrozenDictionary optimization (dotnet#112298) Start regular pri-1 tests runs with native AOT (dotnet#111391) Observe exceptions from _connectionCloseTcs (dotnet#112190) Test failure - SendAsync_RequestVersion20_ResponseVersion20 (dotnet#112232) Fix init race in mono_class_try_get_[shortname]_class. (dotnet#112282) Remove repeated call to DllMain (dotnet#112285) Replace bitvector.h/cpp with ptrArgTP type in gc_unwind_x86.h/inl (dotnet#112268) JIT: Limit 3-opt to 1000 swaps per run (dotnet#112259) [main] Update dependencies from dotnet/icu, dotnet/runtime-assets (dotnet#112120) Update dependencies from https://github.com/dotnet/emsdk build 20250205.3 (dotnet#112223) Fix EventPipe on Android CoreClr. (dotnet#112270) Fix exception handling in the prestub worker (dotnet#111937) ...
Fixes #60380. Implementation follows the corresponding methods for method and field definitions, except that the binary search is performed on rows of the
PropertyMap
andEventMap
tables for properties and fields respectively, and we don't account for rows with no properties/events.