ser*_*hio 0 .net vb.net generics extension-methods
我想在VB.NET中实现一个扩展方法,它将克隆类型为T的对象.
说,我想要
Dim cust1 as New Customer() //...
Dim cust2 as New Customer() //...
cust2 = cust1.Clone()
''
' My extension method '
''
<Runtime.CompilerServices.Extension()> _
Public Function Clone(Of T As {Class, New})(ByVal obj As T) As T
Dim objClone As New T
' clonning stuff '
' objClone = CType(GetAnObjClone(), T) '
Return objClone
End Function
Dim c As MyObject
Dim cc As MyObject = c.Clone() ' does work!!! cool... '
Run Code Online (Sandbox Code Playgroud)
要删除的问题.