Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
PathInfo.cs166 linesDownload Raw Back to namespaces
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4namespace System.Management.Automation5{6    /// <summary>7    /// An object that represents a path.8    /// </summary>9    public sealed class PathInfo10    {11        /// <summary>12        /// Gets the drive that contains the path.13        /// </summary>14        public PSDriveInfo Drive15        {16            get17            {18                PSDriveInfo result = null;19 20                if (_drive != null &&21                    !_drive.Hidden)22                {23                    result = _drive;24                }25 26                return result;27            }28        }29 30        /// <summary>31        /// Gets the provider that contains the path.32        /// </summary>33        public ProviderInfo Provider34        {35            get36            {37                return _provider;38            }39        }40 41        /// <summary>42        /// This is the internal mechanism to get the hidden drive.43        /// </summary>44        /// <returns>45        /// The drive associated with this PathInfo.46        /// </returns>47        internal PSDriveInfo GetDrive()48        {49            return _drive;50        }51 52        /// <summary>53        /// Gets the provider internal path for the PSPath that this PathInfo represents.54        /// </summary>55        /// <exception cref="ProviderInvocationException">56        /// The provider encountered an error when resolving the path.57        /// </exception>58        /// <exception cref="InvalidOperationException">59        /// The path was a home relative path but the home path was not60        /// set for the provider.61        /// </exception>62        public string ProviderPath63        {64            get65            {66                if (_providerPath == null)67                {68                    // Construct the providerPath69 70                    LocationGlobber pathGlobber = _sessionState.Internal.ExecutionContext.LocationGlobber;71                    _providerPath = pathGlobber.GetProviderPath(Path);72                }73 74                return _providerPath;75            }76        }77 78        private string _providerPath;79        private readonly SessionState _sessionState;80 81        /// <summary>82        /// Gets the PowerShell path that this object represents.83        /// </summary>84        public string Path85        {86            get87            {88                return this.ToString();89            }90        }91 92        private readonly PSDriveInfo _drive;93        private readonly ProviderInfo _provider;94        private readonly string _path = string.Empty;95 96        /// <summary>97        /// Gets a string representing the PowerShell path.98        /// </summary>99        /// <returns>100        /// A string representing the PowerShell path.101        /// </returns>102        public override string ToString()103        {104            string result = _path;105 106            if (_drive == null ||107                _drive.Hidden)108            {109                // For hidden drives just return the current location110                result =111                    LocationGlobber.GetProviderQualifiedPath(112                        _path,113                        _provider);114            }115            else116            {117                result = LocationGlobber.GetDriveQualifiedPath(_path, _drive);118            }119 120            return result;121        }122 123        /// <summary>124        /// The constructor of the PathInfo object.125        /// </summary>126        /// <param name="drive">127        /// The drive that contains the path128        /// </param>129        /// <param name="provider">130        /// The provider that contains the path.131        /// </param>132        /// <param name="path">133        /// The path this object represents.134        /// </param>135        /// <param name="sessionState">136        /// The session state associated with the drive, provider, and path information.137        /// </param>138        /// <exception cref="ArgumentNullException">139        /// If <paramref name="drive"/>, <paramref name="provider"/>,140        /// <paramref name="path"/>, or <paramref name="sessionState"/> is null.141        /// </exception>142        internal PathInfo(PSDriveInfo drive, ProviderInfo provider, string path, SessionState sessionState)143        {144            if (provider == null)145            {146                throw PSTraceSource.NewArgumentNullException(nameof(provider));147            }148 149            if (path == null)150            {151                throw PSTraceSource.NewArgumentNullException(nameof(path));152            }153 154            if (sessionState == null)155            {156                throw PSTraceSource.NewArgumentNullException(nameof(sessionState));157            }158 159            _drive = drive;160            _provider = provider;161            _path = path;162            _sessionState = sessionState;163        }164    }165}166