I want to take value from name
node and fix
node using a lambda expression.
<Issue>
<name>asdasasdasd</name>
<fix>zxcczxczxczzxc </fix>
</Issue>
My try was
GlobalVariables.issuesList = doc.Descendants("Issue").Select(s => new IssueModel(s.Value, s.Value) { }).AsEnumerable();
Your question is far from clear, but I suspect you may want something like:
// I would strongly discourage you from using global variables...
var issues = doc.Descendants("Issue")
.Select(x => new IssueModel((string) x.Element("name"),
(string) x.Element("fix")))
.ToList();
The ToList()
call will force immediate evaluation of the query; without it, it would be reevaluated every time you iterate over issues
.
Note that if the name
or fix
element is missing from an Issue
, with the code above you'll get a null reference instead. You could instead use x.Element("name").Value
(and ditto for fix
) in which case you'll get an exception immediately if the element is missing.
See more on this question at Stackoverflow