
Allan Thraen
7.4K posts

Allan Thraen
@athraen
Freelance Episerver Expert and .NET Architect, Partner in CodeArt










While reading Stephen Toub's article on .NET 8 performance, I noticed a very interesting feature introduced in .NET 8, that I never heard about: [UnsafeAccessor]. It allows you to get a reference to a private field or method of a target type while ignoring visibility checks. Because it returns a reference to the field, you can use it to read AND write a value to it. This is extremely useful for instance for the Datadog tracer, because we routinely need to access private fields from third-party libraries to instrument them. To do so, we emit IL at runtime, which has a significant impact on startup time. This new feature provides a zero-overhead alternative for us. github.com/dotnet/runtime… #dotnet










