Public Shared Function ConvertToDataTable(Of T)(ByVal list As IList(Of T)) As DataTable
Dim table As New DataTable()
Dim fields() As FieldInfo = GetType(T).GetFields()
For Each field As FieldInfo In fields
table.Columns.Add(field.Name, field.FieldType)
Next
For Each item As T In list
Dim row As DataRow = table.NewRow()
For Each field As FieldInfo In fields
row(field.Name) = field.GetValue(item)
Next
table.Rows.Add(row)
Next
Return table
End Function
Tag : .NET, Win (Windows App), VB.NET, C#, VS 2008 (.NET 3.x), VS 2010 (.NET 4.x)
Class BaseClassA
Public Function BeHappy () As String
Return "หากว่าเราสบายจงปรบมือพลัน ป้าบๆ"
End Function
End Class
Class ChildClassB
Inherits BaseClassA
Public Function BeHappy () As String
Return "ช้างๆ น้องเคยเห็นช้างป่าวจ้ะ"
End Function
End Class
Class Person
Public Function SingSomeSong(Of T As BaseClassA ) (Byval Song As T)
Return Song.BeHappy()
End Funtion
End Class
Sub Main()
Dim SongA As New BaseClassA()
Dim SongB As New ChildClassB()
Dim SomeOne As New Person()
Dim SongText As String = SomeOne(SongA) & " : : & SomeOne(SongB)
End Sub