Я пробую код из этой статьи .
public static void Test()
{
// Force the code in the finally to be eagerly prepared
RuntimeHelpers.PrepareConstrainedRegions();
try
{
Console.WriteLine("In try");
}
finally
{
// MyType's static constructor is implicitly called in here
MyType.Foo();
}
}
public class MyType
{
static MyType()
{
Console.WriteLine("MyType Constructor Called");
}
// This attribute is required for PrepareConstrainedRegions to work.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
public static void Foo() { }
}
Вывод. Net Framework:
MyType Constructor Called
In try
Вывод. Net Core 3.1:
In try
MyType Constructor Called
Как я понимаю. net ядро не поддерживает RuntimeHelpers.PrepareRegionMethod. Я хочу знать, какие методы класса RuntimeHelpers поддерживаются? И как я могу заставить код выше работать?