/// <summary> /// Applies all shared properties from <see cref="Source"/> to <see cref="Destination"/>. /// </summary> /// <param name="Source"><see cref="PKM"/> that supplies property values.</param> /// <param name="Destination"><see cref="PKM"/> that receives property values.</param> protected void TransferPropertiesWithReflection(PKM Source, PKM Destination) { var SourceProperties = ReflectUtil.getPropertiesCanWritePublic(Source.GetType()); var DestinationProperties = ReflectUtil.getPropertiesCanWritePublic(Destination.GetType()); // Skip Data property when applying all individual properties. Let the setters do the updates for Data. foreach (string property in SourceProperties.Intersect(DestinationProperties).Where(prop => prop != nameof(Data))) { var prop = ReflectUtil.GetValue(this, property); if (prop != null) { ReflectUtil.SetValue(Destination, property, prop); } } }
protected void TransferPropertiesWithReflection(PKM Source, PKM Destination) { var SourceProperties = ReflectUtil.getPropertiesCanWritePublic(Source.GetType()); var DestinationProperties = ReflectUtil.getPropertiesCanWritePublic(Destination.GetType()); foreach (string property in SourceProperties.Intersect(DestinationProperties).Where(prop => prop != nameof(Data))) { var prop = ReflectUtil.GetValue(this, property); if (prop == null) { continue; } ReflectUtil.SetValue(Destination, property, prop); } }