C# and .Net 8 - Who Needs Reflection Anymore? Accessing private members without reflection
GOTO Community Day Chicago 2023

Tuesday Oct 24
15:15 –
16:00
Chicago (Wayman 2)

C# and .Net 8 - Who Needs Reflection Anymore? Accessing private members without reflection

.Net 8 is introducing a way to access non-public members without using reflection, implemented at build time! Essentially, it provides instructions to the compiler to ignore non-public attributes and allow access to the associated members through a specific mechanism. As it is a build time implementation, it is fast, almost as fast as accessing public entities. It also fully supports native AOT.

If you’re like me, you find that you often want to extend a framework/library and often this requires accessing non-public methods, properties and fields. This new feature allows us to do this in a more managed and performant way.

Microsoft have not gone out of their way to make the new feature well known. This Lightning Talk describes how it is done and compares the performance of accessing private members using this new technique and reflection.