Tag: structure

通用结构的大小

我需要找出一个通用结构的大小(我不能像sizeof(T)或使用Marshal.SizeOf(…)0>给我一个错误) 所以我写道: public static class HelperMethods { static HelperMethods() { SizeOfType = createSizeOfFunc(); } public static int SizeOf() { return SizeOfType(typeof(T)); } public static readonly Func SizeOfType = null; private static Func 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 il.Emit(OpCodes.Sizeof, […]