CloneContext Class
A context used when cloning objects to maintain object reference mapping or to change a behavior of a cloning process.
- Inheritance:
- System.ObjectCloneContext
Remarks
Cloning is a process when one or more objects from a presentation are duplicated. Objects can be duplicated to the same or another presentation and to the same or another location (for example, to another slide).
Cloning methods are available on collection types, such as SlideCollection, DrawingCollection, TextParagraphCollection or TextElementCollection. Exception is the PresentationDocument type that has a Clone() method used to make a deep clone of the entire presentation. Cloning methods available on the collection types have two forms: AddClone(Slide) and InsertClone(Int32, Slide) to append the duplicate to the collection or insert it into a specific location in the collection.
Objects contained in the presentation can contain references to other objects. For example, Slide contains a reference to its ParentTemplate, Connector can contain a reference to drawings that it connects (BeginConnection and EndConnection), Action can contain a Target to Slide or CustomSlideShow that should be shown when the action is triggered.
When cloning multiple objects, the desired behavior is to maintain these references in the duplicated objects so that, for example, when Connector is cloned, and later when drawings that it connects are cloned, the duplicated Connector also connects duplicates of the original drawings that are connected.
This reference mapping between an original object and its duplicate is maintained by the instance of the CloneContext type. CloneContext instance is created with Create(PresentationDocument, PresentationDocument) static method. Each object can be cloned exactly once using the same CloneContext instance. If you want to clone the same object multiple times, each time a new CloneContext instance must be used. CloneContext is the most useful when cloning multiple objects one after another or when you want to change a behavior of the cloning operation.
Behavior of the cloning operation can be changed by using Set<T>(T, T) method. With this method you can make an explicit mapping between objects and cloning process will respect that mapping. For example, if you are cloning a Slide instance to another PresentationDocument default behavior would be that its parent template LayoutSlide and MasterSlide would also be cloned to another PresentationDocument. This behavior can be changed by making an explicit mapping from the LayoutSlide that is the ParentTemplate of the Slide that will be cloned to some LayoutSlide in the another PresentationDocument that we wish to be a ParentTemplate of the duplicated Slide. Explicit mapping with Set<T>(T, T) method can currently be made between following type (and their derivatives) instances: SlideObject, Drawing, TableStyle and CustomSlideShow.
Properties
DestinationPresentation
Gets the destination presentation where the cloned objects will be contained.
public PresentationDocument DestinationPresentation { get; }
Public ReadOnly Property DestinationPresentation As PresentationDocument
Property Value
The destination presentation where the cloned objects will be contained.
SourcePresentation
Gets the source presentation that contains the objects that will be cloned.
public PresentationDocument SourcePresentation { get; }
Public ReadOnly Property SourcePresentation As PresentationDocument
Property Value
The source presentation that contains the objects that will be cloned.
Methods
Create(PresentationDocument, PresentationDocument)
Creates the cloning context that can be used to maintain object reference mapping or to change a behavior of a cloning process.
public static CloneContext Create(PresentationDocument sourcePresentation, PresentationDocument destinationPresentation)
Public Shared Function Create(sourcePresentation As PresentationDocument, destinationPresentation As PresentationDocument) As CloneContext
Parameters
sourcePresentation
- PresentationDocument
The source presentation that contains the objects that will be cloned.
destinationPresentation
- PresentationDocument
The destination presentation where the cloned objects will be contained.
Returns
An instance of a CloneContext type that can be used to maintain object reference mapping or to change a behavior of a cloning process.
Exceptions
- System.ArgumentNullException
sourcePresentation
or destinationPresentation
is null.
Get<T>(T)
Gets the destination object (either clone or mapped) for the specified source object.
Parameters
source
- T
The source object.
Returns
- T
the destination object (either clone or mapped) for the specified source object or null.
Type Parameters
T
Either SlideObject, Drawing, TableStyle or CustomSlideShow.
Exceptions
- System.ArgumentNullException
source
is null.
- System.ArgumentException
source
object type is not supported for the mapping operation or it is not contained in the appropriate SourcePresentation.
Set<T>(T, T)
Sets the mapping between the specified source
and destination
objects.
public void Set<T>(T source, T destination)
Public Sub Set(Of T)(source As T, destination As T)
Parameters
source
- T
The source object.
destination
- T
The destination object.
Type Parameters
T
Either SlideObject, Drawing, TableStyle or CustomSlideShow.
Exceptions
- System.ArgumentNullException
source
or destination
is null.
- System.ArgumentException
Either source
or destination
object type is not supported for the mapping operation or objects are not contained in the appropriate SourcePresentation or DestinationPresentation.