本文整理汇总了C#中IList.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# IList.OfType方法的具体用法?C# IList.OfType怎么用?C# IList.OfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IList
的用法示例。
在下文中一共展示了IList.OfType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindMatchingItems
// This behavior is case sensitive
public override IEnumerable<object> FindMatchingItems(string searchText, IList items, IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode)
{
var strings = searchText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (strings.Length == 0)
{
return base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode);
}
string name = string.Empty;
string capital = string.Empty;
if (strings.Length > 0)
{
name = strings[0];
}
if (strings.Length > 1)
{
capital = strings[1].TrimStart(' ');
}
IEnumerable<object> results = null;
if (textSearchMode == TextSearchMode.Contains)
{
results = items.OfType<Country>().Where(x => x.Name.Contains(name) && x.Capital.Contains(capital));
}
else
{
results = items.OfType<Country>().Where(x => x.Name.StartsWith(name) && x.Capital.StartsWith(capital));
}
return results.Where(x => !escapedItems.Contains(x));
}
示例2: ShouldHumanize
private static bool ShouldHumanize(ModelMetadata modelMetadata, IList<Attribute> propertyAttributes)
{
if (string.IsNullOrEmpty(modelMetadata.PropertyName))
return false;
if (propertyAttributes.OfType<DisplayNameAttribute>().Any())
return false;
if (propertyAttributes.OfType<DisplayAttribute>().Any())
return false;
return true;
}
示例3: IsTransformRequired
private static bool IsTransformRequired(ModelMetadata modelMetadata, IList<Attribute> propertyAttributes)
{
if (string.IsNullOrEmpty(modelMetadata.PropertyName))
return false;
if (propertyAttributes.OfType<DisplayNameAttribute>().Any())
return false;
if (propertyAttributes.OfType<DisplayAttribute>().Any())
return false;
return true;
}
示例4: CopyRequestHeaders
/// <summary>
/// Copies HTTP Request Headers from parent request to all requests from multi-part child requests.
/// This fixes a problem where content negotiation does not work correctly and JSON is always returned
/// even when the client expects xml+atom.
/// </summary>
public virtual void CopyRequestHeaders(HttpRequestMessage request, IList<ODataBatchRequestItem> items)
{
var requests =
items.OfType<OperationRequestItem>().Select(o => o.Request)
.Union(items.OfType<ChangeSetRequestItem>().SelectMany(cs => cs.Requests));
foreach (var childRequest in requests)
{
foreach (var header in request.Headers)
{
childRequest.Headers.Add(header.Key, request.Headers.GetValues(header.Key));
}
}
}
示例5: ListPickerBox
protected ListPickerBox(IList items, IList selectedItems, bool singleSelection, string _title, bool minOneSelected = true, bool showSelectAllButton = false)
{
InitializeComponent();
this.minOneSelected = minOneSelected;
if (string.IsNullOrEmpty(_title))
title.Visibility = Visibility.Collapsed;
else
title.Text = _title;
if (selectedItems == null)
selectedItems = new List<object>();
SelectAllButton.Visibility = showSelectAllButton ? Visibility.Visible : Visibility.Collapsed;
list.ItemTemplate = (DataTemplate)(singleSelection ? Resources["singleTemplate"] : Resources["multipleTemplate"]);
OriginalSelectedItems = selectedItems;
Dispatcher.BeginInvoke(delegate
{
Items = items.OfType<object>().
Select(i => new ListPickerBoxItem { Item = i, IsChecked = selectedItems.Contains(i) }).
ToList();
UpdateSelectedItems();
UpdateSelectAllButton();
list.ItemsSource = Items;
});
}
示例6: GetDependentVariables
/// <summary>
/// Creates a dictionary describing argument based dependencies for the given list of functions.
/// </summary>
/// <param name="functions"></param>
/// <returns></returns>
public static IDictionary<IVariable, IEnumerable<IVariable>> GetDependentVariables(IList<IFunction> functions)
{
var result = new Dictionary<IVariable, IEnumerable<IVariable>>();
var variables = functions.OfType<IVariable>();
foreach (var variable in variables)
{
var variable1 = variable;
result[variable] = functions.OfType<IVariable>()
.Where(variable2 => variable2.Arguments.Contains(variable1))
.ToList();
}
return result;
}
示例7: ClassDefinition
public ClassDefinition(Token classToken, Token nameToken, Token baseClassToken, IList<Executable> members)
: base(classToken)
{
this.NameToken = nameToken;
this.BaseClassToken = baseClassToken;
this.Members = members.OfType<FunctionDefinition>().ToArray();
}
示例8: StartSearchAsync
public async Task<IEnumerable<IMediaFile>> StartSearchAsync(IList 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.AddRange(GetSubFolders(token, source));
}
var orderedDirs = directories.Distinct().OrderBy(s => s);
this.Log().Debug("search for files in {0} directories (sub directories included)", orderedDirs.Count());
foreach (var rawDir in orderedDirs.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;
}
示例9: Render
protected override void Render(IList<IBaseTexture> inputs)
{
var texture = inputs.OfType<ITexture2D>().SingleOrDefault();
if (texture == null)
return;
Render(texture);
}
示例10: CompiledFilter
public CompiledFilter(MIA_Management miaManagement, IFilter filter, Namespace ns, BindVarNamespace bvNamespace, string outerMIIDJoinVariable, ICollection<TableJoin> tableJoins)
{
_statementParts = new List<object>();
_statementBindVars = new List<BindVar>();
_requiredMIATypes = new List<MediaItemAspectMetadata>();
CompileStatementParts(miaManagement, filter, ns, bvNamespace, _requiredMIATypes, outerMIIDJoinVariable, tableJoins,
_statementParts, _statementBindVars);
_requiredAttributes = _statementParts.OfType<QueryAttribute>().ToList();
}
示例11: CopyRequestHeadersToBatchItems
/// <summary>
/// OData does not copy headers from the main request to the batch sub-request. Let's do it here...
/// </summary>
public virtual void CopyRequestHeadersToBatchItems(HttpRequestMessage request, IList<ODataBatchRequestItem> items)
{
var batchRequests = items
.OfType<OperationRequestItem>().Select(o => o.Request)
.Union(items.OfType<ChangeSetRequestItem>().SelectMany(cs => cs.Requests));
foreach (var batchRequest in batchRequests)
{
foreach (var header in request.Headers)
{
if (String.Equals(header.Key, DataServiceVersionHeader, StringComparison.OrdinalIgnoreCase) ||
String.Equals(header.Key, MaxDataServiceVersionHeader, StringComparison.OrdinalIgnoreCase))
{
batchRequest.Headers.Add(header.Key, request.Headers.GetValues(header.Key));
}
}
}
}
开发者ID:ZhiYuanHuang,项目名称:NuGetGallery,代码行数:21,代码来源:ODataServiceVersionHeaderPropagatingBatchHandler.cs
示例12: GetDevice
protected static Device GetDevice(IList<ICallCopyEntity> callCopyEntities)
{
Device device = callCopyEntities.OfType<Device>().FirstOrDefault();
if (device == null)
{
device = new Device {Name = "Placeholder", DeviceType = "Placeholder"};
callCopyEntities.Add(device);
}
return device;
}
示例13: StartSearchAsync
public async Task<IEnumerable<IMediaFile>> StartSearchAsync(IList 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;
}
示例14: IndexerNode
public IndexerNode(IList<object> arguments)
{
Arguments = arguments;
var intArgs = Arguments.OfType<int>().ToArray();
if (intArgs.Length == arguments.Count)
{
_intArgs = intArgs;
}
}
示例15: SelectClauseHandler
public SelectClauseHandler(SelectClause clause)
{
_references = clause.Columns.ToList();
_resolvers = _references.Select(ValueResolver.Create).ToList();
if (_resolvers.OfType<AggregateValueResolver>().Any())
{
_groupingHandler =
new GroupingHandler(
_references.Where(ReferenceIsNotAggregateFunction).Select(r => r.GetAliasOrName()).ToArray());
}
}