Bonjour,
J'ai la structure suivante :
[CODE]
unsafe public struct TEST_STRUCT
{
public Int32 Attr1;
public fixed bool Attr2[3];
}
[/CODE]
Je veux parser cette structure via un FieldInfo et récupérer les types de variables et valeurs de chaque attribut...
Mon code :
[CODE]
unsafe
{
TEST_STRUCT test;
test.Attr1 = 0;
test.Attr2[0] = true;
test.Attr2[1] = false;
test.Attr2[2] = true;
foreach (FieldInfo info in typeof(TEST_STRUCT).GetFields())
{
object instanceCurrent = info.GetValue(test);
Console.WriteLine("{0,50}\t:\t{1,30}\t:\t{2,5}", info.Name, info.FieldType.FullName, info.GetValue(test));
object[] attr = info.GetCustomAttributes(typeof(System.Runtime.CompilerServices.FixedBufferAttribute), false);
if (attr.Length > 0)
{
System.Runtime.CompilerServices.FixedBufferAttribute bufattr = (System.Runtime.CompilerServices.FixedBufferAttribute)attr[0];
Console.WriteLine("Member '{0}' is a fixed buffer with {1} elements of {2}", info.Name, bufattr.Length, bufattr.ElementType);
}
}
}
[/CODE]
J'y arrive facilement sur un attribut de type bool : je récupère le FieldInfo suivant : {[U]Type :[/U] Int32, [U]Name :[/U] Attr1} et le getValue fonctionne...
Par contre pour un tableau, j'ai le souci suivant : je récupère le FieldInfo suivant : {[U]Type :[/U] <Attr2>e__FixedBuffer0, [U]Name :[/U] : Attr2}...
J'arrive à choper le type du tableau avec un GetCustomAttributes(...) mais je ne sais pas comment faire pour récupérer les valeurs de chaque indice du tableau. :cry:
Sauriez vous le faire ? ;)
Merci.
Pascal