fifrelin70
Messages postés31Date d'inscriptionmercredi 17 octobre 2007StatutMembreDernière intervention16 mars 2009
-
29 janv. 2009 à 11:11
fifrelin70
Messages postés31Date d'inscriptionmercredi 17 octobre 2007StatutMembreDernière intervention16 mars 2009
-
30 janv. 2009 à 08:59
Bonjour à tous, je me lance dans la programmation orientée objet...
Je souhaiterais faire une classe statique càd non instanciable pour faire de ma classe une classe style passerelle.
Or Static n'existe pas en vb.net j'utilise donc shared.
Mais toutefois je voudrais que l'on me donne son avis sur ma synthaxe pour savoir si elle est cohérente d'un point de vue objet en m'expliquant ce que je n'aurais pas compris (Je compte présenter ce code à un PTI BTS). Je vous remercie d'avance voici le code:
Option Strict On
Option Explicit On
Imports System.Xml.linq
Public Class C_Xml 'Static n'existe pas
Private Shared _Path as String 'avec _Path le chemin du fichier xml
Private Shared _XmlDoc as XDocument
Shared Sub New()
_Path = Application.StartupPath & "\Filtre.xml"
End Sub
Public Shared Sub CreationXml()
_XmlDoc = _
<?xml version="1.0" encoding="utf-8"?>
<filtre>
</filtre>
End Sub
Public Shared Sub AjoutRepertoire(ByVal R as C_Repertoire)
Dim _XmlElement as XElement
_XmlElement = _XmlDoc.Element("filtre")
_XmlElement.Add(New XElement("repertoire", New XAttribute("niveau", R.get_Level), R.get_Path))
End Sub
Public Shared Sub EcritureXml()
_XmlDoc.Save(_Path)
End Sub
Public Shared Function LectureXml() as List(Of C_Repertoire)
Dim ListRep as New List(Of C_Repertoire)
_XmlDoc = XDocument.Load(_Path)
For Each X As XElement in _XmlDoc.Elements
If X.Name = "repertoire" Then
Dim R as New C_Repertoire(X.Value, Cint(X.Attribute("niveau")))
ListeRep.add(R)
End If
Next
Return ListRep
End Function
End Class
Ma question repose plus sur le Shared et les attributs Shared... Merci