public class ConfigurationItemCloner : Cloner { private readonly List<string> _dontCloneFields; private readonly List<DXPropertyEditor> _propertyEditors; public ConfigurationItemCloner( List<string> dontCloneFields, List<DXPropertyEditor> propertyEditors ) { _dontCloneFields = dontCloneFields; _propertyEditors = propertyEditors; } public override void CopyMemberValue( XPMemberInfo memberInfo, IXPSimpleObject sourceObject, IXPSimpleObject targetObject ) { var customPropertyEditor = _propertyEditors.FirstOrDefault( x => x.PropertyName == memberInfo.Name ); if (_dontCloneFields == null || !_dontCloneFields.Contains(memberInfo.Name)) { if ((sourceObject is Configuratieitem) && customPropertyEditor != null) { var session = targetObject.Session; var newValue = customPropertyEditor.PropertyValue; if (newValue is PersistentBase obj) { var key = obj.ClassInfo.GetId(obj); newValue = session.GetObjectByKey(newValue.GetType(), key); } targetObject .GetType() .GetProperty(customPropertyEditor.PropertyName) .SetValue(targetObject, newValue); } else { base.CopyMemberValue(memberInfo, sourceObject, targetObject); } } } }
770800cookie-checkDevExpress XAF / XPO getobjectbyid / key clone / copy members