fix rewriting declaring type for a generic method (#711)

This commit is contained in:
Jesse Plamondon-Willard 2020-05-19 22:50:33 -04:00
parent 1838842bbc
commit b54d892abf
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
1 changed files with 7 additions and 1 deletions

View File

@ -122,7 +122,13 @@ namespace StardewModdingAPI.Framework.ModLoading.Framework
MethodReference methodRef = RewriteHelper.AsMethodReference(instruction);
if (methodRef != null)
{
rewritten |= this.RewriteTypeReference(methodRef.DeclaringType, newType => methodRef.DeclaringType = newType);
rewritten |= this.RewriteTypeReference(methodRef.DeclaringType, newType =>
{
// note: generic methods are wrapped into a MethodSpecification which doesn't allow changing the
// declaring type directly. For our purposes we want to change all generic versions of a matched
// method anyway, so we can use GetElementMethod to get the underlying method here.
methodRef.GetElementMethod().DeclaringType = newType;
});
rewritten |= this.RewriteTypeReference(methodRef.ReturnType, newType => methodRef.ReturnType = newType);
foreach (var parameter in methodRef.Parameters)