I have this legacy function that gets a string and need to return an IEntityCollection2.
It uses reflection but I would like to be able to instantiate the classes directly. This is the current function:
Public Function CreateEntityCollection(ByVal entityName As String) As IEntityCollection2
Dim dynamicAssembly = Assembly.LoadFrom(DALFileName)
Dim assemblyName = Split(dynamicAssembly.FullName, ",")(0)
Dim sEntityName = assemblyName & ".EntityClasses." & entityName
Dim type = dynamicAssembly.GetType(assemblyName & ".HelperClasses.EntityCollection`1[" & sEntityName & "]", True) 'Get the generic collection type
Dim instance = Activator.CreateInstance(type) 'Call the constuctor to create the entity collection
Return instance
End Function
Ideally I would be able to write something like this
Public Function CreateEntityCollection(ByVal entityName As String) As IEntityCollection2
Return New EntityCollection(Of CreateEntity(entityName))
End Function
Where CreateEntity is
Public Function CreateEntity(ByVal entityName As String) As EntityBase2
Return FactoryClasses.GeneralEntityFactory.Create( _
CType(System.Enum.Parse(GetType(EntityType), entityName), EntityType))
End Function
But that obviously doesn't work. I'm new to LLBLGen, is there a factory I can use to generate this?
Thanks