Following up on my previous question. I am now trying to find a specific occurrence of an XML-part. For instance in the following XML (part)
<?xml version="1.0" encoding="utf-8" ?>
<definition date="2021-04-30" version="1.01">
<changes>
<change number="1" date="2021-04-30" description="Added .." />
<change number="2" date="2021-04-30" description="Changes in .." />
<change number="3" date="2021-04-30" description="Fixed .." />
<change number="4" date="2021-05-11" description="Added " />
</changes>
<general>
<styles>
<style name="title">
<font name="Arial" size="12" bold="true"/>
</style>
<style name="general">
<font name="Courier new" size="10" bold="true" />
</style>
<style name="header">
<font name="Courier new" size="10" bold="false" />
</style>
</styles>
</general>
I would like to find change number 3. I'm using Dandraka XML-Utilities to make the XML an ExpandoObject. Which should allow me to get easily to specific values. For instance, working with the above I am able to get the Definition date and version like this:
Dim strXML As String
strXML = File.ReadAllText("C:\Tools\ReportDefinitions.xml")
Dim def As Object
def = XmlSlurper.ParseText(strXML)
Console.WriteLine(def.date)
Console.WriteLine(def.version)
I would like to use Linq on the list: def.changes.changeList. But simply:
def.changes.changeList.where(Function(c) c.number = "1").count()
Gives an error on the where part. Have searched here on SO but most examples are in C# and translating them to VB.net ends up in something that doesn't compile.
Suppose I have to Cast it but how?
var iet = def.changes.changeList;
var iets = (IEnumerable)def.changes.changeList;
var iets2 = iets.Cast<dynamic>();
var iets3 = iets2.FirstOrDefault(p => p.number == "3");
int iets4 = iets3.number;
Console.WriteLine(iets4);
Now in VB.Net I can do most of it like this:
Dim iet As Object = def.changes.changeList
Dim iets = CType(def.changes.changeList, IEnumerable)
But this line:
var iets2 = iets.Cast<dynamic>();
No idea how to transform that to VB.Net..
Thanks
dynamicis how you make C# let you do late binding. I think the equivalent in VB would just beCast(Of Object). Note thatIEnumerable.Cast(Of T)will give you anIEnumerable(Of T)from anIEnumerable.