File size: 1,994 Bytes
8c763fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Collections.Generic;

namespace System.Management.Automation
{
    /// <summary>
    /// An object that represents a stack of paths.
    /// </summary>
    public sealed class PathInfoStack : Stack<PathInfo>
    {
        /// <summary>
        /// Constructor for the PathInfoStack class.
        /// </summary>
        /// <param name="stackName">
        /// The name of the stack.
        /// </param>
        /// <param name="locationStack">
        /// A stack object containing PathInfo objects
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="locationStack"/> is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// If <paramref name="stackName"/> is null or empty.
        /// </exception>
        internal PathInfoStack(string stackName, Stack<PathInfo> locationStack) : base()
        {
            if (locationStack == null)
            {
                throw PSTraceSource.NewArgumentNullException(nameof(locationStack));
            }

            if (string.IsNullOrEmpty(stackName))
            {
                throw PSTraceSource.NewArgumentException(nameof(stackName));
            }

            Name = stackName;

            // Since the Stack<T> constructor takes an IEnumerable and
            // not a Stack<T> the stack actually gets enumerated in the
            // wrong order.  I have to push them on manually in the
            // appropriate order.

            PathInfo[] stackContents = new PathInfo[locationStack.Count];
            locationStack.CopyTo(stackContents, 0);

            for (int index = stackContents.Length - 1; index >= 0; --index)
            {
                this.Push(stackContents[index]);
            }
        }

        /// <summary>
        /// Gets the name of the stack.
        /// </summary>
        public string Name { get; } = null;
    }
}