/// <summary> /// Duplicate a record /// </summary> /// <param name="record"></param> /// <returns></returns> public static DSRecord Copy(DSRecord record) { if (record == null) { return(null); } if (!(Activator.CreateInstance(record.GetType()) is DSRecord newCopy)) { return(null); } foreach (PropertyInfo property in record.GetType().GetProperties()) { if (!property.CanWrite) { continue; } if (property.PropertyType != typeof(byte[])) { property.SetValue(newCopy, property.GetValue(record)); continue; } if (!(property.GetValue(record) is byte[] value)) { property.SetValue(newCopy, null); continue; } byte[] newValue = new byte[value.Length]; value.CopyTo(newValue, 0); property.SetValue(newCopy, newValue); } return(newCopy); }
/// <summary> /// Constructor by copy /// </summary> /// <param name="copy"></param> public DSRecord(DSRecord copy) { Id = copy.Id; }