public void Add(T element) { SimpleListItem <T> newItem = new SimpleListItem <T>(element); this.Count++; if (last == null) { this.first = newItem; this.last = newItem; } else { this.last.next = newItem; this.last = newItem; } }
public IEnumerator <T> GetEnumerator() { SimpleListItem <T> current = this .first; while (current != null) { yield return (current.data); current = current.next; } }
public void Add(T element) { SimpleListItem <T> newItem = new SimpleListItem <T>(element); this.Count++; if (last == null) { this.first = newItem; this.last = newItem; } else { //Присоединение элемента к цепочке this.last.next = newItem; //Присоединенный элемент считается последним this.last = newItem; } }
public SimpleListItem <T> GetItem(int number) { if ((number < 0) || (number >= this.Count)) { throw new Exception ( "Выход за границу индекса" ); } SimpleListItem <T> current = this.first; int i = 0; while (i < number) { current = current.next; i++; } return(current); }
public void SimpleList_FindItemAtPosition(string input, int position, string expectedItemValue) { SimpleList list = MSBuildExpression.ParseSimpleList(input); DumpList(list, input); SimpleListItem actualItem = list.FindItemAt(position); Assert.NotNull(actualItem); Assert.Equal(expectedItemValue, actualItem.Value); string actualInput = input.Substring( startIndex: actualItem.AbsoluteStart, length: actualItem.AbsoluteEnd - actualItem.AbsoluteStart ); Assert.Equal(expectedItemValue, actualInput); }
public SimpleListItem <T> GetItem(int number) { if ((number < 0) || (number >= this.Count)) { //Можно создать собственный класс исключения throw new Exception("Выход за границу индекса"); } SimpleListItem <T> current = this.first; int i = 0; //Пропускаем нужное количество элементов while (i < number) { //Переход к следующему элементу current = current.next; //Увеличение счетчика i++; } return(current); }
public T Pop() { T Result = default(T); if (this.Count == 0) { return(Result); } if (this.Count == 1) { Result = this.first.data; this.first = null; this.last = null; } else { SimpleListItem <T> newLast = this.GetItem(this.Count - 2); Result = newLast.next.data; this.last = newLast; newLast = null; } this.Count--; return(Result); }
public T Pop() { T result = default(T); if (Count == 0) { return(result); } if (Count == 1) { result = first.data; first.next = null; last.next = null; } else { SimpleListItem <T> newlast = GetItem(Count - 2); result = newlast.next.data; last = newlast; newlast.next = null; } Count--; return(result); }
public override DataTemplate SelectTemplate(object item, DependencyObject container) { DataTemplate template = null; if (item != null) { SimpleListItem richItem = (SimpleListItem)item; switch (richItem.ItemTemplate) { case WeatherItemTemplate.WI_TEMPLATE_SPACE: template = SpaceItem; break; case WeatherItemTemplate.WI_TEMPLATE_SEPARATOR: template = SeparatorItem; break; case WeatherItemTemplate.WI_TEMPLATE_SIMPLE: template = SimpleItem; break; case WeatherItemTemplate.WI_TEMPLATE_SMALL_ICON: template = SmallIconItem; break; case WeatherItemTemplate.WI_TEMPLATE_LARGE_ICON: template = LargeIconItem; break; case WeatherItemTemplate.WI_TEMPLATE_AREA: template = AreaItem; break; case WeatherItemTemplate.WI_TEMPLATE_OBS: template = OBSItem; break; case WeatherItemTemplate.WI_TEMPLATE_WEEK: template = WeekItem; break; case WeatherItemTemplate.WI_TEMPLATE_SEA: template = SeaItem; break; case WeatherItemTemplate.WI_TEMPLATE_NEARSEA: template = NearSeaItem; break; case WeatherItemTemplate.WI_TEMPLATE_TIDE: template = TideItem; break; case WeatherItemTemplate.WI_TEMPLATE_GLOBAL: template = GlobalItem; break; } return(template); } return(base.SelectTemplate(item, container)); }
public int AddSimpleListItem(SimpleListItem simpleListItem) { _simpleListEntities.SimpleListItems.Add(simpleListItem); return(_simpleListEntities.SaveChanges()); }
/// <summary> /// Provide completions for the specified location. /// </summary> /// <param name="location"> /// The <see cref="XmlLocation"/> where completions are requested. /// </param> /// <param name="projectDocument"> /// The <see cref="ProjectDocument"/> that contains the <paramref name="location"/>. /// </param> /// <param name="cancellationToken"> /// A <see cref="CancellationToken"/> that can be used to cancel the operation. /// </param> /// <returns> /// A <see cref="Task{TResult}"/> that resolves either a <see cref="CompletionList"/>s, or <c>null</c> if no completions are provided. /// </returns> public override async Task <CompletionList> ProvideCompletions(XmlLocation location, ProjectDocument projectDocument, CancellationToken cancellationToken = default(CancellationToken)) { if (location == null) { throw new ArgumentNullException(nameof(location)); } if (projectDocument == null) { throw new ArgumentNullException(nameof(projectDocument)); } Log.Verbose("Evaluate completions for {XmlLocation:l}", location); List <CompletionItem> completions = new List <CompletionItem>(); using (await projectDocument.Lock.ReaderLockAsync()) { XSAttribute attribute; if (!location.CanCompleteAttributeValue(out attribute, onElementWithPath: WellKnownElementPaths.Target) || !SupportedAttributeNames.Contains(attribute.Name)) { Log.Verbose("Not offering any completions for {XmlLocation:l} (not the value of a supported attribute on a 'Target' element).", location); return(null); } Range targetRange = attribute.ValueRange; HashSet <string> excludeTargetNames = new HashSet <string>(); // Handle potentially composite (i.e. "Value1;Value2;Value3") values, where it's legal to have them. if (attribute.Name != "Name" && attribute.Value.IndexOf(';') != -1) { int startPosition = projectDocument.XmlPositions.GetAbsolutePosition(attribute.ValueRange.Start); int relativePosition = location.AbsolutePosition - startPosition; SimpleList list = MSBuildExpression.ParseSimpleList(attribute.Value); SimpleListItem itemAtPosition = list.FindItemAt(relativePosition); if (itemAtPosition == null) { return(null); } Log.Verbose("Completions will replace item {ItemValue} spanning [{ItemStartPosition}..{ItemEndPosition}) in MSBuild simple list expression {ListExpression}.", itemAtPosition.Value, itemAtPosition.AbsoluteStart, itemAtPosition.AbsoluteEnd, attribute.Value ); targetRange = projectDocument.XmlPositions.GetRange( absoluteStartPosition: startPosition + itemAtPosition.AbsoluteStart, absoluteEndPosition: startPosition + itemAtPosition.AbsoluteEnd ); } completions.AddRange( GetCompletionItems(projectDocument, targetRange, excludeTargetNames) ); } if (completions.Count == 0) { return(null); // No completions provided. } Log.Verbose("Offering {CompletionCount} completion(s) for {XmlLocation:l}", completions.Count, location); return(new CompletionList(completions, isIncomplete: false // Consider this list to be exhaustive )); }
private void HandleExploreItemSelected(SimpleListItem item) { Uri uriExplore = UtilityHelper.GetExplorePageURL(item.Title, item.URL, item.ItemType, item.SubItemTemplate); NavigationService.Navigate(uriExplore); }
static SimpleListItem[] ParseSimpleList(string pageContent) { List<SimpleListItem> listItems = new List<SimpleListItem>(); var listMatch = ListRegex.Match(pageContent); if(!listMatch.Success) return null; var listMatches = SimpleListContentRegex.Matches(listMatch.Groups["content"].Value); foreach(Match curMatch in listMatches) { SimpleListItem newListItem = new SimpleListItem() { Link = curMatch.Groups["link"].Value, Name = curMatch.Groups["name"].Value}; listItems.Add(newListItem); } return listItems.ToArray(); }