Last active
July 7, 2023 14:43
-
-
Save smoogipoo/de8d9b967e30ddbae09adcd3c6ce7c8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics.CodeAnalysis; | |
using System.Runtime.InteropServices; | |
// Works if you uncomment this line. | |
Console.WriteLine(Marshal.OffsetOf(typeof(Struct), nameof(Struct.A))); | |
// Fails if the above line is commented. | |
method(typeof(Struct)); | |
return; | |
static void method([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type) | |
{ | |
Console.WriteLine(Marshal.OffsetOf(type, nameof(Struct.A))); | |
} | |
internal struct Struct | |
{ | |
public int A; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uncommented:
Commented: