A
Aeden Jameson
Suppose I have the follwing
Public Interface IEntity
End Interface
Public Class TestEntity
Implements IEntity
End Class
Public Interface IRepository(Of T As {IEntity})
End Interface
Public Interface IConcreteRepository
Inherits IRepository(Of TestEntity)
End Interface
Public Class ConcreteRepository
Implements IConcreteRepository
End Class
Public Class Factory
Public Shared Function Create(Of TRepository As {Class,
IRepository(Of TEntity)}, TEntity As {IEntity})()
Return New ConcreteRepository()
End Function
End Class
I get casting exception on the line
Dim Repository As IRepository(Of IEntity) = Factory.Create(Of
IConcreteRepository, TestEntity)()
What am I missing?
The exception states
Unable to cast object of type 'ConcreteRepository' to type
'IRepository`1[IEntity]'.
Cheers,
Aeden
Public Interface IEntity
End Interface
Public Class TestEntity
Implements IEntity
End Class
Public Interface IRepository(Of T As {IEntity})
End Interface
Public Interface IConcreteRepository
Inherits IRepository(Of TestEntity)
End Interface
Public Class ConcreteRepository
Implements IConcreteRepository
End Class
Public Class Factory
Public Shared Function Create(Of TRepository As {Class,
IRepository(Of TEntity)}, TEntity As {IEntity})()
Return New ConcreteRepository()
End Function
End Class
I get casting exception on the line
Dim Repository As IRepository(Of IEntity) = Factory.Create(Of
IConcreteRepository, TestEntity)()
What am I missing?
The exception states
Unable to cast object of type 'ConcreteRepository' to type
'IRepository`1[IEntity]'.
Cheers,
Aeden