0
我有许多类都实现相同的接口。例如将(T)的列表转换为以逗号分隔的字符串的ID
Public Class IncidentAsset
Implements IModelWithIdentity
Private _assetId As Int16
Private _otherAsset As String
Private _asset As Asset
Public Property AssetId() As Int16
Get
Return _assetId
End Get
Set(ByVal value As Int16)
_assetId = value
End Set
End Property
Public Property OtherAsset() As String
Get
Return _otherAsset
End Get
Set(ByVal value As String)
_otherAsset = value
End Set
End Property
Public Property Asset() As Asset
Get
Return _asset
End Get
Set(ByVal value As Asset)
_asset = value
End Set
End Property
Public Function GetId() As String Implements IModelWithIdentity.GetId
Return _assetId.ToString()
End Function
End Class
我有另一个对象与这些对象的列表。
Public Property IncidentAssetsDamaged() As List(Of IncidentAsset)
Get
Return _incidentAssetsDamaged
End Get
Set(ByVal value As List(Of IncidentAsset))
_incidentAssetsDamaged = value
End Set
End Property
我需要写会返回一个逗号分隔的标识的使用接口的getId()方法的字符串的方法。
这是我到目前为止有:
Public Shared Function ToCommaSeparatedStringOfIds(Of T)(ByVal collection As List(Of T)) As String
Dim array As List(Of String) = New List(Of String)
For Each obj As IModelWithIdentity In collection
array.Add(obj.GetId())
Next
Return String.Join(",", array.ToArray)
End Function
有没有使用.NET 2.0中VB.NET这样做的更好的办法?