C# Path.IsPathRooted的代码示例

通过代码示例来学习C# Path.IsPathRooted方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


Path.IsPathRooted是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的Path.IsPathRooted() 已经帮大家高亮显示了,大家可以重点学习Path.IsPathRooted() 方法的写法,从而快速掌握该方法的应用。

Path.IsPathRooted的代码示例1 - GetGitProcess()

    using System.IO;

        public Process GetGitProcess(string command, string workingDirectory, string dotGitDirectory, bool useReadObjectHook, bool redirectStandardError, string gitObjectsDirectory)
        {
            ProcessStartInfo processInfo = new ProcessStartInfo(this.gitBinPath);
            processInfo.WorkingDirectory = workingDirectory;
            processInfo.UseShellExecute = false;
            processInfo.RedirectStandardInput = true;
            processInfo.RedirectStandardOutput = true;
            processInfo.RedirectStandardError = redirectStandardError;
            processInfo.WindowStyle = ProcessWindowStyle.Hidden;
            processInfo.CreateNoWindow = true;

            processInfo.StandardOutputEncoding = UTF8NoBOM;
            processInfo.StandardErrorEncoding = UTF8NoBOM;

            // Removing trace variables that might change git output and break parsing
            // List of environment variables: https://git-scm.com/book/gr/v2/Git-Internals-Environment-Variables
            foreach (string key in processInfo.EnvironmentVariables.Keys.Cast().ToList())
            {
                // If GIT_TRACE is set to a fully-rooted path, then Git sends the trace
                // output to that path instead of stdout (GIT_TRACE=1) or stderr (GIT_TRACE=2).
                if (key.StartsWith("GIT_TRACE", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        if (!Path.IsPathRooted(processInfo.EnvironmentVariables[key]))
                        {
                            processInfo.EnvironmentVariables.Remove(key);
                        }
                    }
                    catch (ArgumentException)
                    {
                        processInfo.EnvironmentVariables.Remove(key);
                    }
                }
            }

            processInfo.EnvironmentVariables["GIT_TERMINAL_PROMPT"] = "0";
            processInfo.EnvironmentVariables["GCM_VALIDATE"] = "0";

            if (gitObjectsDirectory != null)
            {
                processInfo.EnvironmentVariables["GIT_OBJECT_DIRECTORY"] = gitObjectsDirectory;
            }

            if (!useReadObjectHook)
            {
                command = "-c " + GitConfigSetting.CoreVirtualizeObjectsName + "=false " + command;
            }

            if (!string.IsNullOrEmpty(dotGitDirectory))
            {
                command = "--git-dir=\"" + dotGitDirectory + "\" " + command;
            }

            processInfo.Arguments = command;

            Process executingProcess = new Process();
            executingProcess.StartInfo = processInfo;

            return executingProcess;
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:63,代码来源:GitProcess.cs

在GetGitProcess()方法中,Path的代码示例类中的IsPathRooted的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.IsPathRooted的代码示例2 - ProcessTargetPath()

    using System.IO;

        /// 
        /// Processes the target path by splitting path creating nested s on-fly.
        /// 
        /// The target path.
        /// The feature associated with the .
        /// 
        protected Dir ProcessTargetPath(string targetPath, Feature feature)
        {
            Dir currDir = this;

            if (System.IO.Path.IsPathRooted(targetPath))
            {
                this.Name = targetPath;
            }
            else
            {
                //create nested Dirs on-fly
                var nestedDirs = targetPath.Split("\\/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                this.Name = nestedDirs.First();
                for (int i = 1; i < nestedDirs.Length; i++)
                {
                    Dir nextSubDir = new Dir(feature, nestedDirs[i]);
                    nextSubDir.AutoParent = currDir;
                    //currDir.MoveAttributesTo(nextSubDir); //attributes may not be set at this stage
                    currDir.Dirs = new Dir[] { nextSubDir };
                    currDir = nextSubDir;
                }
            }

            return currDir;
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:33,代码来源:Dir.cs

在ProcessTargetPath()方法中,Path的代码示例类中的IsPathRooted的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.IsPathRooted的代码示例3 - GetFiles()

    using System.IO;

        /// 
        /// Analyses  and returns all files matching .
        /// 
        /// The base directory for file analysis. It is used in conjunction with
        /// relative .Though  takes precedence if it is an absolute path.
        /// Array of s.
        public File[] GetFiles(string baseDirectory)
        {
            if (IO.Path.IsPathRooted(Directory))
                baseDirectory = Directory;
            if (baseDirectory.IsEmpty())
                baseDirectory = Environment.CurrentDirectory;

            baseDirectory = IO.Path.GetFullPath(baseDirectory);

            string rootDirPath;
            if (IO.Path.IsPathRooted(Directory))
                rootDirPath = Directory;
            else
                rootDirPath = Utils.PathCombine(baseDirectory, Directory);

            var files = new List();
            var excludeWildcards = new List();

            foreach (string file in IO.Directory.GetFiles(rootDirPath, IncludeMask))
            {
                bool ignore = false;

                if (!ignore && Filter(file))
                {
                    var filePath = IO.Path.GetFullPath(file);

                    var item = new File(filePath)
                    {
                        Feature = this.Feature,
                        Features = this.Features,
                        AttributesDefinition = this.AttributesDefinition,
                        Attributes = this.Attributes.Clone()
                    };

                    OnProcess?.Invoke(item);

                    files.Add(item);
                }
            }
            return files.ToArray();
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:49,代码来源:DirFiles.cs

在GetFiles()方法中,Path的代码示例类中的IsPathRooted的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.IsPathRooted的代码示例4 - GetAllItems()

    using System.IO;

        /// 
        /// Analyses  and returns all files (including subdirectories) matching .
        /// 
        /// The base directory for file analysis. It is used in conjunction with
        /// relative . Though  takes precedence if it is an absolute path.
        /// Array of  instances, which are either  or/and  objects.
        /// Parent Wix# directory
        public WixEntity[] GetAllItems(string baseDirectory, Dir parentWixDir = null)
        {
            if (IO.Path.IsPathRooted(Directory))
                baseDirectory = Directory;
            if (baseDirectory.IsEmpty())
                baseDirectory = Environment.CurrentDirectory;

            baseDirectory = IO.Path.GetFullPath(baseDirectory);

            string rootDirPath;
            if (IO.Path.IsPathRooted(Directory))
                rootDirPath = Directory;
            else
                rootDirPath = Utils.PathCombine(baseDirectory, Directory);

            void AgregateSubDirs(Dir parentDir, string dirPath)
            {
                foreach (var subDirPath in IO.Directory.GetDirectories(dirPath))
                {
                    var dirName = IO.Path.GetFileName(subDirPath);

                    Dir subDir = parentDir.Dirs.FirstOrDefault(dir => dir.Name.SameAs(dirName, ignoreCase: true));

                    if (subDir == null)
                    {
                        subDir = new Dir(dirName);
                        parentDir.AddDir(subDir);
                    }

                    subDir.AddFeatures(this.ActualFeatures);
                    subDir.AddDirFileCollection(
                                                new DirFiles(IO.Path.Combine(subDirPath, this.IncludeMask))
                                                {
                                                    Feature = this.Feature,
                                                    Features = this.Features,
                                                    AttributesDefinition = this.AttributesDefinition,
                                                    Attributes = this.Attributes,
                                                    Filter = this.Filter,
                                                    OnProcess = this.OnProcess
                                                });

                    AgregateSubDirs(subDir, subDirPath);
                }
            };

            var result = new List
            {
                new DirFiles(IO.Path.Combine(rootDirPath, this.IncludeMask))
                {
                    Feature = this.Feature,
                    Features = this.Features,
                    AttributesDefinition = this.AttributesDefinition,
                    Attributes = this.Attributes.Clone(),
                    Filter = this.Filter,
                    OnProcess = this.OnProcess
                }
            };

            if (!IO.Directory.Exists(rootDirPath))
                throw new IO.DirectoryNotFoundException(rootDirPath);

            foreach (var subDirPath in System.IO.Directory.GetDirectories(rootDirPath))
            {
                var dirName = IO.Path.GetFileName(subDirPath);

                var subDir = parentWixDir?.Dirs.FirstOrDefault(dir => dir.Name.SameAs(dirName, ignoreCase: true));

                if (subDir == null)
                {
                    subDir = new Dir(dirName);
                    result.Add(subDir);
                }

                subDir.AddFeatures(this.ActualFeatures);
                subDir.AddDirFileCollection(
                                            new DirFiles(IO.Path.Combine(subDirPath, this.IncludeMask))
                                            {
                                                Feature = this.Feature,
                                                Features = this.Features,
                                                AttributesDefinition = this.AttributesDefinition,
                                                Attributes = this.Attributes,
                                                Filter = this.Filter,
                                                OnProcess = this.OnProcess
                                            });

                AgregateSubDirs(subDir, subDirPath);
            }

            return result.ToArray();
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:99,代码来源:Files.cs

在GetAllItems()方法中,Path的代码示例类中的IsPathRooted的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.IsPathRooted的代码示例5 - AddAssemblyLocation()

    using System.IO;

        public override void AddAssemblyLocation(string filePath)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            if (!Path.IsPathRooted(filePath))
            {
                throw new ArgumentException(nameof(filePath));
            }

            var assemblyName = Path.GetFileNameWithoutExtension(filePath);
            lock (_lock)
            {
                if (!_wellKnownAssemblies.TryGetValue(assemblyName, out var paths))
                {
                    paths = new List();
                    _wellKnownAssemblies.Add(assemblyName, paths);
                }

                if (!paths.Contains(filePath))
                {
                    paths.Add(filePath);
                }
            }
        }
    

开发者ID:aspnet,项目名称:Razor,代码行数:29,代码来源:DefaultExtensionAssemblyLoader.cs

在AddAssemblyLocation()方法中,Path的代码示例类中的IsPathRooted的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.IsPathRooted的代码示例6 - CheckCore()

    using System.IO;

        private bool CheckCore(IEnumerable assemblyFilePaths)
        {
            var items = assemblyFilePaths.Select(a => ExtensionVerificationItem.Create(a)).ToArray();
            var assemblies = new HashSet(items.Select(i => i.Identity));

            for (var i = 0; i < items.Length; i++)
            {
                var item = items[i];
                _output.WriteLine($"Verifying assembly at {item.FilePath}");

                if (!Path.IsPathRooted(item.FilePath))
                {
                    _error.WriteLine($"The file path '{item.FilePath}' is not a rooted path. File paths must be absolute and fully-qualified.");
                    return false;
                }

                foreach (var reference in item.References)
                {
                    if (_ignoredAssemblies.Any(n => reference.Name.StartsWith(n)))
                    {
                        // This is on the allow list, keep going.
                        continue;
                    }

                    if (assemblies.Contains(reference))
                    {
                        // This was also provided as a dependency, keep going.
                        continue;
                    }

                    // If we get here we can't resolve this assembly. This is an error.
                    _error.WriteLine($"Extension assembly '{item.Identity.Name}' depends on '{reference.ToString()} which is missing.");
                    return false;
                }
            }

            // Assuming we get this far, the set of assemblies we have is at least a coherent set (barring
            // version conflicts). Register all of the paths with the loader so they can find each other by
            // name.
            for (var i = 0; i < items.Length; i++)
            {
                _loader.AddAssemblyLocation(items[i].FilePath);
            }

            // Now try to load everything. This has the side effect of resolving all of these items
            // in the loader's caches.
            for (var i = 0; i < items.Length; i++)
            {
                var item = items[i];
                item.Assembly = _loader.LoadFromPath(item.FilePath);
            }

            // Third, check that the MVIDs of the files on disk match the MVIDs of the loaded assemblies.
            for (var i = 0; i < items.Length; i++)
            {
                var item = items[i];
                if (item.Mvid != item.Assembly.ManifestModule.ModuleVersionId)
                {
                    _error.WriteLine($"Extension assembly '{item.Identity.Name}' at '{item.FilePath}' has a different ModuleVersionId than loaded assembly '{item.Assembly.FullName}'");
                    return false;
                }
            }

            return true;
        }
    

开发者ID:aspnet,项目名称:Razor,代码行数:67,代码来源:DefaultExtensionDependencyChecker.cs

在CheckCore()方法中,Path的代码示例类中的IsPathRooted的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.IsPathRooted的代码示例7 - ValidateArguments()

    using System.IO;

        protected override bool ValidateArguments()
        {
            if (string.IsNullOrEmpty(TagHelperManifest.Value()))
            {
                Error.WriteLine($"{TagHelperManifest.Description} must be specified.");
                return false;
            }

            if (Assemblies.Values.Count == 0)
            {
                Error.WriteLine($"{Assemblies.Name} must have at least one value.");
                return false;
            }

            if (string.IsNullOrEmpty(ProjectDirectory.Value()))
            {
                ProjectDirectory.Values.Add(Environment.CurrentDirectory);
            }

            if (string.IsNullOrEmpty(Version.Value()))
            {
                Error.WriteLine($"{Version.Description} must be specified.");
                return false;
            }
            else if (!RazorLanguageVersion.TryParse(Version.Value(), out _))
            {
                Error.WriteLine($"Invalid option {Version.Value()} for Razor language version --version; must be Latest or a valid version in range {RazorLanguageVersion.Version_1_0} to {RazorLanguageVersion.Latest}.");
                return false;
            }

            if (string.IsNullOrEmpty(Configuration.Value()))
            {
                Error.WriteLine($"{Configuration.Description} must be specified.");
                return false;
            }

            if (ExtensionNames.Values.Count != ExtensionFilePaths.Values.Count)
            {
                Error.WriteLine($"{ExtensionNames.Description} and {ExtensionFilePaths.Description} should have the same number of values.");
            }

            foreach (var filePath in ExtensionFilePaths.Values)
            {
                if (!Path.IsPathRooted(filePath))
                {
                    Error.WriteLine($"Extension file paths must be fully-qualified, absolute paths.");
                    return false;
                }
            }

            return true;
        }
    

开发者ID:aspnet,项目名称:Razor,代码行数:54,代码来源:DiscoverCommand.cs

在ValidateArguments()方法中,Path的代码示例类中的IsPathRooted的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.IsPathRooted的代码示例8 - ValidateArguments()

    using System.IO;

        protected override bool ValidateArguments()
        {
            if (Sources.Values.Count == 0)
            {
                Error.WriteLine($"{Sources.Description} should have at least one value.");
                return false;
            }

            if (Outputs.Values.Count != Sources.Values.Count)
            {
                Error.WriteLine($"{Sources.Description} has {Sources.Values.Count}, but {Outputs.Description} has {Outputs.Values.Count} values.");
                return false;
            }

            if (RelativePaths.Values.Count != Sources.Values.Count)
            {
                Error.WriteLine($"{Sources.Description} has {Sources.Values.Count}, but {RelativePaths.Description} has {RelativePaths.Values.Count} values.");
                return false;
            }

            if (DocumentKinds.Values.Count != 0 && DocumentKinds.Values.Count != Sources.Values.Count)
            {
                // 2.x tasks do not specify DocumentKinds - in which case, no values will be present. If a kind for one document is specified, we expect as many kind entries
                // as sources.
                Error.WriteLine($"{Sources.Description} has {Sources.Values.Count}, but {DocumentKinds.Description} has {DocumentKinds.Values.Count} values.");
                return false;
            }

            if (string.IsNullOrEmpty(ProjectDirectory.Value()))
            {
                ProjectDirectory.Values.Add(Environment.CurrentDirectory);
            }

            if (string.IsNullOrEmpty(Version.Value()))
            {
                Error.WriteLine($"{Version.Description} must be specified.");
                return false;
            }
            else if (!RazorLanguageVersion.TryParse(Version.Value(), out _))
            {
                Error.WriteLine($"Invalid option {Version.Value()} for Razor language version --version; must be Latest or a valid version in range {RazorLanguageVersion.Version_1_0} to {RazorLanguageVersion.Latest}.");
                return false;
            }

            if (string.IsNullOrEmpty(Configuration.Value()))
            {
                Error.WriteLine($"{Configuration.Description} must be specified.");
                return false;
            }

            if (ExtensionNames.Values.Count != ExtensionFilePaths.Values.Count)
            {
                Error.WriteLine($"{ExtensionNames.Description} and {ExtensionFilePaths.Description} should have the same number of values.");
            }

            foreach (var filePath in ExtensionFilePaths.Values)
            {
                if (!Path.IsPathRooted(filePath))
                {
                    Error.WriteLine($"Extension file paths must be fully-qualified, absolute paths.");
                    return false;
                }
            }

            return true;
        }
    

开发者ID:aspnet,项目名称:Razor,代码行数:68,代码来源:GenerateCommand.cs

在ValidateArguments()方法中,Path的代码示例类中的IsPathRooted的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

本文中的Path.IsPathRooted方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。