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


C# IEnumerable.LastOrDefault方法代码示例

本文整理汇总了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;
 }
开发者ID:bnayae,项目名称:VisualRx.DeleteCandidate,代码行数:9,代码来源:TestVisualRxChannel.cs

示例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;
		}
开发者ID:monoman,项目名称:NugetCracker,代码行数:26,代码来源:NugetifyCommand.cs

示例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);
            }
        }
开发者ID:carloserodriguez2000,项目名称:iot-journey,代码行数:34,代码来源:WarmStorageProcessor.cs

示例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;
		}
开发者ID:monoman,项目名称:NugetCracker,代码行数:27,代码来源:AddNugetCommand.cs

示例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;
        }
开发者ID:ZimbakaBe,项目名称:Object-Oriented-Programming,代码行数:7,代码来源:Mage.cs

示例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);
            }
        }
开发者ID:sbidy,项目名称:iot-journey,代码行数:28,代码来源:WarmStorageProcessor.cs

示例7: DetermineNodeId

        public override int DetermineNodeId(IEnumerable <int> trail)
        {
            int nodeId = trail.LastOrDefault();

            nodeId = Helper.Reverse(nodeId);

            return nodeId;
        }
开发者ID:tschroedter,项目名称:Selkie.WPF,代码行数:8,代码来源:EndNodeModel.cs

示例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;
            } 
        }
开发者ID:emrahoner,项目名称:CsQuery,代码行数:20,代码来源:Last.cs

示例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;
        }
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:19,代码来源:DependencyVersionMatcher.cs

示例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));
 }
开发者ID:vadimostanin,项目名称:GA,代码行数:10,代码来源:Program.cs

示例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
            }));
        }
开发者ID:DevExpress,项目名称:DevExtreme.AspNet.Data,代码行数:11,代码来源:Utils.cs

示例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;
            }
        }
开发者ID:icedage,项目名称:CashLady,代码行数:13,代码来源:AggregateRoot.cs

示例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
				};
			}

		}
开发者ID:mhusen,项目名称:Eto,代码行数:49,代码来源:TypeCompletion.cs

示例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;
		}
开发者ID:Chuhukon,项目名称:uWebshop-Releases,代码行数:18,代码来源:CatalogCategoryPlusProductUrlService.cs

示例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;
		}
开发者ID:mhusen,项目名称:Eto,代码行数:19,代码来源:TypeCompletion.cs


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