// This file is part of YamlDotNet - A .NET library for YAML. // Copyright (c) Antoine Aubry and contributors // // Permission is hereby granted, free of charge, to any person obtaining a copy of // this software and associated documentation files (the "Software"), to deal in // the Software without restriction, including without limitation the rights to // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies // of the Software, and to permit persons to whom the Software is furnished to do // so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. using System; using System.Collections.Generic; using System.Linq; using YamlDotNet.Core; namespace YamlDotNet.Serialization { public sealed class EmissionPhaseObjectGraphVisitorArgs { /// /// Gets the next visitor that should be called by the current visitor. /// public IObjectGraphVisitor InnerVisitor { get; private set; } /// /// Gets the that is to be used for serialization. /// public IEventEmitter EventEmitter { get; private set; } /// /// Gets a function that, when called, serializes the specified object. /// public ObjectSerializer NestedObjectSerializer { get; private set; } public IEnumerable TypeConverters { get; private set; } private readonly IEnumerable> preProcessingPhaseVisitors; public EmissionPhaseObjectGraphVisitorArgs( IObjectGraphVisitor innerVisitor, IEventEmitter eventEmitter, IEnumerable> preProcessingPhaseVisitors, IEnumerable typeConverters, ObjectSerializer nestedObjectSerializer ) { InnerVisitor = innerVisitor ?? throw new ArgumentNullException(nameof(innerVisitor)); EventEmitter = eventEmitter ?? throw new ArgumentNullException(nameof(eventEmitter)); this.preProcessingPhaseVisitors = preProcessingPhaseVisitors ?? throw new ArgumentNullException(nameof(preProcessingPhaseVisitors)); TypeConverters = typeConverters ?? throw new ArgumentNullException(nameof(typeConverters)); NestedObjectSerializer = nestedObjectSerializer ?? throw new ArgumentNullException(nameof(nestedObjectSerializer)); } /// /// Gets the visitor of type that was used during the pre-processing phase. /// /// The type of the visitor.s /// /// /// No visitor of that type has been registered, /// or ore than one visitors registered are of type . /// public T GetPreProcessingPhaseObjectGraphVisitor() where T : IObjectGraphVisitor { return preProcessingPhaseVisitors .OfType() .Single(); } } }