本文整理汇总了C#中IEnumerable.LastOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# IEnumerable.LastOrDefault方法的具体用法?C# IEnumerable.LastOrDefault怎么用?C# IEnumerable.LastOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumerable
的用法示例。
在下文中一共展示了IEnumerable.LastOrDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BulkSend
public Task BulkSend(IEnumerable<Marble> items)
{
_marbles.AddRange(items);
if (items.LastOrDefault()?.Kind == NotificationKind.OnCompleted)
_completion.SetResult(null);
else if (items.LastOrDefault()?.Kind == NotificationKind.OnError)
_completion.SetException(new Exception(items.Last().Value.ToString()));
return Task.CompletedTask;
}
示例2: Process
public bool Process(ILogger logger, IEnumerable<string> args, MetaProjectPersistence metaProject, ComponentsList components, string packagesOutputDirectory)
{
// BIG TODO: reengineer command parsing
var componentNamePattern = args.LastOrDefault();
if (componentNamePattern == null || componentNamePattern.StartsWith("-") || componentNamePattern.EndsWith("\"")) {
logger.Error("No component pattern specified");
return true;
}
string tags = args.ParseStringParameter("tags");
string licenseUrl = args.ParseStringParameter("licenseUrl");
string projectUrl = args.ParseStringParameter("projectUrl");
string iconUrl = args.ParseStringParameter("iconUrl");
string copyright = args.ParseStringParameter("copyright");
bool requireLicenseAcceptance = args.Contains("-r");
if (licenseUrl == null && requireLicenseAcceptance) {
logger.Error("Requiring license acceptance demands a license url");
return true;
}
var specificComponent = components.FindComponent<IProject>(componentNamePattern, c => c.CanBecomeNugget);
if (specificComponent == null)
return true;
if (specificComponent.PromoteToNuget(logger, packagesOutputDirectory, tags,
licenseUrl, projectUrl, iconUrl, copyright, requireLicenseAcceptance) != null)
ScanCommand.Rescan(logger, metaProject, components);
return true;
}
示例3: ProcessEventsAsync
public async Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> events)
{
// Workaround for event hub sending null on timeout
events = events ?? Enumerable.Empty<EventData>();
foreach (var eventData in events)
{
var updateTemperatureEvent = JsonConvert.DeserializeObject<UpdateTemperatureEvent>(Encoding.UTF8.GetString(eventData.GetBytes()));
eventData.Properties["BuildingId"] = _buildingLookupService.GetBuildingId(updateTemperatureEvent.DeviceId);
}
if(!await _elasticSearchWriter.WriteAsync(events.ToList(), _token).ConfigureAwait(false))
{
return;
}
try
{
EventData checkpointEventData = events.LastOrDefault();
await context.CheckpointAsync(checkpointEventData);
WarmStorageEventSource.Log.CheckpointCompleted(ProcessorName, _eventHubName, context.Lease.PartitionId, checkpointEventData.Offset);
}
catch (Exception ex)
{
if (!(ex is StorageException || ex is LeaseLostException))
{
throw;
}
WarmStorageEventSource.Log.UnableToCheckpoint(ex, ProcessorName, _eventHubName, context.Lease.PartitionId);
}
}
示例4: Process
public bool Process(ILogger logger, IEnumerable<string> args, MetaProjectPersistence metaProject, ComponentsList components, string packagesOutputDirectory)
{
var nugetNamePattern = args.FirstOrDefault();
if (nugetNamePattern == null || nugetNamePattern.StartsWith("-") || nugetNamePattern.EndsWith("\"")) {
logger.Error("No nuget pattern specified");
return true;
}
var nugetComponent = components.FindComponent<INugetSpec>(nugetNamePattern);
if (nugetComponent == null)
return true;
logger.Info("== Nuget to add: {0}", nugetComponent);
var componentNamePattern = args.LastOrDefault();
if (componentNamePattern == null || componentNamePattern.StartsWith("-") || componentNamePattern.EndsWith("\"")) {
logger.Error("No component pattern specified");
return true;
}
var specificComponent = components.FindComponent<IProject>(componentNamePattern);
if (specificComponent == null)
return true;
logger.Info("== Component to reference nuget: {0}", specificComponent);
if (specificComponent == nugetComponent) {
logger.Error("Nuget can't be added to itself");
return true;
}
specificComponent.AddNuget(logger, nugetComponent, components, packagesOutputDirectory);
return true;
}
示例5: GetTarget
public override Character GetTarget(IEnumerable<Character> targetsList)
{
return targetsList.LastOrDefault(character => (character.Team != this.Team && character.IsAlive));
//var target = targetsList.LastOrDefault(character => (character.Team != this.Team && character.IsAlive));
//return target;
}
示例6: ProcessEventsAsync
public async Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> events)
{
// Workaround for event hub sending null on timeout
events = events ?? Enumerable.Empty<EventData>();
if(!await _elasticSearchWriter.WriteAsync(events.ToList(), _token).ConfigureAwait(false))
{
return;
}
try
{
EventData checkpointEventData = events.LastOrDefault();
await context.CheckpointAsync(checkpointEventData);
WarmStorageEventSource.Log.CheckpointCompleted(ProcessorName, _eventHubName, context.Lease.PartitionId, checkpointEventData.Offset);
}
catch (Exception ex)
{
if (!(ex is StorageException || ex is LeaseLostException))
{
throw;
}
WarmStorageEventSource.Log.UnableToCheckpoint(ex, ProcessorName, _eventHubName, context.Lease.PartitionId);
}
}
示例7: DetermineNodeId
public override int DetermineNodeId(IEnumerable <int> trail)
{
int nodeId = trail.LastOrDefault();
nodeId = Helper.Reverse(nodeId);
return nodeId;
}
示例8: Filter
/// <summary>
/// Filter for the last element in the selection set
/// </summary>
///
/// <param name="selection">
/// The sequence of elements prior to this filter being applied.
/// </param>
///
/// <returns>
/// The last element in the selection.
/// </returns>
public IEnumerable<IDomObject> Filter(IEnumerable<IDomObject> selection)
{
var last = selection.LastOrDefault();
if (last != null)
{
yield return last;
}
}
示例9: MatchesConstraints
public string MatchesConstraints(IEnumerable<string> packageVersions, string versionConstraint,
string branch = null) {
var doVersion = !string.IsNullOrWhiteSpace(versionConstraint);
var doBranch = !string.IsNullOrWhiteSpace(branch);
packageVersions = packageVersions.OrderBy(x => new SpecificVersion("x", x).Version);
if (doBranch) {
return doVersion
? packageVersions.LastOrDefault(
x =>
x.EndsWith("-" + branch) &&
MatchesVersionConstraint(x.Split('-').First(), versionConstraint))
: packageVersions.LastOrDefault(x => x.EndsWith("-" + branch));
}
return doVersion
? packageVersions.LastOrDefault(x => MatchesVersionConstraint(x.Split('-').First(), versionConstraint))
: null;
}
示例10: GetNodes
private static IEnumerable<string> GetNodes(string id, IEnumerable<string[]> lines)
{
var line = lines.LastOrDefault(l => l[0] == id);
if (line == null)
{
return new[] { "_" };
}
var newId = line[3];
return (new[] { id }).Union(GetNodes(newId, lines));
}
示例11: AddRequiredSort
public static IEnumerable<SortingInfo> AddRequiredSort(IEnumerable<SortingInfo> sort, IEnumerable<string> requiredSelectors) {
sort = sort ?? new SortingInfo[0];
requiredSelectors = requiredSelectors.Except(sort.Select(i => i.Selector));
var desc = sort.LastOrDefault()?.Desc;
return sort.Concat(requiredSelectors.Select(i => new SortingInfo {
Selector = i,
Desc = desc != null && desc.Value
}));
}
示例12: LoadsFromHistory
public void LoadsFromHistory(IEnumerable<Event> history)
{
foreach (var e in history)
{
ApplyChange(e, false);
}
var lastEvent = history.LastOrDefault();
if (lastEvent != null)
{
Version = lastEvent.Version;
}
}
示例13: GetClasses
public override IEnumerable<CompletionItem> GetClasses(IEnumerable<string> path, Func<Type, bool> filter)
{
var prefixWithColon = PrefixWithColon;
string contentProperty;
var nodeType = GetNodeType(path.LastOrDefault(), out contentProperty);
var contentType = GetContentType(nodeType, contentProperty);
var types = GetExportedTypes();
if (filter != null)
{
foreach (var result in types.Where(filter))
{
// special case, don't allow windows as a child control
if (contentType != null
&& typeof(Window).IsAssignableFrom(result))
continue;
yield return new CompletionItem
{
Name = prefixWithColon + result.Name,
Description = XmlComments.GetSummary(result),
Type = CompletionType.Class
};
}
}
if (contentType != null
&& !contentType.IsAbstract
&& !types.Contains(contentType)
&& contentType.Assembly == Assembly)
yield return new CompletionItem
{
Name = prefixWithColon + contentType.Name,
Description = XmlComments.GetSummary(contentType),
Type = CompletionType.Class
};
if (nodeType != null)
{
yield return new CompletionItem
{
Name = prefixWithColon + nodeType.Name + ".",
Description = "Add a property tag",
Type = CompletionType.Property
};
}
}
示例14: GetUrlUsingCategoryPathOrCanonical
public string GetUrlUsingCategoryPathOrCanonical(IProduct product, IEnumerable<ICategory> categoryPath)
{
var category = categoryPath.LastOrDefault();
if (category != null && product.Categories.Any(c => c.Id == category.Id))
{
return _categoryCatalogUrlService.GetUrlForPath(categoryPath) + "/" + product.UrlName;
}
category = product.Categories.FirstOrDefault();
// todo: products can get their own url using storeUrl/productUrlName, but resolving and name conflicts need to be fixed
if (category == null)
{
return product.UrlName;
}
return _categoryCatalogUrlService.GetCanonicalUrl(category) + "/" + product.UrlName;
}
示例15: GetFilter
public override Func<Type, bool> GetFilter(IEnumerable<string> path)
{
string propertyName;
var nodeType = GetNodeType(path.LastOrDefault(), out propertyName);
var contentType = GetContentType(nodeType, propertyName);
if (contentType != null)
{
var converter = TypeDescriptor.GetConverter(contentType);
if (converter != null)
{
return t => contentType.IsAssignableFrom(t) || converter.CanConvertFrom(t);
}
else
{
return contentType.IsAssignableFrom;
}
}
return null;
}