.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+

CloneObjectViewController.CustomCloneObject Event

Occurs before the default cloning process begins.

Namespace: DevExpress.ExpressApp.CloneObject

Assembly: DevExpress.ExpressApp.CloneObject.v20.1.dll

Declaration

public event EventHandler<CustomCloneObjectEventArgs> CustomCloneObject
Public Event CustomCloneObject As EventHandler(Of CustomCloneObjectEventArgs)

Event Data

The CustomCloneObject event's data class is CustomCloneObjectEventArgs. The following properties provide information specific to this event:

Property Description
ClonedObject Represents the target object of the cloning process.
SourceObject Gets the object to be cloned.
TargetObjectSpace Specifies the Object Space of the target object.
TargetType Gets the type of the target object.

Remarks

When this event is handled and the handler's ClonedObject parameter is initialized, the object represented by this parameter becomes the target object of the cloning process. Otherwise, default cloning is performed.

Handle this event to implement custom cloning logic. Pass the custom cloned object via the handler's ClonedObject parameter. Pass the target object's Object Space via the TargetObjectSpace parameter.

To manually clone a source object, handle this event and assign a custom cloned object to the CustomCloneObjectEventArgs.ClonedObject parameter. If the event is not handled or the ClonedObject parameter is null (Nothing in VB), the default cloning is performed.

By default, the CustomCloneObjectEventArgs.TargetObjectSpace parameter refers to an IObjectSpace object. Initialize the TargetObjectSpace property to use custom Object Space type object to clone an object.

NOTE

When the handler's ClonedObject parameter is passed, but the TargetObjectSpace parameter is null (Nothing in VB), an exception is raised.

You can implement a custom DevExpress.Persistent.Base.Cloner class descendant to customize the cloning process, and then call it's CloneTo method in the CustomCloneObject event handler.

The following snippet illustrates how to override the Cloner.CopyMemberValue method to skip association proprerties when cloning.

using DevExpress.ExpressApp.CloneObject;
using DevExpress.Xpo.Metadata;
using DevExpress.Xpo;
using DevExpress.Persistent.Base;
//...
public class CustomizeCloneObjectController : ObjectViewController {
    protected override void OnActivated() {
        base.OnActivated();
        var cloneObjectController = Frame.GetController<CloneObjectViewController>();
        if (cloneObjectController != null) {
            cloneObjectController.CustomCloneObject += cloneObjectController_CustomCloneObject;
        }
    }
    void cloneObjectController_CustomCloneObject(object sender, CustomCloneObjectEventArgs e) {
        var cloner = new MyCloner();
        e.TargetObjectSpace = e.CreateDefaultTargetObjectSpace();
        object objectFromTargetObjectSpace = e.TargetObjectSpace.GetObject(e.SourceObject);
        e.ClonedObject = cloner.CloneTo(objectFromTargetObjectSpace, e.TargetType);
    }
}
public class MyCloner : Cloner {
    public override void CopyMemberValue(
        XPMemberInfo memberInfo, IXPSimpleObject sourceObject, IXPSimpleObject targetObject) {
        if (!memberInfo.IsAssociation) {
            base.CopyMemberValue(memberInfo, sourceObject, targetObject);
        }
    }
}
See Also