-Rewrote LINQ to JSON internals to use lists and dictionaries rather than a linked list
-Moved JPropertyDescriptor to Newtonsoft.Json.Linq namespace
This commit is contained in:
@@ -631,5 +631,39 @@ namespace Newtonsoft.Json.Utilities
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the index of the first occurrence in a sequence by using the default equality comparer.
|
||||
/// </summary>
|
||||
/// <typeparam name="TSource">The type of the elements of source.</typeparam>
|
||||
/// <param name="list">A sequence in which to locate a value.</param>
|
||||
/// <param name="value">The object to locate in the sequence</param>
|
||||
/// <returns>The zero-based index of the first occurrence of value within the entire sequence, if found; otherwise, –1.</returns>
|
||||
public static int IndexOf<TSource>(this IEnumerable<TSource> list, TSource value) where TSource : IEquatable<TSource>
|
||||
{
|
||||
return list.IndexOf<TSource>(value, EqualityComparer<TSource>.Default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the index of the first occurrence in a sequence by using a specified IEqualityComparer.
|
||||
/// </summary>
|
||||
/// <typeparam name="TSource">The type of the elements of source.</typeparam>
|
||||
/// <param name="list">A sequence in which to locate a value.</param>
|
||||
/// <param name="value">The object to locate in the sequence</param>
|
||||
/// <param name="comparer">An equality comparer to compare values.</param>
|
||||
/// <returns>The zero-based index of the first occurrence of value within the entire sequence, if found; otherwise, –1.</returns>
|
||||
public static int IndexOf<TSource>(this IEnumerable<TSource> list, TSource value, IEqualityComparer<TSource> comparer)
|
||||
{
|
||||
int index = 0;
|
||||
foreach (TSource item in list)
|
||||
{
|
||||
if (comparer.Equals(item, value))
|
||||
{
|
||||
return index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user