I’m attempting to dynamically register entities and configurations with a context (ef4 code-only)
I would normally do:
Private Shared Sub ConfigureDatabase(ByRef Builder As ContextBuilder(Of ContextExtension))
'Load configurations for each of the tables (Entity sets) in our database...
ConfigureEntity(Builder, New ContactConfig)
End Sub
Private Shared Sub ConfigureEntity(Of T)(ByRef Builder As ContextBuilder(Of ContextExtension), ByVal config As EntityConfiguration(Of T), ByVal setName As String)
'Register the entity configuration with the builder
Builder.Configurations.Add(config)
'Register the entity set name with the builder
Builder.RegisterSet(Of T)(setName)
End Sub
Where ContactConfig is a class which inherits EntityConfiguration(Of Contact) and Contact is a class which implements an interface IEntity (IEntity is common to all entities).
So… I need to search a namespace (say Project.DB.Client) for all signatures that match:
EntityConfiguration(Of <Class which implements IEntity>)
How can I achieve this?
Namespace is just a part of object’s name. Searching for types which inherit generic class involves much more effort than just filtering by namespace name:
CheckTypefunction checks if type is inherited fromEntityConfiguration(Of T).FilterTypesfunction additionally filters types by namespace and returns filtered list a result.Example:
Dim types = FilterTypes("Project.DB.Client", Assembly.GetExecutingAssembly().GetTypes()).