I'm having one or more classes that contains only declarations of primitives and primitives initialized arrays
i.e:
class PrimitivesStruc ture
{
public int32 integer1;
public char[] array1 = new char[20];
public int[] array2 = new int[10];
...
}
How can I found, dianmically, from another class, the length in bytes of declared primitives arrays?
For primitive fields it's simple:
PrimitivesStruc ture myObject = new PrimitivesStruc ture();
foreach (System.Reflect ion.FieldInfo fi in myObject.GetTyp e().GetFields() )
{
if (!fi.FieldType. IsArray)
Console.WriteLi ne(System.Runti me.InteropServi ces.Marshal.Siz eOf(Activator.. CreateInstance( fi.FieldType))) ;
}
--
Horatiu Ripa
i.e:
class PrimitivesStruc ture
{
public int32 integer1;
public char[] array1 = new char[20];
public int[] array2 = new int[10];
...
}
How can I found, dianmically, from another class, the length in bytes of declared primitives arrays?
For primitive fields it's simple:
PrimitivesStruc ture myObject = new PrimitivesStruc ture();
foreach (System.Reflect ion.FieldInfo fi in myObject.GetTyp e().GetFields() )
{
if (!fi.FieldType. IsArray)
Console.WriteLi ne(System.Runti me.InteropServi ces.Marshal.Siz eOf(Activator.. CreateInstance( fi.FieldType))) ;
}
--
Horatiu Ripa
Comment