Posted By

delm on 04/29/09


Tagged

copy Reflection copiar


Versions (?)

Asimilar valores de un objeto de la misma clase


 / Published in: VB.NET
 

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

  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  

You need to login to post a comment.