带有通用接口的.NET继承

时间:2008-10-14 15:05:46

标签: .net vb.net generics inheritance interface

你好我现在正在玩城堡项目ActiveRecord和远程设施。

我目前的问题是我需要找到一种方法来实现我的地址类中IBaseRepository的save sub,我不知道如何。

这是我当前的代码,VS告诉我“实现IAddress”这一行 我必须为[共享] .IBaseRepository([共享] .IAddress)实现Sub Save(obj As IAddress)

并在线公共覆盖子保存(ByVal obj As Address)实现IBaseRepository(Of IAddress)。保存

我无法实现保存,因为[共享] .IBaseRepository([共享] .IAddress中没有子保存)

我只是不明白:( 请赐教。

TIA

Public Interface IBaseRepository(Of T As Class)  
     Sub Save(ByVal obj As T)  
End Interface

Public Interface IAddress  
    Inherits IBaseRepository(Of IAddress)  
    Property Guid() As Guid  
    Property CompanyName() As String  
    Property Surename() As String  
    Property Christianname() As String  
End Interface`

Public Class BaseRepository(Of T As Class)  
Inherits MarshalByRefObject   
Implements IBaseRepository(Of T)

    Protected mediator As ActiveRecordMediator(Of T)  

    Public Overridable Sub Save(ByVal obj As T) Implements IBaseRepository(Of T).Save  
        ActiveRecordMediator(Of T).Save(obj)  
    End Sub  
End Class


<ActiveRecord("Address")> _    
Public Class Address  
    Inherits BaseRepository(Of Address)  
    Implements IAddress

    Public Overrides Sub Save(ByVal obj As Address) Implements IBaseRepository(Of IAddress).Save
        MyBase.Save(obj)
    End Sub
End Class

1 个答案:

答案 0 :(得分:2)

 Public Class Address
    Inherits BaseRepository(Of Address)
    Implements IAddress


    Public Overrides Sub Save(ByVal obj As Address)
        MyBase.Save(obj)
    End Sub


    Public Overloads Sub Save(ByVal obj As IAddress) _
         Implements IBaseRepository(Of IAddress).Save
    End Sub
 '
 ' Some other stuff...
 '
 End Class