you can use
Marshal.SizeOf(typeof(T));
Be very aware that this will cause all kinds of unexpected results if you abuse it.
Perhaps you could limit your limit to the generic Types method, which would make sense to you, i.e. int , long , ect
Also be careful with such things Marshal.SizeoOf(typeof(char)) == 1.
Update
As MickD posted in his comments (and not surprisingly), compiler master Eric Lippert made a blog post at some smaller points
What is the difference? sizeof and Marshal.SizeOf
Update
Also, as MickD pointed out, and to make it clear that any young Jedi reading this Marshal.SizeOf returns an unmanaged size.
Method (Type) Marshal .SizeOf
Returns the size of the unmanaged type in bytes.
The returned size is the size of the unmanaged type. Unmanaged and controllable dimensions of an object may vary. For character types, size depends on the CharSet value applied to this class.
source share