SaveAsXaml( Object serializedObject ) { if (serializedObject == null) { throw new ArgumentNullException(nameof(serializedObject)); } if (!XpsSerializationManager.IsSerializedObjectTypeSupported(serializedObject, IsBatchMode)) { throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_NotSupported)); } if (Simulator == null) { Simulator = new XpsOMHierarchySimulator(this, serializedObject); } if (!IsSimulating) { Simulator.BeginConfirmToXPSStructure(IsBatchMode); IsSimulating = true; } if (IsBatchMode) { // // Add the Visual received in to the queue // BatchOperationWorkItem batchOperationWorkItem = new BatchOperationWorkItem(BatchOperationType.batchWrite, serializedObject); _batchOperationQueue.Enqueue(batchOperationWorkItem); PostSerializationTask(new DispatcherOperationCallback(InvokeSaveAsXamlBatchWorkItem)); } else { ReachSerializer reachSerializer = GetSerializer(serializedObject); if (reachSerializer != null) { // // Prepare the context that is going to be pushed on the stack // SerializationManagerOperationContextStack contextStack = new SerializationManagerOperationContextStack(reachSerializer, serializedObject); // // At this stage, start calling another method which would peak at the stack // _operationStack.Push(contextStack); PostSerializationTask(new DispatcherOperationCallback(InvokeSaveAsXamlWorkItem)); } else { throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_NoSerializer)); } } }