示例#1
0
        /// <summary>
        /// <para>
        /// Creates a snapshot of the current state of the <see cref="RouteData"/> before appending
        /// <paramref name="router"/> to <see cref="Routers"/>, merging <paramref name="values"/> into
        /// <see cref="Values"/>, and merging <paramref name="dataTokens"/> into <see cref="DataTokens"/>.
        /// </para>
        /// <para>
        /// Call <see cref="RouteDataSnapshot.Restore"/> to restore the state of this <see cref="RouteData"/>
        /// to the state at the time of calling
        /// <see cref="PushState(IRouter, RouteValueDictionary, RouteValueDictionary)"/>.
        /// </para>
        /// </summary>
        /// <param name="router">
        /// An <see cref="IRouter"/> to append to <see cref="Routers"/>. If <c>null</c>, then <see cref="Routers"/>
        /// will not be changed.
        /// </param>
        /// <param name="values">
        /// A <see cref="RouteValueDictionary"/> to merge into <see cref="Values"/>. If <c>null</c>, then
        /// <see cref="Values"/> will not be changed.
        /// </param>
        /// <param name="dataTokens">
        /// A <see cref="RouteValueDictionary"/> to merge into <see cref="DataTokens"/>. If <c>null</c>, then
        /// <see cref="DataTokens"/> will not be changed.
        /// </param>
        /// <returns>A <see cref="RouteDataSnapshot"/> that captures the current state.</returns>
        public RouteDataSnapshot PushState(IRouter router, RouteValueDictionary values, RouteValueDictionary dataTokens)
        {
            var snapshot = new RouteDataSnapshot(
                this,
                _dataTokens?.Count > 0 ? new RouteValueDictionary(_dataTokens) : null,
                _routers?.Count > 0 ? new List <IRouter>(_routers) : null,
                _values?.Count > 0 ? new RouteValueDictionary(_values) : null);

            if (router != null)
            {
                Routers.Add(router);
            }

            if (values != null)
            {
                foreach (var kvp in values)
                {
                    if (kvp.Value != null)
                    {
                        Values[kvp.Key] = kvp.Value;
                    }
                }
            }

            if (dataTokens != null)
            {
                foreach (var kvp in dataTokens)
                {
                    DataTokens[kvp.Key] = kvp.Value;
                }
            }

            return(snapshot);
        }
示例#2
0
    public RouteDataSnapshot PushState(IRouter?router, RouteValueDictionary?values, RouteValueDictionary?dataTokens)
    {
        // Perf: this is optimized for small list sizes, in particular to avoid overhead of a native call in
        // Array.CopyTo inside the List(IEnumerable<T>) constructor.
        List <IRouter>?routers = null;
        var            count   = _routers?.Count;

        if (count > 0)
        {
            Debug.Assert(_routers != null);

            routers = new List <IRouter>(count.Value);
            for (var i = 0; i < count.Value; i++)
            {
                routers.Add(_routers[i]);
            }
        }

        var snapshot = new RouteDataSnapshot(
            this,
            _dataTokens?.Count > 0 ? new RouteValueDictionary(_dataTokens) : null,
            routers,
            _values?.Count > 0 ? new RouteValueDictionary(_values) : null);

        if (router != null)
        {
            Routers.Add(router);
        }

        if (values != null)
        {
            foreach (var kvp in values)
            {
                if (kvp.Value != null)
                {
                    Values[kvp.Key] = kvp.Value;
                }
            }
        }

        if (dataTokens != null)
        {
            foreach (var kvp in dataTokens)
            {
                DataTokens[kvp.Key] = kvp.Value;
            }
        }

        return(snapshot);
    }
示例#3
0
        /// <summary>
        /// <para>
        /// Creates a snapshot of the current state of the <see cref="RouteData"/> before appending
        /// <paramref name="router"/> to <see cref="Routers"/>, merging <paramref name="values"/> into
        /// <see cref="Values"/>, and merging <paramref name="dataTokens"/> into <see cref="DataTokens"/>.
        /// </para>
        /// <para>
        /// Call <see cref="RouteDataSnapshot.Restore"/> to restore the state of this <see cref="RouteData"/>
        /// to the state at the time of calling
        /// <see cref="PushState(IRouter, RouteValueDictionary, RouteValueDictionary)"/>.
        /// </para>
        /// </summary>
        /// <param name="router">
        /// An <see cref="IRouter"/> to append to <see cref="Routers"/>. If <c>null</c>, then <see cref="Routers"/>
        /// will not be changed.
        /// </param>
        /// <param name="values">
        /// A <see cref="RouteValueDictionary"/> to merge into <see cref="Values"/>. If <c>null</c>, then
        /// <see cref="Values"/> will not be changed.
        /// </param>
        /// <param name="dataTokens">
        /// A <see cref="RouteValueDictionary"/> to merge into <see cref="DataTokens"/>. If <c>null</c>, then
        /// <see cref="DataTokens"/> will not be changed.
        /// </param>
        /// <returns>A <see cref="RouteDataSnapshot"/> that captures the current state.</returns>
        public RouteDataSnapshot PushState(IRouter router, RouteValueDictionary values, RouteValueDictionary dataTokens)
        {
            var snapshot = new RouteDataSnapshot(
                this,
                _dataTokens?.Count > 0 ? new RouteValueDictionary(_dataTokens) : null,
                _routers?.Count > 0 ? new List<IRouter>(_routers) : null,
                _values?.Count > 0 ? new RouteValueDictionary(_values) : null);

            if (router != null)
            {
                Routers.Add(router);
            }

            if (values != null)
            {
                foreach (var kvp in values)
                {
                    if (kvp.Value != null)
                    {
                        Values[kvp.Key] = kvp.Value;
                    }
                }
            }

            if (dataTokens != null)
            {
                foreach (var kvp in dataTokens)
                {
                    DataTokens[kvp.Key] = kvp.Value;
                }
            }

            return snapshot;
        }