Skip to content
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 GetDeclaringType to PropertyDefinition and EventDefinition. #111646

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

teo-tsirpanis
Copy link
Contributor

Fixes #60380. Implementation follows the corresponding methods for method and field definitions, except that the binary search is performed on rows of the PropertyMap and EventMap tables for properties and fields respectively.

Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jan 21, 2025
@teo-tsirpanis teo-tsirpanis requested a review from Copilot January 21, 2025 00:53

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 for PropertyDefinitionHandle 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 for EventDefinitionHandle 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()
@teo-tsirpanis teo-tsirpanis marked this pull request as ready for review January 25, 2025 21:06
We have to return the value of the parent type column in the map table, not the row to the map table itself.
@teo-tsirpanis
Copy link
Contributor Author

@dotnet/area-system-reflection-metadata this is ready for review.

Comment on lines +1408 to +1425
int value = this.GetPropertyListStartFor(row);
if (value == propertyRowId)
{
while (row < numOfRows)
{
int newRow = row + 1;
value = this.GetPropertyListStartFor(newRow);
if (value == propertyRowId)
{
row = newRow;
}
else
{
break;
}
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this is needed for property map table. Unlike typedef table that this code was copied from, the property map should not have rows for types with no properties.

Dtto for event map

foreach (var typeDefHandle in reader.TypeDefinitions)
{
var typeDef = reader.GetTypeDefinition(typeDefHandle);
foreach (var nestedTypeHandle in typeDef.GetNestedTypes())
Copy link
Member

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add GetDeclaringType to PropertyDefinition and EventDefinition
3 participants