Size of generic structure
I need to find out a size of a generic structure (I can not do it like sizeof(T) or using Marshal.SizeOf(...) 0> gives me an error) So I wrote: public static class HelperMethods { static HelperMethods() { SizeOfType = createSizeOfFunc(); } public static int SizeOf<T>() { return SizeOfType(typeof(T)); } public static readonly Func<Type, int> SizeOfType = null; private static Func<Type, int> createSizeOfFunc() { var dm = new DynamicMethod("SizeOfType", typeof(int), new Type[] { typeof(Type) }); ILGenerator il = dm.GetILGenerator(); il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Sizeof); //needs to be