Hi, now i'm hoping the following is possible although I'm not entirely certain it is so here goes...
Below is the setup of what I'm hoping is possible (in VB.net, feel free to answer in C# and I should be able to work it out):
Public Class A
Private _name As String
Private _s As SearchA
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal Value As String)
_name = Value
End Set
End Property
Public Property S() As SearchA
Get
Return _s
End Get
Set(ByVal Value As SearchA)
_s = Value
End Set
End Property
Public Sub New(ByVal name As String)
_name = name
_s = New SearchA()
End Sub
Public Function GetSearch() As String
Return _s.Search
End Sub
End Class
and
Public Class SearchA
Private _search As String
Public Property Search () As String
Get
Return _search
End Get
Set(ByVal Value As String
_search = Value
End Set
End Property
Public Sub New()
_search = "Search using Base"
End Sub
End Class
and
Public Class B
Inherits A
Private Shadows _s As SearchB
Public Shadows Property S() As SearchB
Get
Return _s
End Get
Set(ByVal Value As SearchB)
_s = Value
End Set
End Property
Public Sub New(ByVal name As String)
Mybase.New(name)
_s = New SearchB()
End Sub
End Class
and finally
Public Class SearchB
Inherits SearchA
Private _superSearch As String
Public Property SuperSearch () As String
Get
Return _superSearch
End Get
Set(ByVal Value As String
_superSearch = Value
End Set
End Property
Public Sub New()
Mybase.New()
_search = "Search using New"
_superSearch = "With more options..."
End Sub
End Class
and here's the usage:
Dim oB As New B("hello")
Response.Write(oB.GetSearch())
I thought that shadows might work and print "Search using New" but it doesn't, any ideas? I can't override as the property has a different return type to the base class property. I want to define within a base class a core set of functions that I don't have to override within each child class. Or does this not make much sense?
Thanks for your help!
Steve