S
Simon Woods
Hi
I have a factory class which I want to use to create new objects which
inherit a certain base type so I have a declaration
Public Class MyOwnFactory(Of T As MyOwnBase)
As I understand it, a new MyOwnFactory will get instantiated for every
different type of class implementing MyOwnBase. (This is what I want
anyway as the factory is holding a cache of previously created objects
of this type)
In the class, I have some methods :
Public Function GetMyObject(ByVal p_key As String, ByVal p_reload As
Boolean) As T
....
Dim l_def As T = CreateMyObject(l_dto)
...
Return l_def
End Function
Private Function CreateMyObject() As T
Dim l_def As T = New T()
If LoadCommonData(l_def, l_data) then
endif
Return l_def
End Function
I'm getting the error
"'New' cannot be used on a type parameter that does not have a 'New'
constraint." against the line
Dim l_def As T = New T()
Because it is a factory, I want to keep the New-ing local to the factory
(so I don't want public constructors on the types inheriting MyOwnBase)
and I wondering if someone could explain a way to do this or perhaps an
alternative way of looking at this.
Thx in advance
Simon
I have a factory class which I want to use to create new objects which
inherit a certain base type so I have a declaration
Public Class MyOwnFactory(Of T As MyOwnBase)
As I understand it, a new MyOwnFactory will get instantiated for every
different type of class implementing MyOwnBase. (This is what I want
anyway as the factory is holding a cache of previously created objects
of this type)
In the class, I have some methods :
Public Function GetMyObject(ByVal p_key As String, ByVal p_reload As
Boolean) As T
....
Dim l_def As T = CreateMyObject(l_dto)
...
Return l_def
End Function
Private Function CreateMyObject() As T
Dim l_def As T = New T()
If LoadCommonData(l_def, l_data) then
endif
Return l_def
End Function
I'm getting the error
"'New' cannot be used on a type parameter that does not have a 'New'
constraint." against the line
Dim l_def As T = New T()
Because it is a factory, I want to keep the New-ing local to the factory
(so I don't want public constructors on the types inheriting MyOwnBase)
and I wondering if someone could explain a way to do this or perhaps an
alternative way of looking at this.
Thx in advance
Simon