MesPresets = ( From f In xDoc.Descendants("Preset") Select New Presets With { .Name = f.Attribute("name")?.Value, .SpecialUse = f.Attribute("SpecialUse")?.Value, .Channels = (From s In f.Descendants("channels") Select New Channels With { .PresetValue = (From t In s.Descendants("PresetValue") Select New Channel With { .Fixture_id = t.Element("channel").Attribute("Fixture_Id")?.Value, .Attribute_Name = t.Element("Channel").Attribute("Attribute_Name")?.Value ))}).ToList()}).ToList()}).Tolist()
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionClass Fixture Public Property Nom As String'là c'est bien une string unique Public Property Type As String Public Property NomType As String Public Property LesSubFixtures As List(Of SubFixture)'là c'est une liste End Class
Class SubFixture Public Property PatchAdresse As Integer Public Property Position As Point3D Public Property Rotation As Point3D Public Property Echelle As Point3D End Class Class Point3D Public Property X As Double Public Property Y As Double Public Property Z As Double ''' <summary> ''' Cette méthode évite d'écrire 3fois la même chose dans la requete de désserialisation ''' </summary> ''' <param name="E"></param> ''' <returns></returns> Public Shared Function FromXML(ByVal E As XElement) As Point3D If E Is Nothing Then Return New Point3D() End If Return New Point3D With {.X = ToDouble(E.Attribute("x")?.Value), .Y = ToDouble(E.Attribute("y")?.Value), .Z = ToDouble(E.Attribute("z")?.Value)} End Function ''' <summary> ''' convertit en double peu importe le symbole décimal du PC et du texte ''' </summary> ''' <param name="Texte"></param> ''' <returns>Si ca ne marche pas retourne Not A Number</returns> Private Shared Function ToDouble(ByVal Texte As String) As Double Dim res As Double If Double.TryParse(Texte.Replace(","c, "."c), System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, res) Then Return res Else Return Double.NaN End If End Function End Class
Public Property test As String()
Class Presets Public Property Name As Integer Public Property SpecialUse As String Public Property Channels As List(Of Channels) End Class Class Channels Public Property PresetValue As List(Of PresetValue) End Class Class PresetValue Public Property Value As Double Public Property Embeded As List(Of Embeded) ' quand il y a le noeud HANDLE c'est qu'il y a une preset embeded Public Property Channel As List(Of Channel) End Class Class Embeded Public Property Name As Integer Public Property Numero As List(Of Numero) End Class Class Channel Public Property Fixture_id As Integer Public Property Attribute_Name As String End Class Class Numero Public Property Num1 As Integer Public Property Num2 As Integer Public Property Num3 As Integer End Class
MesPresets = ( From f In xDoc.Descendants("Preset") Select New Presets With { .Name = f.Attribute("name")?.Value, .SpecialUse = f.Attribute("SpecialUse")?.Value, .Channels = (From s In f.Descendants("channels") Select New Channels With { .PresetValue = (From t In s.Descendants("PresetValue") Select New Channel With { .Fixture_id = t.Element("channel").Attribute("Fixture_Id")?.Value, .Attribute_Name = t.Element("Channel").Attribute("Attribute_Name")?.Value ))}).ToList()}).ToList()}).Tolist()
Dim MesPresets As List(Of Presets) = ('la parenthèse fermante associée est au même niveau From f In xDoc.Descendants("Preset") Select New Presets With {'idem pour cette accolade .Name = f.Attribute("name")?.Value, .SpecialUse = f.Attribute("SpecialUse")?.Value, .Channels = (From s In f.Descendants("channels") Select New Channels With { .PresetValue = (From t In s.Descendants("PresetValue") Select New Channel With { .Fixture_id = t.Element("channel").Attribute("Fixture_Id")?.Value, .Attribute_Name = t.Element("Channel").Attribute("Attribute_Name")?.Value } ).ToList() } ).Tolist() } ).ToList()
J'ai une autre question : est ce que ça ne pose pas de problème qu'une Property d'une class ai le même nom qu'une classe?
Class PresetPools Public Property Presets As Les_Presets Public Property Index As Integer End Class Class Les_Presets Public Property Index As Integer Public Property Name As String Public Property SpecialUse As String Public Property Channels As List(Of Les_Channels) End Class Class Les_Channels Public Property PresetValue As List(Of Les_PresetValue) End Class Class Les_PresetValue Public Property Value As Double Public Property Embeded As List(Of Les_Embeded) ' quand il y a le noeud HANDLE c'est qu'il y a une preset embeded Public Property Channel As List(Of Les_Channel) End Class Class Les_Embeded Public Property Name As String Public Property Numero As List(Of Les_Numero) End Class Class Les_Channel Public Property Fixture_id As Integer Public Property Attribute_Name As String End Class Class Les_Numero Public Property Num1 As Integer Public Property Num2 As Integer Public Property Num3 As Integer End Class
Dim MesPresetPool2 As List(Of PresetPools) = ('la parenthèse fermante associée est au même niveau From k In xDoc.Descendants("PresetPools") Select New PresetPools With { .Index = k.Attribute("index")?.Value, .Presets = (From l In k.Descendants("PresetPool") Select New Les_Presets With { .Index = l.Attribute("index")?.Value, .Name = l.Attribute("name")?.Value, .SpecialUse = l.Attribute("SpecialUse")?.Value, .Channels = (From m In l.Descendants("Channels") Select New Les_Channels With { .PresetValue = (From n In m.Descendants("PresetValue") Select New Les_PresetValue With { .Value = n.Attribute("Value")?.Value, .Embeded = (From p In n.Descendants("Handle") Select New Les_Embeded With { .Name = p.Attribute("name")?.Value, .Numero = (From q In p.Descendants("No") Select New Les_Numero With { .Num1 = q.Element("No")?.Value' A MODIFIER POUR LES NUM DES PRESETS EMBEDED } ).ToList(), } ).tolist(), .Channel = (From t In n.Descendants("Channel") Select New Les_Channel With { .Fixture_id = t.Element("channel").Attribute("Fixture_Id")?.Value, .Attribute_Name = t.Element("Channel").Attribute("Attribute_Name")?.Value } ).ToList() } ).tolist() } ).tolist() } ).tolist() } ).tolist()
J'ai suivi tes conseils et modifié les noms des class
Public Property Channel As List(Of Les_Channel)
Public Property LesChannels As List(Of Channel) 'LesChanels est une liste qui contiendra des instances de Channel
Dim p as New Personne with { .Nom = "Sors", 'je vais encore initier le prénom est la date, il y a une virgule .Prenom = "Jean", .DateNaissance = "01/01/2000" ' pas d'autre propriété à initier -> pas de virgule }
Select New Channel With { .Fixture_id = CInt(t.Element("channel").Attribute("fixture_Id")?.Value), .Attribute_Name = t.Element("Channel").Attribute("attribute_Name")?.Value }
System.NullReferenceException : 'La référence d'objet n'est pas définie à une instance d'un objet.'
System.Xml.Linq.XContainer.Element(...) retournée Nothing.
Element("channel")une fois avec « c » et une fois avec « C »
Module Module_extensions <Extension()> Function Mon_todouble(ByVal texte As String) As Double Dim res As Double If texte <> Nothing Then If Double.TryParse(texte.Replace(",", "."), System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, res) Then Return res Else Return Double.NaN End If End If End Function End Module
If texte <> Nothing Then If Double.TryParse(texte.Replace(",", "."), System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, res) Then Return res End If End If Return Double.NaN
If texte <> Nothing AndAlso Double.TryParse(texte.Replace(",", "."), System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, res) Then Return res End If Return Double.NaN
<Preset index="1" name="ch4 HOME"> <Values> <Channels> <PresetValue> <Handle name="warp niches 0.1"> <No>1</No> <No>0</No> <No>1</No> </Handle> <Channel fixture_id="4" channel_id="4" attribute_name="FIXTUREGLOBALRESET" /> </PresetValue> <PresetValue> <Handle name="warp niches 0.1"> <No>1</No> <No>0</No> <No>1</No> </Handle> <Channel fixture_id="4" channel_id="4" attribute_name="PAN" /> </PresetValue> </Channels> </Value> <Preset>
Dim texte = "<Preset index=""1"" name=""ch4 HOME""> <Values> <Channels> <PresetValue> <Handle name=""warp niches 0.1""> <No>1</No> <No>0</No> <No>1</No> </Handle> <Channel fixture_id=""4"" channel_id=""4"" attribute_name=""FIXTUREGLOBALRESET"" /> </PresetValue> <PresetValue> <Handle name=""warp niches 0.1""> <No>3</No> <No>2</No> <No>1</No> </Handle> <Channel fixture_id=""4"" channel_id=""4"" attribute_name=""PAN"" /> </PresetValue> </Channels> </Values> </Preset>" Dim lesPresetsJoints As List(Of String) = (From h In XDocument.Parse(texte).Descendants("Handle") Let lesPresets = ( From p In h.Descendants("No") Select p.Value ) Select String.Join(";", lesPresets) ).ToList()
Dim lesPresetsJoints As List(Of String) = (From h In XDocument.Parse(texte).Descendants("Handle") Select String.Join(";", From p In h.Descendants("No") Select p.Value ) ).ToList()
System.InvalidCastException : 'Impossible d'effectuer un cast d'un objet de type 'WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String]' en type 'System.String'.'
MesPresetPool = ( From k In xDoc.Descendants("PresetPool") Select New PresetPool With { .Index = Mon_ToInteger(k.Attribute("index")?.Value), .Les_Presets = (From l In xDoc.Descendants("Preset") Select New Presets With { .Index = Mon_ToInteger(l.Attribute("index")?.Value), .Name = l.Attribute("name")?.Value, .SpecialUse = l.Attribute("SpecialUse")?.Value, .Les_values = (From m In l.Descendants("Values") Select New Values With { .Les_Channels = (From v In m.Descendants("Channels") Select New Channels With { .Les_PresetValue = (From n In v.Descendants("PresetValue") Select New PresetValue With { .Value = Mon_todouble(n.Attribute("Value")?.Value), .Embeded_Name = n?.Element("Handle")?.Attribute("name")?.Value, .Embeded_Num = (From p In n?.Descendants("Handle") Select String.Join(";", From u In p.Descendants("No") Select p?.Value ) ), .Fixture = Mon_ToInteger(n.Element("Channel")?.Attribute("fixture_id")?.Value), .Attribute_name = n.Element("Channel")?.Attribute("attribute_name")?.Value } ).ToList() } ).ToList() } ).ToList() } ).ToList() } ).ToList()
.Embeded_Num = (From p In n?.Descendants("Handle") Select String.Join(";", From u In p.Descendants("No") Select p?.Value )
.Embeded_Num = (String.Join(";", From u In n?.Descendants("No") Select u?.Value )
.Index = l.Attribute("index")?.Value.Mon_ToInteger(),
dans notre exemple :C’est dans le fichier complet?
la preset avec l'index 5 a les valeurs de la preset 1dans le PresetPool 4.
donc la valeur 32.499603 pour l'attribute_name "COLORRGB1" du fixture_id 10