private static IFileSystem GetFileSystem(string text, out Path path) { if (_providers == null) { throw new InvalidOperationException("The value of 'Services' property is null."); } if (string.IsNullOrWhiteSpace(text)) { throw new ArgumentNullException("text"); } //如果路径解析失败则返回空 if (!Path.TryParse(text, out path)) { return(null); } //如果路径模式为空则返回本地文件系统 if (string.IsNullOrEmpty(path.Schema)) { return(LocalFileSystem.Instance); } var fileSystem = _providers.Resolve <IFileSystem>(path.Schema); if (fileSystem == null) { throw new InvalidOperationException(string.Format("Can not obtain the File or Directory provider by the '{0}' path.", path)); } return(fileSystem); }
private static IFileSystem GetFileSystem(string text, bool throwException, out Path path) { if (throwException) { path = Path.Parse(text); } else if (!Path.TryParse(text, out path)) { return(null); } var scheme = path.Scheme; //如果路径模式为空则使用默认文件系统方案 if (string.IsNullOrEmpty(scheme)) { if (path.Anchor == PathAnchor.Application) { return(LocalFileSystem.Instance); } scheme = FileSystem.Scheme; //如果文件系统模式为空则返回本地文件方案 if (string.IsNullOrEmpty(scheme)) { return(LocalFileSystem.Instance); } } //尝试获取对应的文件系统提供程序 _providers.TryGet(scheme, out var fileSystem); if (fileSystem == null) { if (throwException) { throw new IOException($"Can not obtain the File or Directory provider by the '{text}'."); } return(null); } return(fileSystem); }
private static IFileSystem GetFileSystem(string text, out Path path) { var providers = _providers; if (providers == null) { throw new InvalidOperationException("The value of 'Providers' property is null."); } if (string.IsNullOrWhiteSpace(text)) { throw new ArgumentNullException("text"); } //如果路径解析失败则返回空 if (!Path.TryParse(text, out path)) { return(null); } var scheme = path.Scheme; //如果路径模式为空则使用默认文件系统方案 if (string.IsNullOrWhiteSpace(scheme)) { scheme = FileSystem.Scheme; //如果文件系统模式为空则返回本地文件方案 if (string.IsNullOrWhiteSpace(scheme)) { return(LocalFileSystem.Instance); } } //根据文件系统模式从服务容器中获得对应的文件系统提供程序 var fileSystem = providers.Resolve <IFileSystem>(scheme); if (fileSystem == null) { throw new InvalidOperationException(string.Format("Can not obtain the File or Directory provider by the '{0}'.", text)); } return(fileSystem); }