Search for string in class structure populated from XML import, how?

Question

I am importing an XML file into a class structure(?) in C# Visual Studio. The structure classes looks like this.

[Serializable, XmlRoot("YamahaAmplifier")]
public class YamahaAmplifier
{
    [XmlElement(ElementName = "Root")]
    public List<Root> Roots = new List<Root>();
}

[Serializable()]
public class Root
{
    [XmlElement("RootName")]
    public string RootName = "";
    [XmlElement("UseRoot")]
    public string UseRoot = "";
    [XmlElement("Device")]
    public List<Device> Devices = new List<Device>();
}

[Serializable()]
public class Device
{
    [XmlElement("DeviceName")]
    public string DeviceName = "";
    [XmlElement("UseFunction")]
    public string UseFunction = "";
    [XmlElement("GETCMD")]
    public string GETCMD = "";
    [XmlElement("PUTCMD")]
    public string PUTCMD = "";
    [XmlElement("Parameter")]
    public List<Parameter> Parameters = new List<Parameter>();
}

[Serializable()]
public class Parameter
{
    [XmlElement("Number")]
    public int Number = 0;
    [XmlElement("Type")]
    public string Type = "";
    [XmlElement("Name")]
    public string Name = "";
    [XmlElement("MinVal")]
    public string MinVal = "";
    [XmlElement("MaxVal")]
    public string MaxVal = "";
}

From the parameters imported I create buttons and sliders to corresponding to function the XML decribe. When pressing I button or sliding a slider I can make the program transmitt the PUTCMD and added information from the Parameter list. The tranmission is done over TCP.

Now to the problem. One of the roots may have a device which has a PUTCMD that for example is "@SYS:MODELNAME". This piece of information is used both for sending the command and for comparison of incomming commands. So when I get a message over TCP which reads "@SYS:MODELNAME" I need to do a search in the class structure to find it so that I may manipulate its corresponding device and parameters. For instance with this example write the model name arriving with the message into a text box.

So that I get the indexes (i, j) of the exact device roots.Roots[i].Devices[j] is found.

Greatful for any assistance!


Show source
| class   | xml   | search   | struct   2016-12-25 22:12 0 Answers

Answers to Search for string in class structure populated from XML import, how? ( 0 )

Leave a reply to - Search for string in class structure populated from XML import, how?

◀ Go back