本文整理匯總了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;
}
示例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;
}