- Home /
Linq List to Gui
I'm trying to parse an ienumerable with Linq from an XML file in my Resources folder. The code (which I brought over from a .NET project) shows without errors except that the .DataContext method isn't available and I can't find a dll in Monodevelop for it (System.Data?). I only have the free version of Unity and am not sure what's supported. The XML would be read only, I don't have to write to it. What kind of GUI element takes a list in Unity? Or how do I display a collection from Linq in the GUI? The data is intelligent building data from architectural models. Here's my code:
public class GuiAlt2 : MonoBehaviour {
public TextAsset RFS;
public void OnGUI()
{
RFS = Resources.Load("RoomFinishSchedule.xml") as TextAsset;
if (RFS !=null)
{
XDocument XMLData = new XDocument(RFS.text);
var infoStrings = from RoomSchedule in XMLData.Descendants("Row")
select new Info
{
roomName = (string)RoomSchedule.Element("NAME"),
roomNumber = (string)RoomSchedule.Element("NUMBER")
};
foreach (Info room in infoStrings)
{
infoStrings.DataContext = room;
GUI.Label(Rect(0,0, 50, 100),room.roomName);
}
}
}
public class Info
{
public string roomName {get; set;}
public string roomNumber {get; set;}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612173007im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
LINQ, XML, putting XML nodes into an array 2 Answers
Displaying the players through GUI 1 Answer
UnityVS 1.8 possible bug with XML.Linq 1 Answer
Can not reference System.Xml.Linq 3 Answers
External mapping in Unity ? 1 Answer