Je le fichier XML suivantLINQ Pour syntaxe XML et des objets de classe dans vb.net
<Test>
<Modules>
<Module Name= "Test1">
<QueueName Name="Test1Active1" Active="True"></QueueName>
<QueueName Name="Test1Active2" Active="True"></QueueName>
<QueueName Name="Test1Active3" Active="True"></QueueName>
<QueueName Name="Test1Active4" Active="True"></QueueName>
<QueueName Name="Test1Inactive1" Active="False"></QueueName>
<QueueName Name="Test1Inactive2" Active="False"></QueueName>
<QueueName Name="Test1Inactive3" Active="False"></QueueName>
<QueueName Name="Test1Inactive4" Active="False"></QueueName>
<OtherSettings TimePause="20" TimeElasped="25" NumberOfThreads="5">
<Connection tag="Test1Test1" Connection="TestCon1"></Connection>
<Connection tag="Test1Test2" Connection="TestCon2"></Connection>
<Url Tag="Test1Test1" Connection="TestUrl"></Url>
<Url Tag="Test1Test2" Connection="TestUrl1"></Url>
</OtherSettings>
</Module>
<Module Name= "Test2">
<QueueName Name="Test2Active1" Active="True"></QueueName>
<QueueName Name="Test2Active2" Active="True"></QueueName>
<QueueName Name="Test2Active3" Active="True"></QueueName>
<QueueName Name="Test2Active4" Active="True"></QueueName>
<QueueName Name="Test2Inactive1" Active="False"></QueueName>
<QueueName Name="Test2Inactive2" Active="False"></QueueName>
<QueueName Name="Test2Inactive3" Active="False"></QueueName>
<QueueName Name="Test2Inactive4" Active="False"></QueueName>
<OtherSettings>
<Connection Tag="Test2Test1" Connection="TestCon1"></Connection>
<Connection Tag="Test2Test2" Connection="TestCon2"></Connection>
<Url Tag="Test2Test1" Connection="TestUrl"></Url>
<Url Tag="Test2Test2" Connection="TestUrl1"></Url>
</OtherSettings>
</Module>
</Modules>
</Test>
j'ai essayé de suis en train de remplir les classes de ce
Partial Public Class Modules
Private _moduleName As String
Private _queueName As IEnumerable(Of QueueName)
Private _otherSetting As OtherSetting
Public Sub New()
End Sub
<DebuggerBrowsable(DebuggerBrowsableState.Never)> _
Public Property ModuleName() As String
Get
Return _moduleName
End Get
Set(ByVal value As String)
_moduleName = value
End Set
End Property
<DebuggerBrowsable(DebuggerBrowsableState.Never)> _
Public Property QueueName() As IEnumerable(Of QueueName)
Get
Return _queueName
End Get
Set(ByVal value As IEnumerable(Of QueueName))
_queueName = value
End Set
End Property
<DebuggerBrowsable(DebuggerBrowsableState.Never)> _
Public Property OtherSetting() As OtherSetting
Get
Return _otherSetting
End Get
Set(ByVal value As OtherSetting)
_otherSetting = value
End Set
End Property
End Class
Ces travaux
Friend Function GetDataModules() As List(Of Modules)
Dim xdoc As XDocument = OpenXml()
Dim modules = (From q In xdoc...<Modules>.<Module> _
Select New Modules With { _
.ModuleName = [email protected] _
}).ToList
Return modules
End Function
Friend Function GetDataQueueNames(ByVal ModuleName As String, ByVal isActive As Boolean) As List(Of QueueName)
Dim xdoc As XDocument = OpenXml()
Dim active = (From q In xdoc...<Modules>.<Module> _
Where [email protected] = ModuleName _
From l In q.<QueueName> _
Where Convert.ToBoolean([email protected]) = isActive _
Select New QueueName With { _
.Name = [email protected], _
.Active = Convert.ToBoolean([email protected]) _
}).ToList
Return active
End Function
Ceci ne fonctionne pas
Protected Function GetAllData() As List(Of Modules)
Dim xdoc As XDocument = OpenXml()
Dim All = From m In xdoc...<Module>.<Module> _
Select New Modules With { _
.ModuleName = [email protected] _
}, _
.QueueName = From q In m...<QueueName> _
Select New QueueName With { _
.Name = [email protected], _
.Active = Convert.ToBoolean([email protected]) _
}, _
.OtherSetting = From o In m...<OtherSettings> _
Select New OtherSetting() With { _
.TimeElasped = Convert.ToInt32([email protected]), _
.TimePause = Convert.ToInt32([email protected]), _
.NumberOfThreads = Convert.ToInt32([email protected]) _
}, _
.Connection = From c In m...<Connection> _
Select New Connection With { _
.ConnectionString = [email protected], _
.Tag = [email protected] _
}, _
.URL = From u In m...<Url> _
Select New URL() With { _
.Tag = [email protected], _
.URL = [email protected] _
}.tolist
End Function
Pourriez-vous s'il vous plaît aider
Est-ce qu'il lance une exception quelconque ou ne recevez-vous pas les résultats comme prévu? –
Je ne peux pas obtenir la syntaxe écrire avec les crochets pour le mettre à tolist –