Add support for static generic methods as bodies for struct functions (#353)

* Add support for static generic methods as callbacks for struct functions.

* Add comment clarifying intent and effectiveness of using MethodHandle.Value in the name of the generated dynamic type.

---------

Co-authored-by: Cristian Levcovici <crisl@microsoft.com>
This commit is contained in:
Cristian Levcovici (MSFT) 2024-04-11 10:44:12 -07:00 коммит произвёл GitHub
Родитель 4c8247bad6
Коммит af7b884ccf
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 15 добавлений и 1 удалений

Просмотреть файл

@ -110,7 +110,21 @@ namespace Microsoft.Performance.SDK.Processing
var resultType = methodToCall.ReturnType;
var type = moduleBuilder.DefineType(
methodToCall.DeclaringType.FullName + "$." + methodToCall.Name,
//
// Notes:
//
// 1. `MethodInfo.MethodHandle.Value` is used in the name of the generated type as a unique identifier
// to avoid type name collisions.
//
// `MethofInfo.DelaringType.FullName` and `MethofInfo.DelaringType.Name` are used there only for
// easy attribution purposes and could, in principle, be removed. The exact `methodToCall` is
// available in the code of the `get_Item` method of the generated dynamic type.
//
// 2. The `MethodInfo.MethodHandle.Value` cannot be reused while this generated type is still loaded
// because `methodToCall` is referenced directly in the IL code of the `get_Item` method of the
// generated dynamic type.
//
$"{methodToCall.DeclaringType.FullName}$.{methodToCall.Name}$.{methodToCall.MethodHandle.Value.ToInt64():x16}",
TypeAttributes.Public,
typeof(ValueType),
new Type[]