| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Linq; |
| | | 4 | | using System.Text; |
| | | 5 | | |
| | | 6 | | namespace WinSolutions.Sveta.Server.Utils |
| | | 7 | | { |
| | | 8 | | class DataUtils |
| | | 9 | | { |
| | | 10 | | public static void CopyTo(object src, object dst) |
| | 0 | 11 | | { |
| | | 12 | | |
| | 0 | 13 | | var srcType = src.GetType(); |
| | 0 | 14 | | foreach (var fi in dst.GetType().GetFields().Where(p=>p.IsPublic)) |
| | 0 | 15 | | { |
| | 0 | 16 | | var rfi = srcType.GetField(fi.Name); |
| | | 17 | | |
| | 0 | 18 | | if(rfi != null) |
| | 0 | 19 | | rfi.SetValue(dst,fi.GetValue(src)); |
| | 0 | 20 | | } |
| | | 21 | | |
| | 0 | 22 | | foreach (var pi in dst.GetType().GetProperties().Where(p=>p.CanWrite && p.CanRead)) |
| | 0 | 23 | | { |
| | 0 | 24 | | var rpi = srcType.GetProperty(pi.Name); |
| | | 25 | | |
| | | 26 | | |
| | 0 | 27 | | if(rpi != null) |
| | 0 | 28 | | rpi.SetValue(dst,pi.GetValue(src,null),null); |
| | 0 | 29 | | } |
| | 0 | 30 | | } |
| | | 31 | | } |
| | | 32 | | } |