'------------------------------------------------------------------------------
'
' This code was generated by a tool.
' Runtime Version: 1.1.4322.573
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
'
'------------------------------------------------------------------------------
Option Strict Off
Option Explicit On
'The following code was generated automatically by use of the Object Model Generator.
'If you feel this tool has helped you in any way or there are bugs to notify me of,
'please let me know at ovanklot@gmx.net or http://weblogs.asp.net/OKloeten/.
'
'Omer van Kloeten
Namespace ObjectModelGenerator
'Represents the MyDataSet element.
Public Class MyDataSetElement
Inherits Object
Implements IXmlElement, System.ICloneable
'This field holds the collection of objects.
Private m_customerss As customersCollection
'This is the default constructor.
Public Sub New()
MyBase.New
Me.m_customerss = New customersCollection(Me)
End Sub
'This constructor is used to deserialize the element from XML DOM.
Friend Sub New(ByVal element As System.Xml.XmlElement)
MyBase.New
If (element.Name <> "MyDataSet") Then
Throw New System.ApplicationException("Invalid element initialization.")
End If
Me.m_customerss = New customersCollection(element, Me)
End Sub
'Gets the collection of objects.
Public ReadOnly Property customerss As customersCollection
Get
Return Me.m_customerss
End Get
End Property
'This method is used to serialize the element to XML DOM.
Function IXmlElement_GetXml(ByVal document As System.Xml.XmlDocument) As System.Xml.XmlElement Implements IXmlElement.GetXml
Dim element As System.Xml.XmlElement = document.CreateElement("MyDataSet")
Dim subElements() As System.Xml.XmlElement
subElements = CType(Me.customerss,IXmlElementCollection).GetXml(document)
Dim index As Integer = 0
Do While (index < subElements.Length)
element.AppendChild(subElements(index))
index = (index + 1)
Loop
Return element
End Function
'This method is used to to clone the element.
Public Function Clone() As Object
Dim clone As MyDataSetElement = New MyDataSetElement
clone.m_customerss = CType(Me.m_customerss.Clone,customersCollection)
clone.m_customerss.SetParentMyDataSetElement(Me)
Return clone
End Function
'Represents the customers element.
Public Class customersElement
Inherits Object
Implements IXmlElement, System.ICloneable
'This field is used to create the CustomerID attribute/simple element.
Private m_CustomerID As Decimal
'Holds the null status for the value type of the CustomerID attribute/simple element.
Private m_IsCustomerIDNull As Boolean
'This field is used to create the CompanyName attribute/simple element.
Private m_CompanyName As String
'This field is used to create the Phone attribute/simple element.
Private m_Phone As String
Private m_ParentMyDataSetElement As MyDataSetElement
'This is the default constructor.
Public Sub New()
MyBase.New
End Sub
'This constructor is used to deserialize the element from XML DOM.
Friend Sub New(ByVal element As System.Xml.XmlElement)
MyBase.New
If (element.Name <> "customers") Then
Throw New System.ApplicationException("Invalid element initialization.")
End If
If (Not (element("CustomerID")) Is Nothing) Then
Me.CustomerID = CType(System.Convert.ChangeType(element("CustomerID").Value, GetType(System.Decimal)),Decimal)
Else
Me.SetCustomerIDNull
End If
If (Not (element("CompanyName")) Is Nothing) Then
Me.CompanyName = CType(System.Convert.ChangeType(element("CompanyName").Value, GetType(System.String)),String)
End If
If (Not (element("Phone")) Is Nothing) Then
Me.Phone = CType(System.Convert.ChangeType(element("Phone").Value, GetType(System.String)),String)
End If
End Sub
'Represents the CustomerID attribute/simple element for this element.
Public Property CustomerID As Decimal
Get
Return Me.m_CustomerID
End Get
Set
Me.m_CustomerID = value
' After setting the value, it is no longer null.
Me.m_IsCustomerIDNull = false
End Set
End Property
'Gets whether the value type of the CustomerID attribute/simple element is null.
Public ReadOnly Property IsCustomerIDNull As Boolean
Get
Return Me.m_IsCustomerIDNull
End Get
End Property
'Represents the CompanyName attribute/simple element for this element.
Public Property CompanyName As String
Get
Return Me.m_CompanyName
End Get
Set
Me.m_CompanyName = value
End Set
End Property
'Represents the Phone attribute/simple element for this element.
Public Property Phone As String
Get
Return Me.m_Phone
End Get
Set
Me.m_Phone = value
End Set
End Property
'Gets the parent for this element.
Public ReadOnly Property ParentMyDataSetElement As MyDataSetElement
Get
Return Me.m_ParentMyDataSetElement
End Get
End Property
Public Event CustomerIDChanged As System.EventHandler
Public Event CompanyNameChanged As System.EventHandler
Public Event PhoneChanged As System.EventHandler
Protected Sub OnCustomerIDChanged(ByVal sender As Object, ByVal e As System.EventArgs)
If (Not (Me.CustomerIDChangedEvent) Is Nothing) Then
RaiseEvent CustomerIDChanged(sender, e)
End If
End Sub
'Sets the value type of the CustomerID attribute/simple element to null.
Public Sub SetCustomerIDNull()
Me.m_IsCustomerIDNull = true
End Sub
Protected Sub OnCompanyNameChanged(ByVal sender As Object, ByVal e As System.EventArgs)
If (Not (Me.CompanyNameChangedEvent) Is Nothing) Then
RaiseEvent CompanyNameChanged(sender, e)
End If
End Sub
Protected Sub OnPhoneChanged(ByVal sender As Object, ByVal e As System.EventArgs)
If (Not (Me.PhoneChangedEvent) Is Nothing) Then
RaiseEvent PhoneChanged(sender, e)
End If
End Sub
'This method is used to serialize the element to XML DOM.
Function IXmlElement_GetXml(ByVal document As System.Xml.XmlDocument) As System.Xml.XmlElement Implements IXmlElement.GetXml
Dim element As System.Xml.XmlElement = document.CreateElement("customers")
Dim subElements() As System.Xml.XmlElement
If (Me.IsCustomerIDNull = false) Then
Dim elmCustomerID As System.Xml.XmlElement = document.CreateElement("CustomerID")
elmCustomerID.Value = Me.CustomerID.ToString
element.AppendChild(elmCustomerID)
End If
If (Not (Me.CompanyName) Is Nothing) Then
Dim elmCompanyName As System.Xml.XmlElement = document.CreateElement("CompanyName")
elmCompanyName.Value = Me.CompanyName.ToString
element.AppendChild(elmCompanyName)
End If
If (Not (Me.Phone) Is Nothing) Then
Dim elmPhone As System.Xml.XmlElement = document.CreateElement("Phone")
elmPhone.Value = Me.Phone.ToString
element.AppendChild(elmPhone)
End If
Return element
End Function
'This method is used to to clone the element.
Public Function Clone() As Object
Dim clone As customersElement = New customersElement
If (Me.IsCustomerIDNull = false) Then
clone.m_CustomerID = Me.m_CustomerID
Else
clone.SetCustomerIDNull
End If
clone.m_CompanyName = Me.m_CompanyName
clone.m_Phone = Me.m_Phone
Return clone
End Function
'Sets a value for the parent for this element.
Protected Sub SetParentMyDataSetElement(ByVal value As MyDataSetElement)
Me.m_ParentMyDataSetElement = value
End Sub
End Class
'This is a typed collection for the customersCollection () element.
Public Class customersCollection
Inherits System.Collections.CollectionBase
Implements IXmlElementCollection, System.ICloneable
Private Const MinAmount As Integer = 1
Private m_Parent As MyDataSetElement
'Default internal constructor.
Friend Sub New(ByVal parent As MyDataSetElement)
MyBase.New
Me.m_Parent = parent
End Sub
'This constructor is used to deserialize the element collection from XML DOM.
Friend Sub New(ByVal parentElement As System.Xml.XmlElement, ByVal parent As MyDataSetElement)
MyBase.New
Me.m_Parent = parent
Dim index As Integer = 0
Do While (index < parentElement.ChildNodes.Count)
If ((parentElement.ChildNodes(index).GetType = GetType(System.Xml.XmlElement)) _
AndAlso (parentElement.ChildNodes(index).Name = "customers")) Then
MyBase.InnerList.Add(New customersElement(CType(parentElement.ChildNodes(index),System.Xml.XmlElement)))
End If
index = (index + 1)
Loop
End Sub
'Gets or sets the at the specific index.
Public Default Property Item(ByVal index As Integer) As customersElement
Get
Return CType(MyBase.InnerList(index),customersElement)
End Get
Set
MyBase.InnerList(index) = value
End Set
End Property
'Adds a to the end of the collection.
Public Function Add(ByVal value As customersElement) As Integer
value.SetParentMyDataSetElement(Me.m_Parent)
Return MyBase.InnerList.Add(value)
End Function
'Determines whether the object is in the collection.
Public Function Contains(ByVal value As customersElement) As Boolean
Return MyBase.InnerList.Contains(value)
End Function
'Returns the zero-based index of the first occurrence of the object in the collection.
Public Function IndexOf(ByVal value As customersElement) As Integer
Return MyBase.InnerList.IndexOf(value)
End Function
'Inserts an object of type into the collection at the specified index.
Public Sub Insert(ByVal index As Integer, ByVal value As customersElement)
value.SetParentMyDataSetElement(Me.m_Parent)
MyBase.InnerList.Insert(index, value)
End Sub
'Removes the first occurrence of a specific object from the collection.
Public Sub Remove(ByVal value As customersElement)
' Check to see if we have reached the minimum amount.
If (MyBase.InnerList.Count = MinAmount) Then
Throw New System.ApplicationException("Minimum amount of items reached.")
End If
value.SetParentMyDataSetElement(Nothing)
MyBase.InnerList.Remove(value)
End Sub
'Removes the at the specific index from the collection.
Public Shadows Sub RemoveAt(ByVal index As Integer)
' Check to see if we have reached the minimum amount.
If (MyBase.InnerList.Count = MinAmount) Then
Throw New System.ApplicationException("Minimum amount of items reached.")
End If
Me(index).SetParentMyDataSetElement(Nothing)
MyBase.InnerList.RemoveAt(index)
End Sub
'This method is used to serialize the element collection to XML DOM.
Function IXmlElementCollection_GetXml(ByVal document As System.Xml.XmlDocument) As System.Xml.XmlElement() Implements IXmlElementCollection.GetXml
If ((MyBase.InnerList.Count <> 0) _
AndAlso (MyBase.InnerList.Count < MinAmount)) Then
Throw New System.ApplicationException("Can not serialize element set since it does not comply with minimum / maximum amo"& _
"unts")
End If
Dim elements() As System.Xml.XmlElement = New System.Xml.XmlElement((MyBase.InnerList.Count) - 1) {}
Dim index As Integer = 0
Do While (index < MyBase.InnerList.Count)
elements(index) = CType(MyBase.InnerList(index),IXmlElement).GetXml(document)
index = (index + 1)
Loop
Return elements
End Function
'This method is used to to clone the collection.
Public Function Clone() As Object
Dim collection As customersCollection = New customersCollection(Nothing)
Dim index As Integer = 0
Do While (index < MyBase.InnerList.Count)
collection.Add(CType(CType(MyBase.InnerList(index),customersElement).Clone,customersElement))
index = (index + 1)
Loop
Return collection
End Function
'Sets a value for the parent for all elements in this collection.
Protected Sub SetParentMyDataSetElement(ByVal parent As MyDataSetElement)
Dim index As Integer = 0
Do While (index < MyBase.InnerList.Count)
CType(Me(index),customersElement).SetParentMyDataSetElement(parent)
index = (index + 1)
Loop
End Sub
Public Function GetByCustomerID(ByVal customerID As Decimal) As customersElement()
Dim list As System.Collections.ArrayList = New System.Collections.ArrayList
Dim index As Integer = 0
Do While (index < Me.Count)
If ((Me(index).IsCustomerIDNull <> false) _
AndAlso (Me(index).CustomerID = customerID)) Then
list.Add(Me(index))
End If
index = (index + 1)
Loop
Return CType(list.ToArray(GetType(customersElement)),customersElement())
End Function
Public Function GetByCustomerIDNull() As customersElement()
Dim list As System.Collections.ArrayList = New System.Collections.ArrayList
Dim index As Integer = 0
Do While (index < Me.Count)
If (Me(index).IsCustomerIDNull = true) Then
list.Add(Me(index))
End If
index = (index + 1)
Loop
Return CType(list.ToArray(GetType(customersElement)),customersElement())
End Function
Public Function GetByCompanyName(ByVal companyName As String) As customersElement()
Dim list As System.Collections.ArrayList = New System.Collections.ArrayList
Dim index As Integer = 0
Do While (index < Me.Count)
If (Me(index).CompanyName = companyName) Then
list.Add(Me(index))
End If
index = (index + 1)
Loop
Return CType(list.ToArray(GetType(customersElement)),customersElement())
End Function
Public Function GetByPhone(ByVal phone As String) As customersElement()
Dim list As System.Collections.ArrayList = New System.Collections.ArrayList
Dim index As Integer = 0
Do While (index < Me.Count)
If (Me(index).Phone = phone) Then
list.Add(Me(index))
End If
index = (index + 1)
Loop
Return CType(list.ToArray(GetType(customersElement)),customersElement())
End Function
End Class
End Class
'This class is used to load and store files that contain the MyDataSet hierarchy.
Public Class MyDataSetDocument
Inherits System.Xml.XmlDocument
'This field is used to store the schema for validation.
Private Shared m_Schema As System.Xml.Schema.XmlSchema = System.Xml.Schema.XmlSchema.Read(New System.IO.StringReader(""&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&""&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&" "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&" "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&" "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&" "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&" "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&" "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&" "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&" "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&" "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&" "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&" "& _
" "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&" "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&" "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&" "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&" "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&""), Nothing)
'This method is used for loading the MyDataSetDocument with data from the DOM.
Public Shared Function FromDOM(ByVal element As MyDataSetElement) As MyDataSetDocument
Dim document As MyDataSetDocument = New MyDataSetDocument
document.AppendChild(document.CreateXmlDeclaration("1.0", "utf-8", "yes"))
document.AppendChild(CType(element,IXmlElement).GetXml(document))
Dim xmlns As System.Xml.XmlAttribute = document.CreateAttribute("xmlns")
xmlns.Value = m_Schema.TargetNamespace
document("MyDataSet").Attributes.Append(xmlns)
Return document
End Function
'This method is used for loading the DOM into this MyDataSetDocument.
Public Function CreateDOM() As MyDataSetElement
Return New MyDataSetElement(Me("MyDataSet"))
End Function
'Loads the XML document from the specified and validates it against the schema.
'Note that if the namespace does not point to the schema, the document will not be validated.
Public Overloads Overrides Sub Load(ByVal reader As System.Xml.XmlReader)
Dim valReader As System.Xml.XmlValidatingReader
If (reader.GetType Is GetType(System.Xml.XmlValidatingReader)) Then
valReader = CType(reader,System.Xml.XmlValidatingReader)
Else
valReader = New System.Xml.XmlValidatingReader(reader)
End If
valReader.Schemas.Add(m_Schema)
valReader.ValidationType = System.Xml.ValidationType.Schema
MyBase.Load(reader)
End Sub
End Class
'This interface is used for serializing the DOM, for an element collection.
Public Interface IXmlElementCollection
'This method is used to serialize an element collection to XML DOM.
Function GetXml(ByVal document As System.Xml.XmlDocument) As System.Xml.XmlElement()
End Interface
'This interface is used for serializing the DOM, for a specific element.
Public Interface IXmlElement
'This method is used to serialize an element to XML DOM.
Function GetXml(ByVal document As System.Xml.XmlDocument) As System.Xml.XmlElement
End Interface
End Namespace