Esempio n. 1
0
        /// <summary>
        /// Creates a new Draft, based on the type of the state.
        /// </summary>
        /// <typeparam name="T">The type of the state.</typeparam>
        /// <param name="state">The immutable.</param>
        /// <param name="draft">A new draft, based on the immutable.</param>
        /// <param name="producerOptions">The producer options to use. If you leave them null, the default options will be used.</param>
        /// <returns>A scope that is used to either reconcile or dispose of the draft.</returns>
        internal static IDraftScope InternalCreateDraft <T>(object state, out T draft, IProducerOptions?producerOptions = null)
            where T : class
        {
            var scope = new DraftScope(producerOptions ?? ProducerOptions.Default);

            try
            {
                PathSegment?path = (scope.Patches != null) ? new PathSegment("/") : null;

                var draftState = InternalGetDraftState(state);
                if (draftState != null)
                {
                    scope.Parent = draftState.Scope;
                    if (draftState != null)
                    {
                        path = draftState.Path;
                    }
                }

                draft = (T)scope.CreateProxy(state, path);
                return(scope);
            }
            catch
            {
                scope.Dispose();
                throw;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DraftState"/> class.
 /// </summary>
 /// <param name="scope">The scope this draft state belongs to.</param>
 /// <param name="original">The original.</param>
 /// <param name="path">The path segment.</param>
 public DraftState(DraftScope scope, object original, PathSegment?path)
 {
     this.Scope    = scope ?? throw new ArgumentNullException(nameof(scope));
     this.original = original ?? throw new ArgumentNullException(nameof(original));
     this.Path     = path;
 }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ObjectDraftState"/> class.
 /// </summary>
 /// <param name="scope">The scope this draft state belongs to.</param>
 /// <param name="original">The original.</param>
 /// <param name="path">The path segment.</param>
 public ObjectDraftState(DraftScope scope, object original, PathSegment?path)
     : base(scope, original, path)
 {
 }