当前位置: 首页>>代码示例>>C#>>正文


C# IFileSystemResourceAccessor.GetChildDirectories方法代码示例

本文整理汇总了C#中IFileSystemResourceAccessor.GetChildDirectories方法的典型用法代码示例。如果您正苦于以下问题:C# IFileSystemResourceAccessor.GetChildDirectories方法的具体用法?C# IFileSystemResourceAccessor.GetChildDirectories怎么用?C# IFileSystemResourceAccessor.GetChildDirectories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFileSystemResourceAccessor的用法示例。


在下文中一共展示了IFileSystemResourceAccessor.GetChildDirectories方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetChildDirectories

 /// <summary>
 /// Returns all child directories of the given directory.
 /// </summary>
 /// <remarks>
 /// This will return all native child directories of the given directory together with all virtual child
 /// directories. The native child directories are taken directly from the given <paramref name="directoryAccessor"/>,
 /// the virtual child directories are obtained by taking the root directories of each chained resource provider applied
 /// to the child files of the given directory.
 /// If, for example, the given <paramref name="directoryAccessor"/> contains a child directory "A" and a child
 /// archive file "B" which can work as input for an installed archive provider, providing the root directory "C"
 /// of that archive, this method will return the resource accessors for directories "A" and "C".
 /// </remarks>
 /// <param name="directoryAccessor">Directory resource accessor to get all child directories for.</param>
 /// <param name="showSystemResources">If set to <c>true</c>, system resources like the virtual drives and directories of the
 /// <see cref="IResourceMountingService"/> will also be returned, else removed from the result value.</param>
 /// <returns>Collection of directory accessors for all native and virtual child directories or <c>null</c>,
 /// if the given <paramref name="directoryAccessor"/> does not point to a directory and
 /// if there is no chained resource provider to unfold the given file.</returns>
 public static ICollection<IFileSystemResourceAccessor> GetChildDirectories(IFileSystemResourceAccessor directoryAccessor, bool showSystemResources)
 {
   IResourceMountingService resourceMountingService = ServiceRegistration.Get<IResourceMountingService>();
   IFileSystemResourceAccessor chainedResourceAccesor; // Needed in multiple source locations, that's why we declare it here
   
   // If directoryAccessor points to a directory, we return all actual subdirectories and the virtual subdirectories
   // we can create by using all available ChainedResourceProviders on all contained files.
   if (!directoryAccessor.IsFile)
   {
     ICollection<IFileSystemResourceAccessor> childDirectories = directoryAccessor.GetChildDirectories();
     ICollection<IFileSystemResourceAccessor> result = new List<IFileSystemResourceAccessor>();
     if (childDirectories != null)
       // Directories are maybe filtered and then just added
       foreach (IFileSystemResourceAccessor childDirectoryAccessor in childDirectories)
       {
         if (!showSystemResources && resourceMountingService.IsVirtualResource(childDirectoryAccessor.CanonicalLocalResourcePath))
         {
           childDirectoryAccessor.Dispose();
           continue;
         }
         result.Add(childDirectoryAccessor);
       }
     ICollection<IFileSystemResourceAccessor> files = directoryAccessor.GetFiles();
     if (files != null)
       // For files, we try to chain up chained resource providers
       foreach (IFileSystemResourceAccessor fileAccessor in files)
         using (fileAccessor)
         {
           if (!showSystemResources && resourceMountingService.IsVirtualResource(fileAccessor.CanonicalLocalResourcePath))
             continue;
           if (TryUnfold(fileAccessor, out chainedResourceAccesor))
             if (!chainedResourceAccesor.IsFile)
               result.Add(chainedResourceAccesor);
             else
               chainedResourceAccesor.Dispose();
           // Simply ignore files because we only want to return directories
         }
     return result;
   }
   
   // Try to unfold file resource
   if (TryUnfold(directoryAccessor, out chainedResourceAccesor))
   {
     if (!chainedResourceAccesor.IsFile)
       return new List<IFileSystemResourceAccessor>(new IFileSystemResourceAccessor[] {chainedResourceAccesor});
     chainedResourceAccesor.Dispose();
     return new List<IFileSystemResourceAccessor>();
   }
   return null;
 }
开发者ID:davinx,项目名称:MediaPortal-2,代码行数:68,代码来源:FileSystemResourceNavigator.cs


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