在asp.net 2.0中,我有幾個使用泛型定義的「下拉菜單」(示例眼睛顏色,頭髮顏色等)。這些田地都是典型的; ID,文本等。所有被定義爲他們自己的類,它們必須實現我創建的稱爲ILookup的接口。然而,當我嘗試返回使用這個類的List <>:我在創建泛型約束時犯了什麼錯誤?
ddlEyeColor.DataSource = luMgt.GetLookUpItemList(Of EyeColor)()
這就要求BC層:
Public Function GetLookUpItemList(Of t As {ILookup, New})() As List(Of t)
Dim luMgt As New LookupMgt
Return luMgt.GetLookUpItemList(Of t)()
End Function
它調用DBC層,它在某種程度上是....
Public Function GetLookUpItemList(Of t As {ILookup, New})() As List(Of t)
Dim lstGenericList As New List(Of t)
'rest of code to populate the list here
end function
錯誤消息聲稱EyeColor沒有實現ILookup。
錯誤21類型參數'EyeColor'不繼承或實現約束類型'ILookup'。
但這裏是眼睛顏色類的開頭....
Public Class EyeColor
Implements ILookup
下面是完整的接口....
公用接口ILookup
Property ID() As Int32
Property Text() As String
Property Description() As String
Property Status() As Status
Property OrderID() As Int32
ReadOnly Property LookUpType() As LookUpType
末接口
在這裏,在EyeColor類中,我正在實現interf的屬性王牌
Public Overrides Property Description() As String Implements ILookup.Description
Get
Return MyBase.Description
End Get
Set(ByVal value As String)
MyBase.Description = value
End Set
End Property
Public Overrides Property ID() As Integer Implements ILookup.ID
Get
Return MyBase.ID
End Get
Set(ByVal value As Integer)
MyBase.ID = value
End Set
End Property
Public Overrides Property OrderID() As Integer Implements ILookup.OrderID
Get
Return MyBase.OrderID
End Get
Set(ByVal value As Integer)
MyBase.OrderID = value
End Set
End Property
Public Overrides Property Status() As Status Implements ILookup.Status
Get
Return MyBase.Status
End Get
Set(ByVal value As Status)
MyBase.Status = value
End Set
End Property
Public Property EyeColor() As String Implements ILookup.Text
Get
Return _eyeColor
End Get
Set(ByVal value As String)
_eyeColor = value
End Set
End Property
Public ReadOnly Property LookUpType() As LookUpType Implements ILookup.LookUpType
Get
Return BE.LookUpType.EyeColor
End Get
End Property
有沒有在你的眼睛顏色類中的任何編譯器錯誤?如果接口尚未完全實現,至少使用'NotImplementedExceptions',編譯器錯誤將以這種方式「級聯」。 – Jay 2010-01-26 18:33:52
爲什麼這些屬性聲明爲覆蓋?在這裏有一個基類嗎? – 2010-01-26 18:55:13