@Apoc Not meaning to necro-bump, but I was having a problem with finding whether a struct has the StructLayoutAttribute using
Code:
type.GetCustomAttributes(typeof(StructLayoutAttribute), true)
and I remembered that your WhiteMagic library used that as well. So I tested it quickly with yours, using a small dummy struct with the StructLayout(LayoutKind.Sequential) attribute, and it always errors as well (relevant WhiteMagic code below). Any idea why GetCustomAttributes might ignore StructLayoutAttribute?
Code:
public T ReadStruct<T>(IntPtr address) where T : struct
{
if (!Utilities.HasAttrib<StructLayoutAttribute>(typeof(T)))
throw new MissingAttributeException("StructLayoutAttribute is missing.");
return (T) Marshal.PtrToStructure(address, typeof (T));
}
internal static bool HasAttrib<T>(Type item)
{
return item.GetCustomAttributes(typeof (T), true).Length != 0;
}