Restored previous attempt at IndexOf(), but it's broken either way
This commit is contained in:
		
							parent
							
								
									059c093ec3
								
							
						
					
					
						commit
						ee6a57b784
					
				
					 4 changed files with 354 additions and 345 deletions
				
			
		| 
						 | 
					@ -289,7 +289,19 @@ namespace Nuclex.Avalonia.Collections {
 | 
				
			||||||
    /// <param name="item">Item whose index will be determined</param>
 | 
					    /// <param name="item">Item whose index will be determined</param>
 | 
				
			||||||
    /// <returns>The index of the item in the list or -1 if not found</returns>
 | 
					    /// <returns>The index of the item in the list or -1 if not found</returns>
 | 
				
			||||||
    public int IndexOf(TItem item) {
 | 
					    public int IndexOf(TItem item) {
 | 
				
			||||||
      return this.typedList.IndexOf(item);
 | 
					      requireCount();
 | 
				
			||||||
 | 
					      requireAllPages();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // TODO: this won't work, it will compare the placeholder items :-/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      IComparer<TItem> itemComparer = Comparer<TItem>.Default;
 | 
				
			||||||
 | 
					      for(int index = 0; index < this.assumedCount.Value; ++index) {
 | 
				
			||||||
 | 
					        if(itemComparer.Compare(this.typedList[index], item) == 0) {
 | 
				
			||||||
 | 
					          return index;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      return -1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// <summary>Inserts an item into the list at the specified index</summary>
 | 
					    /// <summary>Inserts an item into the list at the specified index</summary>
 | 
				
			||||||
| 
						 | 
					@ -344,10 +356,8 @@ namespace Nuclex.Avalonia.Collections {
 | 
				
			||||||
    /// <param name="item">Item the list will be checked for</param>
 | 
					    /// <param name="item">Item the list will be checked for</param>
 | 
				
			||||||
    /// <returns>True if the list contains the specified items</returns>
 | 
					    /// <returns>True if the list contains the specified items</returns>
 | 
				
			||||||
    public bool Contains(TItem item) {
 | 
					    public bool Contains(TItem item) {
 | 
				
			||||||
      requireCount();
 | 
					      // TODO: this won't work, it will compare the placeholder items :-/
 | 
				
			||||||
      requireAllPages();
 | 
					      return (IndexOf(item) != -1);
 | 
				
			||||||
 | 
					 | 
				
			||||||
      return this.typedList.Contains(item);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// <summary>Copies the contents of the list into an array</summary>
 | 
					    /// <summary>Copies the contents of the list into an array</summary>
 | 
				
			||||||
| 
						 | 
					@ -359,14 +369,13 @@ namespace Nuclex.Avalonia.Collections {
 | 
				
			||||||
      requireCount();
 | 
					      requireCount();
 | 
				
			||||||
      requireAllPages();
 | 
					      requireAllPages();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // TODO: this won't work, it will copy the placeholder items :-/
 | 
				
			||||||
      this.typedList.CopyTo(array, arrayIndex);
 | 
					      this.typedList.CopyTo(array, arrayIndex);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// <summary>Total number of items in the list</summary>
 | 
					    /// <summary>Total number of items in the list</summary>
 | 
				
			||||||
    public int Count {
 | 
					    public int Count {
 | 
				
			||||||
      get {
 | 
					      get { return requireCount(); }
 | 
				
			||||||
        return requireCount();
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// <summary>Whether the list is a read-only list</summary>
 | 
					    /// <summary>Whether the list is a read-only list</summary>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue