lundi 15 août 2016

Reflection nested struct getvalue non-static variable

i have a struct like below

public struct FixtureHandShake
{
    public Handshake WaitPlace;
    public Handshake WaitPick;
    public Handshake DonePlacement;
    public bool LoadUnloadAvailable;
    public bool PlacementAvailable;
}

public struct Handshake
{
    public bool done;
    public bool request;
}

public static FixtureHandShake LeftFeeder;

I want to use reflection to get the all value of "LeftFeeder" with a timer and regularly update it to a listview. I'm able to get the value of "LoadUnloadAvailable" and "placementAvailable", but when comes to the "WaitPlace", "WaitPick" and "DonePlacement", i only able to get Main.Handshake. Below is the code i applied.

//I'm able to get the "LeftFeeder" object 
object _ObjPassIn = info.GetValue(null);

FieldInfo[] _MyInfo = LeftFeeder.GetType().GetFields();
for (int i = 0; i < _MyInfo.Length; i++)    
{                       
    //Insert into List View
    object _tmp = _MyInfo[i].GetValue(_ObjPassIn);
    string[] row = { _MyInfo[i].Name, _tmp.ToString() };
    ListViewItem lv = new ListViewItem(row);
    //For regularly update
    lv.SubItems[0].Tag = _ObjPassIn;
    lv.Tag = _selectedTypeInfo[i];
    lvItem.Items.Add(lv);
} 

Can somebody please help me with my problem? to overcome my problem, i think i need an object of "WaitPlace", "WaitPick", "DonePlacement", but i am not able to get the object,

object _tmp = _MyInfo[i].GetValue(null);

Any suggestion or help will be appreciate. If you need more information for my problem, please kindly let me know. Thanks





Aucun commentaire:

Enregistrer un commentaire