Is there any Marshal method which instantiate a formatted ready-to-use object?
By "formatted" I mean a struct that have its layout formatted with attributes like StructLayout and MarshalAs.
Some code to clarification bellow.
public struct s1
{
public int i1;
public int i2;
}
public struct s2
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
public s1[] _s1;
}
What I want is to call some Marshal method that will actually return a ready-to-use formatted instance of s2. Some code again to help the understanding.
s2 temp = Marshal<s2>.CrateEmpty();
int i = temp._s1[2].i1;
I need this functionality to avoid creating in each of my structs a method to make this formatting stuff. In the code above, Marshal.CreateEmpty() should be able to instantiate s2._s1 as an array with 5 elements.
Any thoughts?
Thanks.