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

Support generic fields in PersistedAssemblyBuilder #110372

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

Conversation

steveharter
Copy link
Member

Fixes #110247

cc @jgh07

We will likely port to v9.x once verified in v10 since this was new functionality in v9.

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no suggestions.

Comments skipped due to low confidence (1)

src/libraries/System.Reflection.Emit/tests/PersistedAssemblyBuilder/AssemblySaveTypeBuilderTests.cs:244

  • The constructor call should use Type.EmptyTypes for clarity and to avoid potential issues with different runtime environments.
il.Emit(OpCodes.Newobj, declaringType.GetConstructor([]));
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern", Justification = "Internal reflection implementation")]
static Type GetFieldType(FieldInfo fieldInfo)
{
if (fieldInfo.DeclaringType!.IsGenericType)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (fieldInfo.DeclaringType!.IsGenericType)
if (fieldInfo.DeclaringType!.IsConstructedGenericType)

Copy link
Contributor

@buyaa-n buyaa-n left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

memberHandle = AddMemberReference(field.Name, GetTypeHandle(declaringType),
MetadataSignatureHelper.GetFieldSignature(field.FieldType, field.GetRequiredCustomModifiers(), field.GetOptionalCustomModifiers(), this));
MetadataSignatureHelper.GetFieldSignature(GetFieldType(field), field.GetRequiredCustomModifiers(), field.GetOptionalCustomModifiers(), this));
Copy link
Member

Choose a reason for hiding this comment

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

Can this use GetOriginalMemberIfConstructedType like the method cases? GetOriginalMemberIfConstructedType seems to be doing the same thing as the newly added method.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

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

Successfully merging this pull request may close these issues.

PersistedAssemblyBuilder generates invalid IL when loading fields with generic type parameters
3 participants