H
Horatiu Ripa
I'm having one or more classes that contains only declarations of primitives and primitives initialized arrays
i.e:
class PrimitivesStructure
{
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:
PrimitivesStructure myObject = new PrimitivesStructure();
foreach (System.Reflection.FieldInfo fi in myObject.GetType().GetFields())
{
if (!fi.FieldType.IsArray)
Console.WriteLine(System.Runtime.InteropServices.Marshal.SizeOf(Activator..CreateInstance(fi.FieldType)));
}
i.e:
class PrimitivesStructure
{
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:
PrimitivesStructure myObject = new PrimitivesStructure();
foreach (System.Reflection.FieldInfo fi in myObject.GetType().GetFields())
{
if (!fi.FieldType.IsArray)
Console.WriteLine(System.Runtime.InteropServices.Marshal.SizeOf(Activator..CreateInstance(fi.FieldType)));
}