'**************************************************
' FILE : BBCodeElementTypes.vb
' AUTHOR : Paulo Santos
' CREATION : 4/30/2009 10:16:36 PM
' COPYRIGHT : Copyright © 2009
' PJ on Development
' All Rights Reserved.
'
' Description:
' TODO: Add file description
'
' Change log:
' 0.1 4/30/2009 10:16:36 PM
' Paulo Santos
' Created.
'***************************************************
Imports System.Xml.Serialization
Imports System.Globalization
Imports System.Diagnostics.CodeAnalysis
'''
''' Represents a dictionary of types that implements a .
'''
_
_
Public NotInheritable Class BBCodeElementTypeDictionary
Inherits Dictionary(Of String, BBCodeElementTypeDefinition)
Implements IXmlSerializable
Private Const STR_ConfigurationItem As String = "element"
''' Initializes an instance of the class.
''' This is the default constructor for this class.
Friend Sub New()
End Sub
''' Initializes a new instance of the class with serialized data.
''' A object containing the information required to serialize the .
''' A structure containing the source and destination of the serialized stream associated with the .
Private Sub New(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext)
MyBase.New(info, context)
End Sub
'''
''' Adds the specified key and value to the dictionary.
'''
''' The key of the element to add.
''' The value of the element to add.
Private Shadows Sub Add(ByVal tagName As String, ByVal value As BBCodeElementTypeDefinition)
ValidateTagName(tagName)
ValidateBBCodeElementType(value.Type)
MyBase.Add(tagName.ToUpperInvariant(), value)
End Sub
'''
''' Adds the specified key and value to the dictionary.
'''
''' The key of the element to add.
''' The value of the element to add.
Public Shadows Sub Add(ByVal tagName As String, ByVal value As Type, ByVal requireClosingTag As Boolean)
Add(tagName.ToUpperInvariant(), New BBCodeElementTypeDefinition() With {.TagName = tagName, .Type = value, .RequireClosingTag = requireClosingTag})
End Sub
''' This method is reserved and should not be used. When implementing the IXmlSerializable interface, you should return null (Nothing in Visual Basic) from this method, and instead, if specifying a custom schema is required, apply the to the class.
''' An that describes the XML representation of the object that is produced by the method and consumed by the method.
Public Function GetSchema() As System.Xml.Schema.XmlSchema Implements System.Xml.Serialization.IXmlSerializable.GetSchema
Return Nothing
End Function
''' Generates an object from its XML representation.
''' The stream from which the object is deserialized.
Public Sub ReadXml(ByVal reader As System.Xml.XmlReader) Implements System.Xml.Serialization.IXmlSerializable.ReadXml
'*
'* Check the name of the element
'*
If (reader.NamespaceURI <> STR_BBCodeSchemaNamespace) OrElse (reader.LocalName <> STR_BBCodeElementTypesXmlElement) Then
Exit Sub
End If
'*
'* Reads the items
'*
Do While (reader.Read() AndAlso reader.LocalName = STR_ConfigurationItem AndAlso reader.NamespaceURI = STR_BBCodeSchemaNamespace)
Dim definition As New BBCodeElementTypeDefinition()
With definition
.TagName = reader.GetAttribute("name")
Boolean.TryParse(reader.GetAttribute("requireClosingTag"), .RequireClosingTag)
.Type = System.Type.GetType(reader.GetAttribute("type"))
End With
If (definition.Type.IsSubclassOf(GetType(BBCodeElement))) Then
Me.Add(definition.TagName, definition)
End If
Loop
If (reader.NodeType = Xml.XmlNodeType.EndElement) Then
reader.Read()
End If
End Sub
''' Converts an object into its XML representation.
''' The stream to which the object is serialized.
_
Public Sub WriteXml(ByVal writer As System.Xml.XmlWriter) Implements System.Xml.Serialization.IXmlSerializable.WriteXml
For Each it In Me
writer.WriteStartElement(STR_ConfigurationItem, STR_BBCodeSchemaNamespace)
writer.WriteAttributeString("name", it.Key.ToLower(CultureInfo.InvariantCulture))
writer.WriteAttributeString("requireClosingTag", it.Value.RequireClosingTag.ToString())
writer.WriteAttributeString("type", it.Value.Type.AssemblyQualifiedName)
writer.WriteEndElement()
Next
End Sub
End Class