Asimilar valores de un objeto de la misma clase


/ Published in: VB.NET
Save to your folder(s)

Dado un objeto original, este método copia los valores de ese objeto en un segundo objeto de la misma clase, utilizando reflection.


Copy this code and paste it in your HTML
  1. Public Sub Asimilar(of T)(ByVal target as T, ByVal source As T)
  2. Dim propiedades As PropertyInfo()
  3. Dim type As Type = target.GetType()
  4. propiedades = type.GetProperties()
  5.  
  6. For Each pi As PropertyInfo In propiedades
  7. If pi.CanWrite Then pi.SetValue(target, pi.GetValue(source, Nothing), Nothing)
  8. Next
  9. End Sub

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.