當前位置: 首頁>>代碼示例>>C#>>正文


C# StringCollection.OfType方法代碼示例

本文整理匯總了C#中System.Collections.Specialized.StringCollection.OfType方法的典型用法代碼示例。如果您正苦於以下問題:C# StringCollection.OfType方法的具體用法?C# StringCollection.OfType怎麽用?C# StringCollection.OfType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Collections.Specialized.StringCollection的用法示例。


在下文中一共展示了StringCollection.OfType方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: StartSearchAsync

    public async Task<IEnumerable<IMediaFile>> StartSearchAsync(StringCollection filesOrDirsCollection) {
      this.IsWorking = true;
      // create the cancellation token source
      this.cancelToken = new CancellationTokenSource();
      // create the cancellation token
      var token = this.cancelToken.Token;

      this.mainTask = Task<IEnumerable<IMediaFile>>.Factory
        .StartNew(() => {
          var results = new ConcurrentQueue<IMediaFile>();

          // get audio files from input collection
          var rawFiles = filesOrDirsCollection.OfType<string>().Where(this.IsAudioFile).OrderBy(s => s).ToList();
          foreach (var rawFile in rawFiles.TakeWhile(rawDir => !token.IsCancellationRequested)) {
            var mf = this.GetMediaFile(rawFile);
            if (mf != null) {
              results.Enqueue(mf);
            }
          }

          // handle all directories from input collection
          var directories = new List<string>();
          foreach (var source in filesOrDirsCollection.OfType<string>().Except(rawFiles).Where(IsDirectory).TakeWhile(source => !token.IsCancellationRequested)) {
            directories.Add(source);
            try {
              directories.AddRange(Directory.EnumerateDirectories(source, "*", SearchOption.AllDirectories).TakeWhile(dir => !token.IsCancellationRequested));
            } catch (Exception e) {
              // System.UnauthorizedAccessException
              Console.WriteLine(e);
            }
          }
          foreach (var rawDir in directories.Distinct().OrderBy(s => s).TakeWhile(rawDir => !token.IsCancellationRequested)) {
            this.doFindFiles(token, rawDir, results);
          }

          return results;
        }, token, TaskCreationOptions.LongRunning, TaskScheduler.Current);

      var mediaFiles = await this.mainTask;
      this.IsWorking = false;
      return mediaFiles;
    }
開發者ID:dotob,項目名稱:simple-music-player,代碼行數:42,代碼來源:FileSearchWorker.cs

示例2: GetQuerySchema

 internal XmlSchema GetQuerySchema()
 {
     var schema = new XmlSchema {TargetNamespace = QuerySpace};
     schema.Namespaces.Add("", QuerySpace);
     var allParameters = new StringCollection();            
     foreach (var queriesForResourceType in _baseQueries.GroupBy(k => k.ResourceKey)
                                                    .Where(k=>_registrationStorage.IsResourceRegistered(k.Key)))
     {
         
         var group = new XmlSchemaAttributeGroup();
         group.Name = _registrationStorage[queriesForResourceType.Key].ResourceName.Replace(" ", "_");
         var parameters = queriesForResourceType.SelectMany(k => k.Arguments)
                                                .Distinct(_parameterComparer)
                                                .ToArray();
        
         allParameters.AddRange(parameters);
         foreach (var attr in parameters.Select(k => new XmlSchemaAttribute { RefName = new XmlQualifiedName(k, QuerySpace) }))
         {
             group.Attributes.Add(attr);
         }
         schema.Items.Add(group);
     }
    foreach(var attr in allParameters.OfType<string>().Distinct().Select(
         k =>
         new XmlSchemaAttribute
             {
                 Name = k,                        
                 SchemaType = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String)
             }))
    {
        schema.Items.Add(attr);
    }
     
     return schema;
 }
開發者ID:kayanme,項目名稱:Dataspace,代碼行數:35,代碼來源:QueryStorage.cs


注:本文中的System.Collections.Specialized.StringCollection.OfType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。