B
bill
All,
I have the following:
......
[StructLayout(LayoutKind.Sequential)]
unsafe public struct Example
{
public double we;
public double mu;
public fixed double A1[9 ];
public fixed double A2[9 ];
}
Example ex;
......
I am using reflection to discover the contents of various unmanaged
structures. The one above is just a part of a larger unmanaged
structure. In any case lets suppose an instance of the containing
structure, objBig, has been passed into the code below and that it
contains the structure "Example ex". As I loop through Field members of
objBig and when Member.Name == "Ex" -
......
Object objInside = T.InvokeMember(Member.Name,
BindingFlags.GetField, null, objBig, null);
FieldInfo[] fio = objInside .GetType().GetFields();
foreach (FieldInfo fo in fio)
{
Console.WriteLine("Object name, value is {0}, {1}",
fo.Name, fo.GetValue(o));
}
......
the following is output:
Object name, value is we, 5678
Object name, value is mu, 1234
Object name, value is A1,
ANSNavigationU+Inputs+NavILoads+<A1>e__FixedBuffer1f
Object name, value is A2,
ANSNavigationU+Inputs+NavILoads+<A2>e__FixedBuffer20
I cannot figure out how to "get the value" of the 9 array elements in
either A1 or A2. I also need ot be able to "set the value" of the array
elements. I think the way to set the value of a scalar in the above
example would be like this:
Object[] objNew = new object[] { 4321};
myType.InvokeMember("mu",
BindingFlags.DeclaredOnly | BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.Static |
BindingFlags.SetField, null, objInside, objNew );
Also, when I inspect the "objInside" with the debugger I can see
exactly what is in the structure for all values whether they be scalars
or arrays or further nested structures. I would have thought it would
be a lot easier the read/write the structure programmatically.
Any help greatly appreciated,
Bill
I have the following:
......
[StructLayout(LayoutKind.Sequential)]
unsafe public struct Example
{
public double we;
public double mu;
public fixed double A1[9 ];
public fixed double A2[9 ];
}
Example ex;
......
I am using reflection to discover the contents of various unmanaged
structures. The one above is just a part of a larger unmanaged
structure. In any case lets suppose an instance of the containing
structure, objBig, has been passed into the code below and that it
contains the structure "Example ex". As I loop through Field members of
objBig and when Member.Name == "Ex" -
......
Object objInside = T.InvokeMember(Member.Name,
BindingFlags.GetField, null, objBig, null);
FieldInfo[] fio = objInside .GetType().GetFields();
foreach (FieldInfo fo in fio)
{
Console.WriteLine("Object name, value is {0}, {1}",
fo.Name, fo.GetValue(o));
}
......
the following is output:
Object name, value is we, 5678
Object name, value is mu, 1234
Object name, value is A1,
ANSNavigationU+Inputs+NavILoads+<A1>e__FixedBuffer1f
Object name, value is A2,
ANSNavigationU+Inputs+NavILoads+<A2>e__FixedBuffer20
I cannot figure out how to "get the value" of the 9 array elements in
either A1 or A2. I also need ot be able to "set the value" of the array
elements. I think the way to set the value of a scalar in the above
example would be like this:
Object[] objNew = new object[] { 4321};
myType.InvokeMember("mu",
BindingFlags.DeclaredOnly | BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.Instance | BindingFlags.Static |
BindingFlags.SetField, null, objInside, objNew );
Also, when I inspect the "objInside" with the debugger I can see
exactly what is in the structure for all values whether they be scalars
or arrays or further nested structures. I would have thought it would
be a lot easier the read/write the structure programmatically.
Any help greatly appreciated,
Bill