From: Richard B. <rb...@us...> - 2004-12-10 04:31:25
|
Update of /cvsroot/jcframework/FrameworkMapper/CodeSmithDataClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5004/CodeSmithDataClasses Added Files: AssemblyInfo.vb Association.vb AssociationEntry.vb AttributeMap.vb ClassMap.vb ClassMapTypeConverter.vb CodeSmithDataClasses.vbproj DatabaseColumn.vb DatabaseMap.vb DatabaseTable.vb DatabaseTypeConverter.vb InheritedBusinessClass(VB).cst XMLMapping.cst test.vb Log Message: Major update to incorporate CodeSmith scripts, and integration with WinMerge for viewing differences. --- NEW FILE: AssemblyInfo.vb --- Imports System Imports System.Reflection Imports System.Runtime.InteropServices ' General Information about an assembly is controlled through the following ' set of attributes. Change these attribute values to modify the information ' associated with an assembly. ' Review the values of the assembly attributes <Assembly: AssemblyTitle("")> <Assembly: AssemblyDescription("")> <Assembly: AssemblyCompany("")> <Assembly: AssemblyProduct("")> <Assembly: AssemblyCopyright("")> <Assembly: AssemblyTrademark("")> <Assembly: CLSCompliant(True)> 'The following GUID is for the ID of the typelib if this project is exposed to COM <Assembly: Guid("BADE80C6-587B-435F-AFA1-91555400E247")> ' Version information for an assembly consists of the following four values: ' ' Major Version ' Minor Version ' Build Number ' Revision ' ' You can specify all the values or you can default the Build and Revision Numbers ' by using the '*' as shown below: <Assembly: AssemblyVersion("1.0.*")> --- NEW FILE: Association.vb --- Public Class Association Public fromClass As String Public toClass As String Public name As String Public target As String Public cardinality As Integer Public deleteAuto As Boolean = False Public saveAuto As Boolean = False Public retrieveAuto As Boolean = False Public lazyLoad As Boolean = False Public fromNamespace As String Public toNamespace As String Public entries As AssociationEntryCollection End Class Public Class AssociationCollection Inherits CollectionBase Public Sub Add(ByVal a As Association) list.Add(a) End Sub Public Sub Remove(ByVal index As Integer) If index > Count - 1 Or index < 0 Then Throw New Exception("index value is outside of bounds") End If list.RemoveAt(index) End Sub Public Sub Remove(ByVal value As Association) list.Remove(value) End Sub Default Public ReadOnly Property Item(ByVal index As Integer) As Association Get Return CType(list.Item(index), Association) End Get End Property Default Public ReadOnly Property Item(ByVal _name As String) As Association Get For Each ma As Association In Me If ma.name = _name Then Return ma End If Next End Get End Property End Class --- NEW FILE: CodeSmithDataClasses.vbproj --- <VisualStudioProject> <VisualBasic ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{FB3D28DB-55C0-4068-A9F3-23412147768C}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "CodeSmithDataClasses" AssemblyOriginatorKeyFile = "" AssemblyOriginatorKeyMode = "None" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" OptionCompare = "Binary" OptionExplicit = "On" OptionStrict = "Off" RootNamespace = "CodeSmithDataClasses" StartupObject = "" > <Config Name = "Debug" BaseAddress = "285212672" ConfigurationOverrideFile = "" DefineConstants = "" DefineDebug = "true" DefineTrace = "true" DebugSymbols = "true" IncrementalBuild = "true" Optimize = "false" OutputPath = "bin\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" /> <Config Name = "Release" BaseAddress = "285212672" ConfigurationOverrideFile = "" DefineConstants = "" DefineDebug = "false" DefineTrace = "true" DebugSymbols = "false" IncrementalBuild = "false" Optimize = "true" OutputPath = "bin\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" /> <Reference Name = "System.Data" AssemblyName = "System.Data" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" /> </References> <Imports> <Import Namespace = "Microsoft.VisualBasic" /> <Import Namespace = "System" /> <Import Namespace = "System.Collections" /> <Import Namespace = "System.Data" /> <Import Namespace = "System.Diagnostics" /> </Imports> </Build> <Files> <Include> <File RelPath = "AssemblyInfo.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Association.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "AssociationEntry.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "AttributeMap.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "ClassMap.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "ClassMapTypeConverter.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "DatabaseColumn.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "DatabaseMap.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "DatabaseTable.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "DatabaseTypeConverter.vb" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </VisualBasic> </VisualStudioProject> --- NEW FILE: AttributeMap.vb --- Public Class AttributeMap Public Name As String Public column As String Public isKey As Boolean = False Public isProxy As Boolean = True Public isFind As Boolean = False Public isIdentity As Boolean = False Public isTimeStamp As Boolean = False Public referenceToParentField As String Public dataType As String End Class Public Class AttributeCollection Inherits CollectionBase Public Sub Add(ByVal a As AttributeMap) list.Add(a) End Sub Public Sub Remove(ByVal index As Integer) If index > Count - 1 Or index < 0 Then Throw New Exception("index value is outside of bounds") End If list.RemoveAt(index) End Sub Public Sub Remove(ByVal value As AttributeMap) list.Remove(value) End Sub Default Public ReadOnly Property Item(ByVal index As Integer) As AttributeMap Get Return CType(list.Item(index), AttributeMap) End Get End Property Default Public ReadOnly Property Item(ByVal _name As String) As AttributeMap Get For Each ma As AttributeMap In Me If ma.Name = _name Then Return ma End If Next End Get End Property End Class --- NEW FILE: AssociationEntry.vb --- Public Class AssociationEntry Public fromAttribute As String Public toAttribute As String Public parentAssociation As String End Class Public Class AssociationEntryCollection Inherits CollectionBase Public Sub Add(ByVal a As AssociationEntry) list.Add(a) End Sub Public Sub Remove(ByVal index As Integer) If index > Count - 1 Or index < 0 Then Throw New Exception("index value is outside of bounds") End If list.RemoveAt(index) End Sub Public Sub Remove(ByVal value As AssociationEntry) list.Remove(value) End Sub Default Public ReadOnly Property Item(ByVal index As Integer) As AssociationEntry Get Return CType(list.Item(index), AssociationEntry) End Get End Property Default Public ReadOnly Property Item(ByVal _name As String) As AssociationEntry Get For Each ma As AssociationEntry In Me If ma.fromAttribute = _name Then Return ma End If Next End Get End Property End Class --- NEW FILE: XMLMapping.cst --- <%@ CodeTemplate Language="VB" TargetLanguage="XML" Description="Generates an XML Mapping file the AToMSFramework." %> <%@ Import Namespace="System.Collections" %> <%@ Assembly Name="CodeSmithDataClasses" %> <%@ Import Namespace="CodeSmithDataClasses" %> <%@ Import Namespace="System.Text" %> <%@ Property Name="databases" Type="DatabaseCollection" Category="Context"%> <%@ Property Name="classes" Type="ClassMapCollection" Category="Context"%> <% dim cls as ClassMap %> <map> <% for each db as DatabaseMap in databases %> <database name="<%= db.dbname %>" class="<%= db.DbType %>"> <parameter name="name" value="<%= db.nameparam %>" /> <parameter name="serverName" value="<%= db.servername %>" /> <parameter name="user" value="<%= db.user %>" /> <parameter name="password" value="<%= db.password %>" /> </database> <% next %> <% for each cls in classes %> <%= GenerateClassHeader(cls) %> <% for each att as AttributeMap in cls.Attributes %> <%= GenerateAttribute(att) %> <% next att %> </class> <% next cls %> <% for each cls in classes if not cls.associations is nothing then for each ass as Association in cls.associations %> <%= GenerateAssociationHeader(ass) %> <% for each entry as associationentry in ass.entries %> <entry fromAttribute="<%= entry.fromattribute %>" toAttribute="<%= entry.toattribute %>"/> <% next entry %> </association> <% next ass end if next cls %> </map> <script runat="template"> public overrides function GetFileName() as string return "output.xml" end function public function GenerateClassHeader(c as ClassMap) as string dim lineBuilder as StringBuilder = new StringBuilder() linebuilder.append(" <class") linebuilder.append(" name=""" & c.classname & """") linebuilder.append(" table=""" & c.table & """") if c.tableowner <> string.empty then linebuilder.append(" owner=""" & c.tableowner & """") end if linebuilder.append(" database = """ & c.databasename & """") if c.superclassname <> string.empty then linebuilder.append(" superclass=""" & c.superclassname & """") if c.superclassnamespace <> string.empty then linebuilder.append(" superclassnamespace=""" & c.superclassnamespace & """") end if end if if c.readonlyflag then linebuilder.append(" readonly=""true""") end if if c.modifyonlyflag then linebuilder.append(" modifyonly=""true""") end if if c.sharedfield <> string.empty then linebuilder.append(" sharedtablefield= """ & c.sharedfield & """") linebuilder.append(" sharedtablevalued= """ & c.sharedvalue & """") end if if c.classnamespace <> string.empty then linebuilder.append(" namespace=""" & c.classnamespace & """") end if if c.assemblypath <> string.empty then linebuilder.append(" assemblypath=""" & c.assemblypath & """") end if if c.factory <> string.empty then linebuilder.append(" factory=""" & c.factory & """") end if linebuilder.append(">") return lineBuilder.ToString() end function public function GenerateAttribute(a as AttributeMap) as string dim lineBuilder as StringBuilder = new StringBuilder() linebuilder.append(" <attribute") linebuilder.append(" name=""" & a.name & """") if a.column <> string.empty then linebuilder.append(" column=""" & a.column & """") end if if a.isfind then linebuilder.append(" find=""true""") end if if a.iskey then linebuilder.append(" key=""primary""") end if if not a.isproxy then linebuilder.append(" proxy=""false""") end if if a.istimestamp then linebuilder.append(" timestamp=""true""") end if if a.isidentity then linebuilder.append(" identity=""true""") end if if a.referenceToParentField <> string.empty then linebuilder.append(" reference=""" & a.referenceToParentField & """") end if linebuilder.append(" />") return lineBuilder.ToString() end function public function GenerateAssociationHeader(a as Association) as string dim lineBuilder as StringBuilder = new StringBuilder() linebuilder.append(" <association") linebuilder.append(" fromClass=""" & a.fromclass & """") linebuilder.append(" toClass=""" & a.toclass & """") linebuilder.append(" target=""" & a.target & """") if a.cardinality = 0 then linebuilder.append(" cardinality=""OneToOne""") else linebuilder.append(" cardinality=""OneToMany""") end if if a.name <> string.empty then linebuilder.append(" name=""" & a.name & """") end if if a.fromNamespace <> string.empty then linebuilder.append(" fromClassNameSpace=""" & a.fromNamespace & """") end if if a.toNamespace <> string.empty then linebuilder.append(" toClassNameSpace=""" & a.toNamespace & """") end if linebuilder.append(vbcrlf) if a.retrieveAuto then if a.lazyload then linebuilder.append(" retrieveAutomatic=""lazy""") else linebuilder.append(" retrieveAutomatic=""true""") end if else linebuilder.append(" retrieveAutomatic=""false""") end if linebuilder.append(vbcrlf) if a.saveauto then linebuilder.append(" saveAutomatic=""true""") else linebuilder.append(" saveAutomatic=""false""") end if linebuilder.append(vbcrlf) if a.deleteauto then linebuilder.append(" deleteAutomatic=""true""") else linebuilder.append(" deleteAutomatic=""false""") end if linebuilder.append(">") return lineBuilder.ToString() end function </script> --- NEW FILE: ClassMap.vb --- Imports System.ComponentModel Public Class ClassMap Public ClassName As String Public SourceFile As String Public attributes As New AttributeCollection Public associations As New AssociationCollection Public databaseName As String Public superClassName As String Public superClassNameSpace As String Public table As String Public tableOwner As String Public readOnlyFlag As Boolean = False Public modifyOnlyFlag As Boolean = False Public sharedField As String Public sharedValue As String Public classNamespace As String Public assemblyPath As String Public factory As String End Class <TypeConverter(GetType(ClassMapTypeConverter))> _ Public Class ClassMapCollection Inherits CollectionBase Public Sub Add(ByVal a As ClassMap) list.Add(a) End Sub Public Sub Remove(ByVal index As Integer) If index > Count - 1 Or index < 0 Then Throw New Exception("index value is outside of bounds") End If list.RemoveAt(index) End Sub Public Sub Remove(ByVal value As ClassMap) list.Remove(value) End Sub Default Public ReadOnly Property Item(ByVal index As Integer) As ClassMap Get Return CType(list.Item(index), ClassMap) End Get End Property Default Public ReadOnly Property Item(ByVal _name As String) As ClassMap Get For Each ma As ClassMap In Me If ma.ClassName = _name Then Return ma End If Next End Get End Property End Class --- NEW FILE: DatabaseColumn.vb --- <Serializable()> Public Class DatabaseColumn Public colName As String Public colType As String Public dotnetTypeName As String Public parentTableName As String Public isPrimaryKey As Boolean End Class Public Class DatabaseColumnCollection Inherits CollectionBase Public Sub Add(ByVal a As DatabaseColumn) list.Add(a) End Sub Public Sub Remove(ByVal index As Integer) If index > Count - 1 Or index < 0 Then Throw New Exception("index value is outside of bounds") End If list.RemoveAt(index) End Sub Public Sub Remove(ByVal value As DatabaseColumn) list.Remove(value) End Sub Default Public ReadOnly Property Item(ByVal index As Integer) As DatabaseColumn Get Return CType(list.Item(index), DatabaseColumn) End Get End Property Default Public ReadOnly Property Item(ByVal _name As String) As DatabaseColumn Get For Each c As DatabaseColumn In Me If c.colName = _name Then Return c End If Next End Get End Property End Class --- NEW FILE: test.vb --- Option Strict Off Option Explicit On Imports System Imports AToMSFramework Public Class Batches Inherits CPersistentObject #region "Generated Code" Private _BatchCode As String Public Overridable Property BatchCode() As String Get Return _BatchCode End Get Set(ByVal Value As String) If _BatchCode <> Value Then _BatchCode = Value SetDirtyFlag() End If End Set End Property Private _Reference As String Public Overridable Property Reference() As String Get Return _Reference End Get Set(ByVal Value As String) If _Reference <> Value Then _Reference = Value SetDirtyFlag() End If End Set End Property Private _StyleCode As String Public Overridable Property StyleCode() As String Get Return _StyleCode End Get Set(ByVal Value As String) If _StyleCode <> Value Then _StyleCode = Value SetDirtyFlag() End If End Set End Property Private _RqdMtrs As Integer Public Overridable Property RqdMtrs() As Integer Get Return _RqdMtrs End Get Set(ByVal Value As Integer) If _RqdMtrs <> Value Then _RqdMtrs = Value SetDirtyFlag() End If End Set End Property Private _RqdKlgs As Integer Public Overridable Property RqdKlgs() As Integer Get Return _RqdKlgs End Get Set(ByVal Value As Integer) If _RqdKlgs <> Value Then _RqdKlgs = Value SetDirtyFlag() End If End Set End Property Private _RqdRolls As Integer Public Overridable Property RqdRolls() As Integer Get Return _RqdRolls End Get Set(ByVal Value As Integer) If _RqdRolls <> Value Then _RqdRolls = Value SetDirtyFlag() End If End Set End Property Private _DoffedMtrs As Integer Public Overridable Property DoffedMtrs() As Integer Get Return _DoffedMtrs End Get Set(ByVal Value As Integer) If _DoffedMtrs <> Value Then _DoffedMtrs = Value SetDirtyFlag() End If End Set End Property Private _DoffedKgs As Integer Public Overridable Property DoffedKgs() As Integer Get Return _DoffedKgs End Get Set(ByVal Value As Integer) If _DoffedKgs <> Value Then _DoffedKgs = Value SetDirtyFlag() End If End Set End Property Private _DoffedRolls As Integer Public Overridable Property DoffedRolls() As Integer Get Return _DoffedRolls End Get Set(ByVal Value As Integer) If _DoffedRolls <> Value Then _DoffedRolls = Value SetDirtyFlag() End If End Set End Property Private _DateStarted As DateTime Public Overridable Property DateStarted() As DateTime Get Return _DateStarted End Get Set(ByVal Value As DateTime) If _DateStarted <> Value Then _DateStarted = Value SetDirtyFlag() End If End Set End Property Private _DateCompleted As DateTime Public Overridable Property DateCompleted() As DateTime Get Return _DateCompleted End Get Set(ByVal Value As DateTime) If _DateCompleted <> Value Then _DateCompleted = Value SetDirtyFlag() End If End Set End Property Private _WorkInProgress As Boolean Public Overridable Property WorkInProgress() As Boolean Get Return _WorkInProgress End Get Set(ByVal Value As Boolean) If _WorkInProgress <> Value Then _WorkInProgress = Value SetDirtyFlag() End If End Set End Property Private _EditedBy As String Public Overridable Property EditedBy() As String Get Return _EditedBy End Get Set(ByVal Value As String) If _EditedBy <> Value Then _EditedBy = Value SetDirtyFlag() End If End Set End Property Private _Created As DateTime Public Overridable Property Created() As DateTime Get Return _Created End Get Set(ByVal Value As DateTime) If _Created <> Value Then _Created = Value SetDirtyFlag() End If End Set End Property Private _Modified As DateTime Public Overridable Property Modified() As DateTime Get Return _Modified End Get Set(ByVal Value As DateTime) If _Modified <> Value Then _Modified = Value SetDirtyFlag() End If End Set End Property Private _Times As BatchTime Public Overridable Property Times() As BatchTime Get Return _Times End Get Set(ByVal Value As BatchTime) If _Times <> Value Then _Times = Value SetDirtyFlag() End If End Set End Property Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject Return New Batches End Function Public Overrides Function IsValid() As Boolean Return True End Function #end region #region "Non-Generated Code" #end region End Class --- NEW FILE: InheritedBusinessClass(VB).cst --- <%@ CodeTemplate Language="VB" TargetLanguage="XML" Description="Generates a business class definition based on the XML Mapping file the AToMSFramework." %> <%@ Assembly Name="CodeSmithDataClasses" %> <%@ Import Namespace="CodeSmithDataClasses" %> <%@ Property Name="classes" Type="ClassMapCollection" Category="Context"%> <% dim intPrefix as string = "_" dim intName as string dim amap as AttributeMap dim cmap as ClassMap cmap = classes.item(0) %> Option Strict Off Option Explicit On Imports System Imports AToMSFramework <% if cmap.classnamespace <> string.empty then %>Namespace <%= cmap.classnamespace %><% end if %> Public Class <%= cmap.ClassName %> Inherits CPersistentObject #region "Generated Private Variables" <% for each amap in cmap.Attributes intName = intPrefix & amap.name if amap.column <> string.empty andalso amap.istimestamp = false then %> Private <%= intname%> As <%= amap.datatype %> <% end if next %> #end region #region "Generated Properties" <% for each amap in cmap.Attributes intName = intPrefix & amap.name if amap.column <> string.empty andalso amap.istimestamp = false then %> Public Overridable Property <%=amap.name %>() As <%= GetVBDataType(amap.datatype) %> Get Return <%= intname %> End Get Set(ByVal Value As <%= amap.datatype %>) If <%= intname %> <> Value Then <%= intname %> = Value SetDirtyFlag() End If End Set End Property <% end if next dim objType as string for each assoc as Association in cmap.associations if assoc.tonamespace <> string.empty then objtype = assoc.tonamespace & "." & assoc.toclass else objtype = assoc.toclass end if intName = intPrefix & assoc.target %> Private <%= intname%> As <%= objType %> Public Overridable Property <%=assoc.target %>() As <%= objtype %> Get Return <%= intname %> End Get Set(ByVal Value As <%= objtype %>) If <%= intname %> <> Value Then <%= intname %> = Value SetDirtyFlag() End If End Set End Property <% next %> Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject Return New <%= cmap.classname %> End Function Public Overrides Function IsValid() As Boolean Return True End Function #end region #region "Non-Generated Code" #end region End Class <% if cmap.classnamespace <> string.empty then %>End Namespace<% end if %> <script runat="template"> ' This function is here as a reference when making other templates that need to change data types public function GetVBDataType(dataType as string) as string Select Case dataType Case "long" return "Long" Case "Object", "Boolean", "String", "DateTime", "Decimal", "Double", "Byte()", "Integer", "Single", "Short", "Byte", "Guid" return dataType end select end function </script> --- NEW FILE: DatabaseMap.vb --- Imports System.ComponentModel <Serializable()> _ Public Class DatabaseMap Public dbname As String Public dbType As String Public serverName As String Public user As String Public password As String Public OIDTable As String Public portNumber As String Public options As String Public NameParam As String Public tables As DatabaseTableCollection End Class <TypeConverter(GetType(DatabaseTypeConverter))> _ Public Class DatabaseCollection Inherits CollectionBase Public Sub Add(ByVal a As DatabaseMap) list.Add(a) End Sub Public Sub Remove(ByVal index As Integer) If index > Count - 1 Or index < 0 Then Throw New Exception("index value is outside of bounds") End If list.RemoveAt(index) End Sub Public Sub Remove(ByVal value As DatabaseMap) list.Remove(value) End Sub Default Public ReadOnly Property Item(ByVal index As Integer) As DatabaseMap Get Return CType(list.Item(index), DatabaseMap) End Get End Property Default Public ReadOnly Property Item(ByVal _name As String) As DatabaseMap Get For Each ma As DatabaseMap In Me If ma.dbname = _name Then Return ma End If Next End Get End Property End Class --- NEW FILE: DatabaseTable.vb --- <Serializable()> Public Class DatabaseTable Public tableName As String Public tableOwner As String Public parentDBName As String Public columns As New DatabaseColumnCollection Public tableType As String End Class Public Class DatabaseTableCollection Inherits CollectionBase Public Sub Add(ByVal a As DatabaseTable) list.Add(a) End Sub Public Sub Remove(ByVal index As Integer) If index > Count - 1 Or index < 0 Then Throw New Exception("index value is outside of bounds") End If list.RemoveAt(index) End Sub Public Sub Remove(ByVal value As DatabaseTable) list.Remove(value) End Sub Default Public ReadOnly Property Item(ByVal index As Integer) As DatabaseTable Get Return CType(list.Item(index), DatabaseTable) End Get End Property Default Public ReadOnly Property Item(ByVal _name As String) As DatabaseTable Get For Each t As DatabaseTable In Me If t.tableName = _name Then Return t End If Next End Get End Property End Class --- NEW FILE: ClassMapTypeConverter.vb --- Imports System Imports System.Collections Imports System.Data Imports System.ComponentModel Imports System.Globalization Imports System.Xml Imports System.IO Imports System.Reflection Imports System.Xml.Serialization Public Class ClassMapTypeConverter Inherits TypeConverter Public Overloads Overrides Function CanConvertFrom(ByVal context As ITypeDescriptorContext, ByVal sourceType As Type) As Boolean If sourceType Is GetType(XmlNode) Then Return True End If Return MyBase.CanConvertFrom(context, sourceType) End Function Public Overloads Overrides Function CanConvertTo(ByVal context As ITypeDescriptorContext, ByVal destinationType As Type) As Boolean If destinationType Is GetType(XmlNode) Then Return True End If Return MyBase.CanConvertTo(context, destinationType) End Function Public Overloads Overrides Function ConvertFrom(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object) As Object Dim i As Integer If value.GetType Is GetType(XmlNode) Or value.GetType.IsSubclassOf(GetType(XmlNode)) Then Dim node As XmlNode = value Dim nodeList As XmlNodeList Dim cm As ClassMapCollection Dim elem As XmlElement elem = node If elem.Name = "property" Then node = elem.FirstChild End If Dim ms As MemoryStream = New MemoryStream Dim objSerializer As XmlSerializer = New XmlSerializer(GetType(XmlNode)) Dim myWriter As StreamWriter = New StreamWriter(ms) objSerializer.Serialize(myWriter, node) ms.Seek(0, SeekOrigin.Begin) Dim objDeSerializer As XmlSerializer = New XmlSerializer(GetType(ClassMapCollection)) Dim obj As Object obj = objDeSerializer.Deserialize(ms) cm = CType(obj, ClassMapCollection) ms.Close() Return cm End If Return MyBase.ConvertFrom(context, culture, value) End Function Public Overloads Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object, ByVal destinationType As Type) As Object If destinationType Is GetType(XmlNode) Then Dim cm As ClassMapCollection = value Dim ms As MemoryStream = New MemoryStream Dim objSerializer As XmlSerializer = New XmlSerializer(GetType(ClassMapCollection)) Dim myWriter As StreamWriter = New StreamWriter(ms) objSerializer.Serialize(myWriter, cm) ms.Seek(0, SeekOrigin.Begin) Dim doc As New XmlDocument doc.Load(ms) ms.Close() Return doc.SelectSingleNode("/ArrayOfClassMap") End If Return MyBase.ConvertTo(context, culture, value, destinationType) End Function End Class --- NEW FILE: DatabaseTypeConverter.vb --- Imports System Imports System.Collections Imports System.Data Imports System.ComponentModel Imports System.Globalization Imports System.Xml Imports System.IO Imports System.Reflection Imports System.Xml.Serialization Public Class DatabaseTypeConverter Inherits TypeConverter Public Overloads Overrides Function CanConvertFrom(ByVal context As ITypeDescriptorContext, ByVal sourceType As Type) As Boolean If sourceType Is GetType(XmlNode) Then Return True End If Return MyBase.CanConvertFrom(context, sourceType) End Function Public Overloads Overrides Function CanConvertTo(ByVal context As ITypeDescriptorContext, ByVal destinationType As Type) As Boolean If destinationType Is GetType(XmlNode) Then Return True End If Return MyBase.CanConvertTo(context, destinationType) End Function Public Overloads Overrides Function ConvertFrom(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object) As Object Dim i As Integer If value.GetType Is GetType(XmlNode) Or value.GetType.IsSubclassOf(GetType(XmlNode)) Then Dim node As XmlNode = value Dim nodeList As XmlNodeList Dim md As DatabaseCollection Dim elem As XmlElement elem = node If elem.Name = "property" Then node = elem.FirstChild End If Dim ms As MemoryStream = New MemoryStream Dim objSerializer As XmlSerializer = New XmlSerializer(GetType(XmlNode)) Dim myWriter As StreamWriter = New StreamWriter(ms) objSerializer.Serialize(myWriter, node) ms.Seek(0, SeekOrigin.Begin) Dim objDeSerializer As XmlSerializer = New XmlSerializer(GetType(DatabaseCollection)) Dim obj As Object obj = objDeSerializer.Deserialize(ms) md = CType(obj, DatabaseCollection) ms.Close() Return md End If Return MyBase.ConvertFrom(context, culture, value) End Function Public Overloads Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object, ByVal destinationType As Type) As Object If destinationType Is GetType(XmlNode) Then Dim md As DatabaseCollection = value Dim ms As MemoryStream = New MemoryStream Dim objSerializer As XmlSerializer = New XmlSerializer(GetType(DatabaseCollection)) Dim myWriter As StreamWriter = New StreamWriter(ms) objSerializer.Serialize(myWriter, md) ms.Seek(0, SeekOrigin.Begin) Dim doc As New XmlDocument doc.Load(ms) ms.Close() Return doc.SelectSingleNode("/ArrayOfDatabaseMap") End If Return MyBase.ConvertTo(context, culture, value, destinationType) End Function End Class |