Skip to content

Instantly share code, notes, and snippets.

@Scooletz
Created April 23, 2015 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Scooletz/9b78bd52451f76ba0eea to your computer and use it in GitHub Desktop.
Save Scooletz/9b78bd52451f76ba0eea to your computer and use it in GitHub Desktop.
nullable alignment
public class TestX
{
[Test]
public void T()
{
Inspect(typeof(int));
Inspect(typeof(long));
Inspect(typeof(bool));
Inspect(typeof(Guid));
}
private static void Inspect(Type t)
{
var type = typeof (Nullable<>).MakeGenericType(t);
Console.WriteLine(type.FullName.Replace(", mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "") + ":");
Console.WriteLine(Marshal.OffsetOf(type, "hasValue"));
Console.WriteLine(Marshal.OffsetOf(type, "value"));
Console.WriteLine(typeof (Marshal).InvokeMember("SizeOfHelper",
BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Static, null, null,
new object[] {type, true}));
Console.WriteLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment