H
hnolan
I want to create a collection of objects that is shared in an
assembly. What is the best way to do this? My initial thought was to
have a public class that has a private shared collection and then a
public shared property that loads the collection if needed and then
returns the needed object. Is this the correct way to do this?
Ex:
Public Class StandardImportDefinitions
Private Shared _definitions as System.Generics.List(of
ImportDefinition)
Private Sub New()
End Sub
Public Shared Function Definition(definitionName as string) as
ImportDefintion
if _definitions is nothing then
_definitions = New System.Generics.List(of ImportDefinition)
Dim xmldef as New XMLDocument
xmldef.Load(My.Resources.IMPORTSPEC)
'read XML, create ImportDefinition and add to collection
end if
for each def as ImportDefinition in _definitions
if def.name = definitionName then
Return def
end if
next
Return Nothing
End Function
End Class
Public Class ImportDefintion
private _name
private _fields etc...
Public Readonly Property Name as string
Get
Return _name
End Get
End Property
End Class
Public Class ImportSpecWithMappings
Private _thisspec
Private _sourcedata as datatable
Private _mappings as Collection
Public Sub New(standardSpecName as string)
_thisspec = StandardImportDefinitions.Definition(standardSpecName)
End Sub
End Class
assembly. What is the best way to do this? My initial thought was to
have a public class that has a private shared collection and then a
public shared property that loads the collection if needed and then
returns the needed object. Is this the correct way to do this?
Ex:
Public Class StandardImportDefinitions
Private Shared _definitions as System.Generics.List(of
ImportDefinition)
Private Sub New()
End Sub
Public Shared Function Definition(definitionName as string) as
ImportDefintion
if _definitions is nothing then
_definitions = New System.Generics.List(of ImportDefinition)
Dim xmldef as New XMLDocument
xmldef.Load(My.Resources.IMPORTSPEC)
'read XML, create ImportDefinition and add to collection
end if
for each def as ImportDefinition in _definitions
if def.name = definitionName then
Return def
end if
next
Return Nothing
End Function
End Class
Public Class ImportDefintion
private _name
private _fields etc...
Public Readonly Property Name as string
Get
Return _name
End Get
End Property
End Class
Public Class ImportSpecWithMappings
Private _thisspec
Private _sourcedata as datatable
Private _mappings as Collection
Public Sub New(standardSpecName as string)
_thisspec = StandardImportDefinitions.Definition(standardSpecName)
End Sub
End Class