Update dependencies (#10)

Fix code style
This commit is contained in:
2021-09-16 13:56:05 +02:00
committed by GitHub
parent d20e5bd308
commit 57925151fa
28 changed files with 378 additions and 256 deletions
@@ -6,7 +6,7 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile> <PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> <PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Version>1.1.2</Version> <Version>1.1.3</Version>
<Authors>Alexandru Macocian</Authors> <Authors>Alexandru Macocian</Authors>
<RepositoryUrl>https://github.com/AlexMacocian/SystemExtensions</RepositoryUrl> <RepositoryUrl>https://github.com/AlexMacocian/SystemExtensions</RepositoryUrl>
</PropertyGroup> </PropertyGroup>
@@ -21,8 +21,8 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.CorrelationVector" Version="1.0.42" /> <PackageReference Include="Microsoft.CorrelationVector" Version="1.0.42" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Slim" Version="1.5.1" /> <PackageReference Include="Slim" Version="1.5.2" />
<PackageReference Include="SystemExtensions.NetStandard" Version="1.3.0" /> <PackageReference Include="SystemExtensions.NetStandard" Version="1.3.1" />
</ItemGroup> </ItemGroup>
</Project> </Project>
@@ -77,16 +77,16 @@ namespace SystemExtensions.NetStandard.Security.Encryption
public async Task<Stream> Encrypt(string key, string iv, Stream value) public async Task<Stream> Encrypt(string key, string iv, Stream value)
{ {
if (value is null) throw new ArgumentNullException(nameof(value)); return value is null
? throw new ArgumentNullException(nameof(value))
return await EncryptInternal(StringToBytes(key), StringToBytes(iv), value).ConfigureAwait(false); : await EncryptInternal(StringToBytes(key), StringToBytes(iv), value).ConfigureAwait(false);
} }
public async Task<Stream> Encrypt(byte[] key, byte[] iv, Stream value) public async Task<Stream> Encrypt(byte[] key, byte[] iv, Stream value)
{ {
if (value is null) throw new ArgumentNullException(nameof(value)); return value is null
? throw new ArgumentNullException(nameof(value))
return await EncryptInternal(key, iv, value).ConfigureAwait(false); : await EncryptInternal(key, iv, value).ConfigureAwait(false);
} }
public Stream GetEncryptionStream(string key, string iv, Stream outStream) public Stream GetEncryptionStream(string key, string iv, Stream outStream)
@@ -112,9 +112,9 @@ namespace SystemExtensions.NetStandard.Security.Encryption
private static byte[] StreamToBytes(Stream value) private static byte[] StreamToBytes(Stream value)
{ {
value.Position = 0; value.Position = 0;
byte[] buffer = new byte[1024]; var buffer = new byte[1024];
using var ms = new MemoryStream(); using var ms = new MemoryStream();
int read = -1; var read = -1;
do do
{ {
read = value.Read(buffer, 0, buffer.Length); read = value.Read(buffer, 0, buffer.Length);
@@ -47,20 +47,33 @@ namespace System.Encryption
public static implicit operator SecureString(string s) => new(s); public static implicit operator SecureString(string s) => new(s);
public static SecureString operator +(SecureString ss1, SecureString ss2) public static SecureString operator +(SecureString ss1, SecureString ss2)
{ {
if (ss1 is null) throw new ArgumentNullException(nameof(ss1)); if (ss1 is null)
if (ss2 is null) throw new ArgumentNullException(nameof(ss2)); {
throw new ArgumentNullException(nameof(ss1));
}
if (ss2 is null)
{
throw new ArgumentNullException(nameof(ss2));
}
return new SecureString(ss1.Value + ss2.Value); return new SecureString(ss1.Value + ss2.Value);
} }
public static SecureString operator +(SecureString ss1, string s2) public static SecureString operator +(SecureString ss1, string s2)
{ {
if (ss1 is null) throw new ArgumentNullException(nameof(ss1)); if (ss1 is null)
{
throw new ArgumentNullException(nameof(ss1));
}
return new SecureString(ss1.Value + s2); return new SecureString(ss1.Value + s2);
} }
public static SecureString operator +(SecureString ss1, char c) public static SecureString operator +(SecureString ss1, char c)
{ {
if (ss1 is null) throw new ArgumentNullException(nameof(ss1)); if (ss1 is null)
{
throw new ArgumentNullException(nameof(ss1));
}
return new SecureString(ss1.Value + c); return new SecureString(ss1.Value + c);
} }
@@ -27,9 +27,9 @@ namespace SystemExtensions.NetStandard.Security.Hashing
private static byte[] StreamToBytes(Stream value) private static byte[] StreamToBytes(Stream value)
{ {
value.Position = 0; value.Position = 0;
byte[] buffer = new byte[1024]; var buffer = new byte[1024];
using var ms = new MemoryStream(); using var ms = new MemoryStream();
int read = -1; var read = -1;
do do
{ {
read = value.Read(buffer, 0, buffer.Length); read = value.Read(buffer, 0, buffer.Length);
@@ -51,7 +51,10 @@ namespace SystemExtensions.NetStandard.Security.Hashing
} }
private static async Task<Stream> HashInternal(Stream raw) private static async Task<Stream> HashInternal(Stream raw)
{ {
if (raw is null) throw new ArgumentNullException(nameof(raw)); if (raw is null)
{
throw new ArgumentNullException(nameof(raw));
}
using var sha256 = SHA256.Create(); using var sha256 = SHA256.Create();
return await Task.Run(() => new MemoryStream(sha256.ComputeHash(raw))); return await Task.Run(() => new MemoryStream(sha256.ComputeHash(raw)));
@@ -13,7 +13,9 @@ namespace SystemExtensions.NetStandard.Security.Utilities
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (!this.HasFlushedFinalBlock) if (!this.HasFlushedFinalBlock)
{
this.FlushFinalBlock(); this.FlushFinalBlock();
}
base.Dispose(false); base.Dispose(false);
} }
@@ -60,7 +60,7 @@ namespace System.Collections.Generic
public void Add(T value) public void Add(T value)
{ {
count++; count++;
AVLNode<T> newItem = new AVLNode<T>(value); var newItem = new AVLNode<T>(value);
if (root == null) if (root == null)
{ {
root = newItem; root = newItem;
@@ -77,7 +77,7 @@ namespace System.Collections.Generic
/// <returns>True if the value is in the tree.</returns> /// <returns>True if the value is in the tree.</returns>
public bool Contains(T value) public bool Contains(T value)
{ {
AVLNode<T> node = Find(value, root); var node = Find(value, root);
if (node == null) if (node == null)
{ {
return false; return false;
@@ -105,12 +105,12 @@ namespace System.Collections.Generic
/// </summary> /// </summary>
public void Clear() public void Clear()
{ {
Queue<AVLNode<T>> queue = new Queue<AVLNode<T>>(); var queue = new Queue<AVLNode<T>>();
queue.Enqueue(root); queue.Enqueue(root);
while (queue.Count > 0) while (queue.Count > 0)
{ {
AVLNode<T> currentNode = queue.Dequeue(); var currentNode = queue.Dequeue();
if (currentNode.Left != null) if (currentNode.Left != null)
{ {
queue.Enqueue(currentNode.Left); queue.Enqueue(currentNode.Left);
@@ -134,11 +134,11 @@ namespace System.Collections.Generic
/// <param name="arrayIndex">Starting index of the provided array.</param> /// <param name="arrayIndex">Starting index of the provided array.</param>
public void CopyTo(T[] array, int arrayIndex) public void CopyTo(T[] array, int arrayIndex)
{ {
Queue<AVLNode<T>> queue = new Queue<AVLNode<T>>(); var queue = new Queue<AVLNode<T>>();
queue.Enqueue(root); queue.Enqueue(root);
while (queue.Count > 0) while (queue.Count > 0)
{ {
AVLNode<T> currentNode = queue.Dequeue(); var currentNode = queue.Dequeue();
array[arrayIndex++] = currentNode.Value; array[arrayIndex++] = currentNode.Value;
if (currentNode.Left != null) if (currentNode.Left != null)
{ {
@@ -164,7 +164,7 @@ namespace System.Collections.Generic
/// <returns>Array containing the values contained in the tree.</returns> /// <returns>Array containing the values contained in the tree.</returns>
public T[] ToArray() public T[] ToArray()
{ {
T[] array = new T[count]; var array = new T[count];
CopyTo(array, 0); CopyTo(array, 0);
return array; return array;
} }
@@ -191,7 +191,7 @@ namespace System.Collections.Generic
} }
private AVLNode<T> BalanceTree(AVLNode<T> current) private AVLNode<T> BalanceTree(AVLNode<T> current)
{ {
int b_factor = BalanceFactor(current); var b_factor = BalanceFactor(current);
if (b_factor > 1) if (b_factor > 1)
{ {
if (BalanceFactor(current.Left) > 0) if (BalanceFactor(current.Left) > 0)
@@ -299,7 +299,9 @@ namespace System.Collections.Generic
return current; return current;
} }
else else
{
return Find(target, current.Left); return Find(target, current.Left);
}
} }
else else
{ {
@@ -308,7 +310,9 @@ namespace System.Collections.Generic
return current; return current;
} }
else else
{
return Find(target, current.Right); return Find(target, current.Right);
}
} }
} }
@@ -318,46 +322,46 @@ namespace System.Collections.Generic
} }
private int GetHeight(AVLNode<T> current) private int GetHeight(AVLNode<T> current)
{ {
int height = 0; var height = 0;
if (current != null) if (current != null)
{ {
int l = GetHeight(current.Left); var l = GetHeight(current.Left);
int r = GetHeight(current.Right); var r = GetHeight(current.Right);
int m = Max(l, r); var m = Max(l, r);
height = m + 1; height = m + 1;
} }
return height; return height;
} }
private int BalanceFactor(AVLNode<T> current) private int BalanceFactor(AVLNode<T> current)
{ {
int l = GetHeight(current.Left); var l = GetHeight(current.Left);
int r = GetHeight(current.Right); var r = GetHeight(current.Right);
int b_factor = l - r; var b_factor = l - r;
return b_factor; return b_factor;
} }
private AVLNode<T> RotateRR(AVLNode<T> parent) private AVLNode<T> RotateRR(AVLNode<T> parent)
{ {
AVLNode<T> pivot = parent.Right; var pivot = parent.Right;
parent.Right = pivot.Left; parent.Right = pivot.Left;
pivot.Left = parent; pivot.Left = parent;
return pivot; return pivot;
} }
private AVLNode<T> RotateLL(AVLNode<T> parent) private AVLNode<T> RotateLL(AVLNode<T> parent)
{ {
AVLNode<T> pivot = parent.Left; var pivot = parent.Left;
parent.Left = pivot.Right; parent.Left = pivot.Right;
pivot.Right = parent; pivot.Right = parent;
return pivot; return pivot;
} }
private AVLNode<T> RotateLR(AVLNode<T> parent) private AVLNode<T> RotateLR(AVLNode<T> parent)
{ {
AVLNode<T> pivot = parent.Left; var pivot = parent.Left;
parent.Left = RotateRR(pivot); parent.Left = RotateRR(pivot);
return RotateLL(parent); return RotateLL(parent);
} }
private AVLNode<T> RotateRL(AVLNode<T> parent) private AVLNode<T> RotateRL(AVLNode<T> parent)
{ {
AVLNode<T> pivot = parent.Right; var pivot = parent.Right;
parent.Right = RotateLL(pivot); parent.Right = RotateLL(pivot);
return RotateRR(parent); return RotateRR(parent);
} }
@@ -367,12 +371,12 @@ namespace System.Collections.Generic
} }
private IEnumerator<T> GetEnumerator(AVLNode<T> rootNode) private IEnumerator<T> GetEnumerator(AVLNode<T> rootNode)
{ {
Queue<AVLNode<T>> queue = new Queue<AVLNode<T>>(); var queue = new Queue<AVLNode<T>>();
queue.Enqueue(rootNode); queue.Enqueue(rootNode);
while (queue.Count > 0) while (queue.Count > 0)
{ {
AVLNode<T> currentNode = queue.Dequeue(); var currentNode = queue.Dequeue();
yield return currentNode.Value; yield return currentNode.Value;
if (currentNode.Left != null) if (currentNode.Left != null)
{ {
@@ -88,7 +88,7 @@ namespace System.Collections.Generic
{ {
Capacity = 2 * Capacity; Capacity = 2 * Capacity;
} }
int position = ++count; var position = ++count;
for (; position > 1 && value.CompareTo(items[position / 2]) < 0; position /= 2) for (; position > 1 && value.CompareTo(items[position / 2]) < 0; position /= 2)
{ {
items[position] = items[position / 2]; items[position] = items[position / 2];
@@ -105,7 +105,7 @@ namespace System.Collections.Generic
{ {
throw new IndexOutOfRangeException("Heap is empty!"); throw new IndexOutOfRangeException("Heap is empty!");
} }
T min = items[1]; var min = items[1];
items[1] = items[count--]; items[1] = items[count--];
BubbleDown(1); BubbleDown(1);
return min; return min;
@@ -120,7 +120,7 @@ namespace System.Collections.Generic
{ {
throw new IndexOutOfRangeException("Heap is empty!"); throw new IndexOutOfRangeException("Heap is empty!");
} }
T min = items[1]; var min = items[1];
return min; return min;
} }
/// <summary> /// <summary>
@@ -129,7 +129,7 @@ namespace System.Collections.Generic
/// <returns>Array with values sorted as in heap</returns> /// <returns>Array with values sorted as in heap</returns>
public T[] ToArray() public T[] ToArray()
{ {
T[] newArray = new T[count]; var newArray = new T[count];
Array.Copy(items, 1, newArray, 0, count); Array.Copy(items, 1, newArray, 0, count);
return newArray; return newArray;
} }
@@ -168,7 +168,7 @@ namespace System.Collections.Generic
/// <returns>Enumerator that iterates over the heap.</returns> /// <returns>Enumerator that iterates over the heap.</returns>
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
for (int i = 0; i < count; i++) for (var i = 0; i < count; i++)
{ {
yield return items[i + 1]; yield return items[i + 1];
} }
@@ -181,7 +181,7 @@ namespace System.Collections.Generic
/// <param name="index">Index of element to bubble</param> /// <param name="index">Index of element to bubble</param>
private void BubbleDown(int index) private void BubbleDown(int index)
{ {
T temp = items[index]; var temp = items[index];
int childIndex; int childIndex;
for (; 2 * index <= count; index = childIndex) for (; 2 * index <= count; index = childIndex)
{ {
@@ -49,7 +49,7 @@
/// <param name="value">Value to be added.</param> /// <param name="value">Value to be added.</param>
public void Add(T value) public void Add(T value)
{ {
FibonacciNode<T> node = new FibonacciNode<T> var node = new FibonacciNode<T>
{ {
Value = value, Value = value,
Marked = false, Marked = false,
@@ -77,7 +77,7 @@
/// <returns>Minimum value.</returns> /// <returns>Minimum value.</returns>
public T Remove() public T Remove()
{ {
FibonacciNode<T> currentRoot = root; var currentRoot = root;
if (currentRoot != null) if (currentRoot != null)
{ {
root = RemoveMinimum(root); root = RemoveMinimum(root);
@@ -96,7 +96,7 @@
/// <param name="value">New value to be assigned to the node.</param> /// <param name="value">New value to be assigned to the node.</param>
public void DecreaseKey(T oldValue, T value) public void DecreaseKey(T oldValue, T value)
{ {
FibonacciNode<T> node = Find(root, oldValue); var node = Find(root, oldValue);
root = DecreaseKey(root, node, value); root = DecreaseKey(root, node, value);
} }
/// <summary> /// <summary>
@@ -129,7 +129,7 @@
{ {
return null; return null;
} }
T[] array = new T[count]; var array = new T[count];
if (count == 1) if (count == 1)
{ {
array[0] = root.Value; array[0] = root.Value;
@@ -137,7 +137,7 @@
} }
else else
{ {
int index = 0; var index = 0;
RecursiveFillArray(root, ref array, ref index); RecursiveFillArray(root, ref array, ref index);
return array; return array;
} }
@@ -160,7 +160,7 @@
/// <param name="index">Index of the next unintialized element in the array.</param> /// <param name="index">Index of the next unintialized element in the array.</param>
private void RecursiveFillArray(FibonacciNode<T> currentNode, ref T[] array, ref int index) private void RecursiveFillArray(FibonacciNode<T> currentNode, ref T[] array, ref int index)
{ {
FibonacciNode<T> oldNode = currentNode; var oldNode = currentNode;
do do
{ {
array[index] = currentNode.Value; array[index] = currentNode.Value;
@@ -178,12 +178,12 @@
/// <param name="currentNode">Current node in the iteration.</param> /// <param name="currentNode">Current node in the iteration.</param>
private IEnumerator<T> GetEnumerator(FibonacciNode<T> currentNode) private IEnumerator<T> GetEnumerator(FibonacciNode<T> currentNode)
{ {
Queue<FibonacciNode<T>> queue = new Queue<FibonacciNode<T>>(); var queue = new Queue<FibonacciNode<T>>();
queue.Enqueue(currentNode); queue.Enqueue(currentNode);
while (queue.Count > 0) while (queue.Count > 0)
{ {
currentNode = queue.Dequeue(); currentNode = queue.Dequeue();
FibonacciNode<T> oldNode = currentNode; var oldNode = currentNode;
do do
{ {
yield return currentNode.Value; yield return currentNode.Value;
@@ -204,7 +204,7 @@
{ {
if (node != null) if (node != null)
{ {
FibonacciNode<T> current = node; var current = node;
do do
{ {
Remove(current.Child); Remove(current.Child);
@@ -234,12 +234,12 @@
} }
if (node1.Value.CompareTo(node2.Value) > 0) if (node1.Value.CompareTo(node2.Value) > 0)
{ {
FibonacciNode<T> temp = node1; var temp = node1;
node1 = node2; node1 = node2;
node2 = temp; node2 = temp;
} }
FibonacciNode<T> node1Next = node1.Next; var node1Next = node1.Next;
FibonacciNode<T> node2Prev = node2.Previous; var node2Prev = node2.Previous;
node1.Next = node2; node1.Next = node2;
node2.Previous = node1; node2.Previous = node1;
node1Next.Previous = node2Prev; node1Next.Previous = node2Prev;
@@ -268,7 +268,7 @@
{ {
return; return;
} }
FibonacciNode<T> current = node; var current = node;
do do
{ {
current.Marked = false; current.Marked = false;
@@ -299,12 +299,12 @@
return node; return node;
} }
FibonacciNode<T>[] trees = new FibonacciNode<T>[64]; var trees = new FibonacciNode<T>[64];
while (true) while (true)
{ {
if (trees[node.Degree] != null) if (trees[node.Degree] != null)
{ {
FibonacciNode<T> t = trees[node.Degree]; var t = trees[node.Degree];
if (t == node) if (t == node)
{ {
break; break;
@@ -344,8 +344,8 @@
} }
node = node.Next; node = node.Next;
} }
FibonacciNode<T> min = node; var min = node;
FibonacciNode<T> start = node; var start = node;
do do
{ {
if (node.Value.CompareTo(min.Value) < 0) if (node.Value.CompareTo(min.Value) < 0)
@@ -397,7 +397,7 @@
if (node.Value.CompareTo(node.Parent.Value) < 0) if (node.Value.CompareTo(node.Parent.Value) < 0)
{ {
root = Cut(root, node); root = Cut(root, node);
FibonacciNode<T> parent = node.Parent; var parent = node.Parent;
node.Parent = null; node.Parent = null;
while (parent != null && parent.Marked) while (parent != null && parent.Marked)
{ {
@@ -429,7 +429,7 @@
/// <returns></returns> /// <returns></returns>
private FibonacciNode<T> Find(FibonacciNode<T> root, T value) private FibonacciNode<T> Find(FibonacciNode<T> root, T value)
{ {
FibonacciNode<T> node = root; var node = root;
if (node == null) if (node == null)
{ {
return null; return null;
@@ -440,7 +440,7 @@
{ {
return node; return node;
} }
FibonacciNode<T> ret = Find(node.Child, value); var ret = Find(node.Child, value);
if (ret != null) if (ret != null)
{ {
return ret; return ret;
@@ -50,7 +50,7 @@
random = new Random(); random = new Random();
head = new NodeSet<T>(default, maxLevel); head = new NodeSet<T>(default, maxLevel);
end = head; end = head;
for (int i = 0; i <= maxLevel; i++) for (var i = 0; i <= maxLevel; i++)
{ {
head.Next[i] = end; head.Next[i] = end;
} }
@@ -64,8 +64,8 @@
/// <param name="item">Item to be added.</param> /// <param name="item">Item to be added.</param>
public void Add(T item) public void Add(T item)
{ {
NodeSet<T> curNode = head; var curNode = head;
int newLevel = 0; var newLevel = 0;
while (random.Next(0, 2) > 0 && newLevel < maxLevel) while (random.Next(0, 2) > 0 && newLevel < maxLevel)
{ {
newLevel++; newLevel++;
@@ -74,7 +74,7 @@
{ {
level = newLevel; level = newLevel;
} }
NodeSet<T> newNode = new NodeSet<T>(item, newLevel); var newNode = new NodeSet<T>(item, newLevel);
for (var i = 0; i <= newLevel; i++) for (var i = 0; i <= newLevel; i++)
{ {
if (i > curNode.Level) if (i > curNode.Level)
@@ -97,8 +97,8 @@
/// <returns>True if removal was successful.</returns> /// <returns>True if removal was successful.</returns>
public bool Remove(T item) public bool Remove(T item)
{ {
bool removed = false; var removed = false;
NodeSet<T> curNode = head; var curNode = head;
for (var i = 0; i <= maxLevel; i++) for (var i = 0; i <= maxLevel; i++)
{ {
if (i > curNode.Level) if (i > curNode.Level)
@@ -134,7 +134,7 @@
/// </summary> /// </summary>
public void Clear() public void Clear()
{ {
for (int i = 0; i < maxLevel; i++) for (var i = 0; i < maxLevel; i++)
{ {
head.Next[i] = end; head.Next[i] = end;
} }
@@ -160,7 +160,7 @@
/// <param name="arrayIndex">Index to start insertion in the array.</param> /// <param name="arrayIndex">Index to start insertion in the array.</param>
public void CopyTo(T[] array, int arrayIndex) public void CopyTo(T[] array, int arrayIndex)
{ {
NodeSet<T> node = head.Next[0]; var node = head.Next[0];
while (node != end) while (node != end)
{ {
array[arrayIndex] = node.Key; array[arrayIndex] = node.Key;
@@ -174,9 +174,9 @@
/// <returns>Array filled with elements from the collection.</returns> /// <returns>Array filled with elements from the collection.</returns>
public T[] ToArray() public T[] ToArray()
{ {
T[] array = new T[count]; var array = new T[count];
int index = 0; var index = 0;
NodeSet<T> curNode = head.Next[0]; var curNode = head.Next[0];
while (curNode != end) while (curNode != end)
{ {
array[index] = curNode.Key; array[index] = curNode.Key;
@@ -191,7 +191,7 @@
/// <returns></returns> /// <returns></returns>
public IEnumerator<T> GetEnumerator() public IEnumerator<T> GetEnumerator()
{ {
NodeSet<T> curNode = head.Next[0]; var curNode = head.Next[0];
while (curNode != end) while (curNode != end)
{ {
yield return curNode.Key; yield return curNode.Key;
@@ -206,9 +206,9 @@
} }
private NodeSet<T> Find(T key) private NodeSet<T> Find(T key)
{ {
NodeSet<T> curNode = head; var curNode = head;
for (int i = level; i >= 0; i--) for (var i = level; i >= 0; i--)
{ {
while (curNode.Next[i] != end) while (curNode.Next[i] != end)
{ {
@@ -97,8 +97,8 @@
{ {
if (root != null) if (root != null)
{ {
T[] array = new T[count]; var array = new T[count];
int index = 0; var index = 0;
ToArray(root, ref array, ref index); ToArray(root, ref array, ref index);
return array; return array;
} }
@@ -221,7 +221,7 @@
{ {
if (node.Key.CompareTo(key) < 0) if (node.Key.CompareTo(key) < 0)
{ {
Node<T> found = Find(node.Left, key); var found = Find(node.Left, key);
if (found == null) if (found == null)
{ {
found = Find(node.Right, key); found = Find(node.Right, key);
@@ -230,7 +230,7 @@
} }
else if (node.Key.CompareTo(key) > 0) else if (node.Key.CompareTo(key) > 0)
{ {
Node<T> found = Find(node.Right, key); var found = Find(node.Right, key);
if (found == null) if (found == null)
{ {
found = Find(node.Left, key); found = Find(node.Left, key);
@@ -255,7 +255,7 @@
} }
private IEnumerator<T> GetEnumerator(Node<T> currentNode) private IEnumerator<T> GetEnumerator(Node<T> currentNode)
{ {
Queue<Node<T>> queue = new Queue<Node<T>>(); var queue = new Queue<Node<T>>();
queue.Enqueue(currentNode); queue.Enqueue(currentNode);
while (queue.Count > 0) while (queue.Count > 0)
{ {
@@ -6,10 +6,13 @@ namespace System.Extensions
{ {
public static byte[] ReadAllBytes(this Stream stream) public static byte[] ReadAllBytes(this Stream stream)
{ {
if (stream is null) throw new ArgumentNullException(nameof(stream)); if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}
var buffer = new byte[256]; var buffer = new byte[256];
using (MemoryStream ms = new MemoryStream()) using (var ms = new MemoryStream())
{ {
int read; int read;
while ((read = stream.Read(buffer, 0, 256)) > 0) while ((read = stream.Read(buffer, 0, 256)) > 0)
@@ -22,7 +22,10 @@ namespace System.Extensions
public static ICollection<T> ClearAnd<T>(this ICollection<T> collection) public static ICollection<T> ClearAnd<T>(this ICollection<T> collection)
{ {
if (collection is null) throw new ArgumentNullException(nameof(collection)); if (collection is null)
{
throw new ArgumentNullException(nameof(collection));
}
collection.Clear(); collection.Clear();
return collection; return collection;
@@ -30,10 +33,17 @@ namespace System.Extensions
public static ICollection<T> AddRange<T>(this ICollection<T> collection, IEnumerable<T> values) public static ICollection<T> AddRange<T>(this ICollection<T> collection, IEnumerable<T> values)
{ {
if (collection is null) throw new ArgumentNullException(nameof(collection)); if (collection is null)
if (values is null) throw new ArgumentNullException(nameof(values)); {
throw new ArgumentNullException(nameof(collection));
}
foreach(var item in values) if (values is null)
{
throw new ArgumentNullException(nameof(values));
}
foreach (var item in values)
{ {
collection.Add(item); collection.Add(item);
} }
@@ -43,8 +53,15 @@ namespace System.Extensions
public static int IndexOfWhere<T>(this ICollection<T> collection, Func<T, bool> selector) public static int IndexOfWhere<T>(this ICollection<T> collection, Func<T, bool> selector)
{ {
if (collection is null) throw new ArgumentNullException(nameof(collection)); if (collection is null)
if (selector is null) throw new ArgumentNullException(nameof(selector)); {
throw new ArgumentNullException(nameof(collection));
}
if (selector is null)
{
throw new ArgumentNullException(nameof(selector));
}
var index = 0; var index = 0;
foreach (var item in collection) foreach (var item in collection)
@@ -7,7 +7,10 @@ namespace System.Extensions
public static T Deserialize<T>(this string serialized) public static T Deserialize<T>(this string serialized)
where T : class where T : class
{ {
if (serialized.IsNullOrWhiteSpace()) throw new ArgumentException("Provided serialized string cannot be null or whitespace", nameof(serialized)); if (serialized.IsNullOrWhiteSpace())
{
throw new ArgumentException("Provided serialized string cannot be null or whitespace", nameof(serialized));
}
return JsonConvert.DeserializeObject<T>(serialized); return JsonConvert.DeserializeObject<T>(serialized);
} }
@@ -15,7 +18,10 @@ namespace System.Extensions
public static string Serialize<T>(this T obj) public static string Serialize<T>(this T obj)
where T : class where T : class
{ {
if (obj is null) throw new ArgumentNullException(nameof(obj)); if (obj is null)
{
throw new ArgumentNullException(nameof(obj));
}
return JsonConvert.SerializeObject(obj); return JsonConvert.SerializeObject(obj);
} }
@@ -37,7 +43,10 @@ namespace System.Extensions
public static T ThrowIfNull<T>([ValidatedNotNull] this T obj, string name) where T : class public static T ThrowIfNull<T>([ValidatedNotNull] this T obj, string name) where T : class
{ {
if (obj is null) throw new ArgumentNullException(name); if (obj is null)
{
throw new ArgumentNullException(name);
}
return obj; return obj;
} }
@@ -40,8 +40,15 @@
} }
public Optional<T> Do(Action<T> onSome, Action onNone) public Optional<T> Do(Action<T> onSome, Action onNone)
{ {
if (onSome is null) throw new ArgumentNullException(nameof(onSome)); if (onSome is null)
if (onNone is null) throw new ArgumentNullException(nameof(onNone)); {
throw new ArgumentNullException(nameof(onSome));
}
if (onNone is null)
{
throw new ArgumentNullException(nameof(onNone));
}
if (this is Some) if (this is Some)
{ {
@@ -67,8 +74,15 @@
} }
public Optional<V> Switch<V>(Func<T, V> onSome, Func<V> onNone) public Optional<V> Switch<V>(Func<T, V> onSome, Func<V> onNone)
{ {
if (onSome is null) throw new ArgumentNullException($"{nameof(onSome)}"); if (onSome is null)
if (onNone is null) throw new ArgumentNullException($"{nameof(onNone)}"); {
throw new ArgumentNullException($"{nameof(onSome)}");
}
if (onNone is null)
{
throw new ArgumentNullException($"{nameof(onNone)}");
}
if (this is Some) if (this is Some)
{ {
@@ -43,9 +43,15 @@
} }
public Result<TSuccess, TFailure> Do(Action onSuccess, Action onFailure) public Result<TSuccess, TFailure> Do(Action onSuccess, Action onFailure)
{ {
if (onSuccess is null) throw new ArgumentNullException(nameof(onSuccess)); if (onSuccess is null)
{
throw new ArgumentNullException(nameof(onSuccess));
}
if (onFailure is null) throw new ArgumentNullException(nameof(onFailure)); if (onFailure is null)
{
throw new ArgumentNullException(nameof(onFailure));
}
if (value is TSuccess) if (value is TSuccess)
{ {
@@ -71,9 +77,15 @@
} }
public Result<TSuccess, TFailure> Do(Action<TSuccess> onSuccess, Action<TFailure> onFailure) public Result<TSuccess, TFailure> Do(Action<TSuccess> onSuccess, Action<TFailure> onFailure)
{ {
if (onSuccess is null) throw new ArgumentNullException(nameof(onSuccess)); if (onSuccess is null)
{
throw new ArgumentNullException(nameof(onSuccess));
}
if (onFailure is null) throw new ArgumentNullException(nameof(onFailure)); if (onFailure is null)
{
throw new ArgumentNullException(nameof(onFailure));
}
if (value is TSuccess success) if (value is TSuccess success)
{ {
@@ -99,9 +111,15 @@
} }
public T Switch<T>(Func<TSuccess, T> onSuccess, Func<TFailure, T> onFailure) public T Switch<T>(Func<TSuccess, T> onSuccess, Func<TFailure, T> onFailure)
{ {
if (onSuccess is null) throw new ArgumentNullException(nameof(onSuccess)); if (onSuccess is null)
{
throw new ArgumentNullException(nameof(onSuccess));
}
if (onFailure is null) throw new ArgumentNullException(nameof(onFailure)); if (onFailure is null)
{
throw new ArgumentNullException(nameof(onFailure));
}
if (value is TSuccess success) if (value is TSuccess success)
{ {
@@ -127,9 +145,15 @@
} }
public Result<V, K> Switch<V, K>(Func<TSuccess, V> onSuccess, Func<TFailure, K> onFailure) public Result<V, K> Switch<V, K>(Func<TSuccess, V> onSuccess, Func<TFailure, K> onFailure)
{ {
if (onSuccess is null) throw new ArgumentNullException(nameof(onSuccess)); if (onSuccess is null)
{
throw new ArgumentNullException(nameof(onSuccess));
}
if (onFailure is null) throw new ArgumentNullException(nameof(onFailure)); if (onFailure is null)
{
throw new ArgumentNullException(nameof(onFailure));
}
if (value is TSuccess success) if (value is TSuccess success)
{ {
@@ -7,8 +7,15 @@ namespace System.Extensions
{ {
public static void DoWhileReading(this Stream stream, Action<int, byte[]> action, int bufferLength = 256) public static void DoWhileReading(this Stream stream, Action<int, byte[]> action, int bufferLength = 256)
{ {
if (stream is null) throw new ArgumentNullException(nameof(stream)); if (stream is null)
if (action is null) throw new ArgumentNullException(nameof(action)); {
throw new ArgumentNullException(nameof(stream));
}
if (action is null)
{
throw new ArgumentNullException(nameof(action));
}
var buffer = new byte[bufferLength]; var buffer = new byte[bufferLength];
var read = stream.Read(buffer, 0, bufferLength); var read = stream.Read(buffer, 0, bufferLength);
@@ -21,7 +28,10 @@ namespace System.Extensions
public static byte[] ReadBytes(this Stream stream, int count) public static byte[] ReadBytes(this Stream stream, int count)
{ {
if (stream is null) throw new ArgumentNullException(nameof(stream)); if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}
var buffer = new byte[count]; var buffer = new byte[count];
stream.Read(buffer, 0, count); stream.Read(buffer, 0, count);
@@ -30,9 +40,15 @@ namespace System.Extensions
public static Stream Rewind(this Stream stream) public static Stream Rewind(this Stream stream)
{ {
if (stream is null) throw new ArgumentNullException(nameof(stream)); if (stream is null)
{
throw new ArgumentNullException(nameof(stream));
}
if (!stream.CanSeek) throw new InvalidOperationException("Stream doesn't support rewinding"); if (!stream.CanSeek)
{
throw new InvalidOperationException("Stream doesn't support rewinding");
}
stream.Seek(0, SeekOrigin.Begin); stream.Seek(0, SeekOrigin.Begin);
return stream; return stream;
@@ -41,17 +57,19 @@ namespace System.Extensions
public static string ReadUntil(this StreamReader sr, string delim) public static string ReadUntil(this StreamReader sr, string delim)
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
bool found = false; var found = false;
while (!found && !sr.EndOfStream) while (!found && !sr.EndOfStream)
{ {
for (int i = 0; i < delim.Length; i++) for (var i = 0; i < delim.Length; i++)
{ {
char c = (char)sr.Read(); var c = (char)sr.Read();
sb.Append(c); sb.Append(c);
if (c != delim[i]) if (c != delim[i])
{
break; break;
}
if (i == delim.Length - 1) if (i == delim.Length - 1)
{ {
@@ -44,13 +44,17 @@ namespace System.Extensions
public static async Task RunPeriodicAsync(this Action onTick, TimeSpan dueTime, TimeSpan interval, CancellationToken token) public static async Task RunPeriodicAsync(this Action onTick, TimeSpan dueTime, TimeSpan interval, CancellationToken token)
{ {
if (dueTime > TimeSpan.Zero) if (dueTime > TimeSpan.Zero)
{
await Task.Delay(dueTime, token).ConfigureAwait(false); await Task.Delay(dueTime, token).ConfigureAwait(false);
}
while (!token.IsCancellationRequested) while (!token.IsCancellationRequested)
{ {
onTick?.Invoke(); onTick?.Invoke();
if (interval > TimeSpan.Zero) if (interval > TimeSpan.Zero)
{
await Task.Delay(interval, token).ConfigureAwait(false); await Task.Delay(interval, token).ConfigureAwait(false);
}
} }
} }
@@ -95,7 +99,7 @@ namespace System.Extensions
var oldContext = SynchronizationContext.Current; var oldContext = SynchronizationContext.Current;
var synch = new ExclusiveSynchronizationContext(); var synch = new ExclusiveSynchronizationContext();
SynchronizationContext.SetSynchronizationContext(synch); SynchronizationContext.SetSynchronizationContext(synch);
T ret = default(T); var ret = default(T);
synch.Post(async _ => synch.Post(async _ =>
{ {
try try
@@ -46,7 +46,10 @@ namespace System.Extensions
public TResult Finally(Action act) public TResult Finally(Action act)
{ {
if (act is null) throw new ArgumentNullException(nameof(act)); if (act is null)
{
throw new ArgumentNullException(nameof(act));
}
try try
{ {
@@ -174,7 +174,7 @@ namespace System.Threading
threadpool = new List<WorkerThread>(); threadpool = new List<WorkerThread>();
tasks = new PriorityQueue<QueueEntry>(); tasks = new PriorityQueue<QueueEntry>();
maxThreads = System.Environment.ProcessorCount; maxThreads = System.Environment.ProcessorCount;
for (int i = 0; i < maxThreads; i++) for (var i = 0; i < maxThreads; i++)
{ {
this.CreateAndStartWorkerThread(); this.CreateAndStartWorkerThread();
} }
@@ -194,7 +194,7 @@ namespace System.Threading
threadpool = new List<WorkerThread>(); threadpool = new List<WorkerThread>();
tasks = new PriorityQueue<QueueEntry>(); tasks = new PriorityQueue<QueueEntry>();
this.maxThreads = Math.Max(maxThreads, 1); this.maxThreads = Math.Max(maxThreads, 1);
for (int i = 0; i < maxThreads; i++) for (var i = 0; i < maxThreads; i++)
{ {
this.CreateAndStartWorkerThread(); this.CreateAndStartWorkerThread();
} }
@@ -216,23 +216,23 @@ namespace System.Threading
{ {
threadpool = new List<WorkerThread>(); threadpool = new List<WorkerThread>();
tasks = new PriorityQueue<QueueEntry>(); tasks = new PriorityQueue<QueueEntry>();
for (int i = 0; i < lowest; i++) for (var i = 0; i < lowest; i++)
{ {
this.CreateAndStartWorkerThread(ThreadPriority.Lowest); this.CreateAndStartWorkerThread(ThreadPriority.Lowest);
} }
for (int i = 0; i < belowNormal; i++) for (var i = 0; i < belowNormal; i++)
{ {
this.CreateAndStartWorkerThread(ThreadPriority.BelowNormal); this.CreateAndStartWorkerThread(ThreadPriority.BelowNormal);
} }
for (int i = 0; i < normal; i++) for (var i = 0; i < normal; i++)
{ {
this.CreateAndStartWorkerThread(ThreadPriority.Normal); this.CreateAndStartWorkerThread(ThreadPriority.Normal);
} }
for (int i = 0; i < aboveNormal; i++) for (var i = 0; i < aboveNormal; i++)
{ {
this.CreateAndStartWorkerThread(ThreadPriority.AboveNormal); this.CreateAndStartWorkerThread(ThreadPriority.AboveNormal);
} }
for (int i = 0; i < highest; i++) for (var i = 0; i < highest; i++)
{ {
this.CreateAndStartWorkerThread(ThreadPriority.Highest); this.CreateAndStartWorkerThread(ThreadPriority.Highest);
} }
@@ -247,7 +247,11 @@ namespace System.Threading
/// <param name="taskPriority">Priority of task. Affects its position into the queue.</param> /// <param name="taskPriority">Priority of task. Affects its position into the queue.</param>
public void QueueUserWorkItem(WaitCallback waitCallback, object callbackState, TaskPriority taskPriority) public void QueueUserWorkItem(WaitCallback waitCallback, object callbackState, TaskPriority taskPriority)
{ {
while (!Monitor.TryEnter(tasksLock)) ; while (!Monitor.TryEnter(tasksLock))
{
;
}
tasks.Enqueue(new QueueEntry(taskPriority, waitCallback, callbackState)); tasks.Enqueue(new QueueEntry(taskPriority, waitCallback, callbackState));
Monitor.Exit(tasksLock); Monitor.Exit(tasksLock);
} }
@@ -307,7 +311,11 @@ namespace System.Threading
thisWorkerThread.Working = true; thisWorkerThread.Working = true;
QueueEntry task = null; QueueEntry task = null;
while (!Monitor.TryEnter(tasksLock)) ; while (!Monitor.TryEnter(tasksLock))
{
;
}
if (tasks.Count > 0) if (tasks.Count > 0)
{ {
task = tasks.Dequeue(); task = tasks.Dequeue();
@@ -316,7 +324,7 @@ namespace System.Threading
if (task != null) if (task != null)
{ {
System.Diagnostics.Debug.WriteLine(Thread.CurrentThread.Name + " - Running task!"); System.Diagnostics.Debug.WriteLine(Thread.CurrentThread.Name + " - Running task!");
WaitCallback waitCallback = task.WaitCallback; var waitCallback = task.WaitCallback;
waitCallback.Invoke(task.Object); waitCallback.Invoke(task.Object);
} }
thisWorkerThread.Working = false; thisWorkerThread.Working = false;
@@ -328,7 +336,7 @@ namespace System.Threading
/// </summary> /// </summary>
private void ObserverLoop() private void ObserverLoop()
{ {
Statistics statistics = new Statistics(); var statistics = new Statistics();
while (true) while (true)
{ {
//Observer operates on a 100ms loop. Due to the low priority of the thread itself, this loop will almost always take //Observer operates on a 100ms loop. Due to the low priority of the thread itself, this loop will almost always take
@@ -346,7 +354,7 @@ namespace System.Threading
//This part of code updates the statistics of the threadpool. //This part of code updates the statistics of the threadpool.
if (statistics.Initialized) if (statistics.Initialized)
{ {
double loopDuration = (DateTime.Now - statistics.LastUpdate).TotalMilliseconds; var loopDuration = (DateTime.Now - statistics.LastUpdate).TotalMilliseconds;
if (statistics.LoopFrequency == 0) if (statistics.LoopFrequency == 0)
{ {
statistics.LoopFrequency = loopDuration; statistics.LoopFrequency = loopDuration;
@@ -387,7 +395,7 @@ namespace System.Threading
if (tasks.Count > 0) if (tasks.Count > 0)
{ {
//If there are tasks pending, find a thread with priority under Normal and upgrade its priority. //If there are tasks pending, find a thread with priority under Normal and upgrade its priority.
Thread t = FindThreadWithLowPriority(); var t = FindThreadWithLowPriority();
if (t != null) if (t != null)
{ {
UpgradeThreadPriority(t); UpgradeThreadPriority(t);
@@ -396,7 +404,7 @@ namespace System.Threading
else else
{ {
//If there are no tasks pending, find a thread with priority above Lowest and downgrade its priority. //If there are no tasks pending, find a thread with priority above Lowest and downgrade its priority.
Thread t = FindThreadWithAcceptablePriority(); var t = FindThreadWithAcceptablePriority();
if (t != null) if (t != null)
{ {
DowngradeThreadPriority(t); DowngradeThreadPriority(t);
@@ -423,7 +431,7 @@ namespace System.Threading
//If thread is currently working, notify it to close. //If thread is currently working, notify it to close.
//Else, abort the thread. //Else, abort the thread.
//Reset counter to 0. //Reset counter to 0.
WorkerThread worker = threadpool[threadpool.Count - 1]; var worker = threadpool[threadpool.Count - 1];
if (worker.Working) if (worker.Working)
{ {
worker.Running = false; worker.Running = false;
@@ -444,7 +452,7 @@ namespace System.Threading
/// <returns>Thread with low priority.</returns> /// <returns>Thread with low priority.</returns>
private Thread FindThreadWithLowPriority() private Thread FindThreadWithLowPriority()
{ {
foreach (WorkerThread t in threadpool) foreach (var t in threadpool)
{ {
if (t.Thread.Priority == ThreadPriority.Lowest || t.Thread.Priority == ThreadPriority.BelowNormal) if (t.Thread.Priority == ThreadPriority.Lowest || t.Thread.Priority == ThreadPriority.BelowNormal)
{ {
@@ -459,7 +467,7 @@ namespace System.Threading
/// <returns>Thread with BelowNormal or Normal priority.</returns> /// <returns>Thread with BelowNormal or Normal priority.</returns>
private Thread FindThreadWithAcceptablePriority() private Thread FindThreadWithAcceptablePriority()
{ {
foreach (WorkerThread t in threadpool) foreach (var t in threadpool)
{ {
if (t.Thread.Priority == ThreadPriority.Normal || t.Thread.Priority == ThreadPriority.BelowNormal) if (t.Thread.Priority == ThreadPriority.Normal || t.Thread.Priority == ThreadPriority.BelowNormal)
{ {
@@ -538,7 +546,7 @@ namespace System.Threading
this.observerCancellationTokenSource.Cancel(); this.observerCancellationTokenSource.Cancel();
this.observer.Join(); this.observer.Join();
} }
foreach (WorkerThread worker in threadpool) foreach (var worker in threadpool)
{ {
worker.CancellationTokenSource.Cancel(); worker.CancellationTokenSource.Cancel();
worker.Thread.Join(); worker.Thread.Join();
@@ -20,7 +20,7 @@ namespace System.Collections.Tests
{ {
try try
{ {
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
avlTree.Add(i * 20 - (50 + i)); avlTree.Add(i * 20 - (50 + i));
} }
@@ -38,7 +38,7 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void ContainsTest() public void ContainsTest()
{ {
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
avlTree.Add(i); avlTree.Add(i);
} }
@@ -52,7 +52,7 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void RemoveTest() public void RemoveTest()
{ {
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
avlTree.Add(i); avlTree.Add(i);
} }
@@ -68,7 +68,7 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void ClearTest() public void ClearTest()
{ {
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
avlTree.Add(i); avlTree.Add(i);
} }
@@ -82,24 +82,24 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void CopyToTest() public void CopyToTest()
{ {
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
avlTree.Add(i); avlTree.Add(i);
} }
int[] array = new int[100]; var array = new int[100];
avlTree.CopyTo(array, 0); avlTree.CopyTo(array, 0);
} }
[TestMethod()] [TestMethod()]
public void GetEnumeratorTest() public void GetEnumeratorTest()
{ {
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
avlTree.Add(i); avlTree.Add(i);
} }
int count = 0; var count = 0;
foreach(int value in avlTree) foreach(var value in avlTree)
{ {
count++; count++;
System.Diagnostics.Debug.WriteLine(value); System.Diagnostics.Debug.WriteLine(value);
@@ -114,34 +114,34 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void ToArrayTest() public void ToArrayTest()
{ {
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
avlTree.Add(i); avlTree.Add(i);
} }
int[] array = avlTree.ToArray(); var array = avlTree.ToArray();
} }
[TestMethod()] [TestMethod()]
public void Serialize() public void Serialize()
{ {
AVLTree<int> avlTree2 = new AVLTree<int>(); var avlTree2 = new AVLTree<int>();
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
avlTree.Add(i); avlTree.Add(i);
} }
BinaryFormatter serializer = new BinaryFormatter(); var serializer = new BinaryFormatter();
string s = string.Empty; var s = string.Empty;
using (var stream = new MemoryStream()) using (var stream = new MemoryStream())
{ {
serializer.Serialize(stream, avlTree); serializer.Serialize(stream, avlTree);
stream.Position = 0; stream.Position = 0;
avlTree2 = (AVLTree<int>)serializer.Deserialize(stream); avlTree2 = (AVLTree<int>)serializer.Deserialize(stream);
} }
IEnumerator<int> avlTreeEnum = avlTree.GetEnumerator(); var avlTreeEnum = avlTree.GetEnumerator();
IEnumerator<int> avlTree2Enum = avlTree2.GetEnumerator(); var avlTree2Enum = avlTree2.GetEnumerator();
for(int i = 0; i < 100; i++) for(var i = 0; i < 100; i++)
{ {
if(avlTreeEnum.Current != avlTree2Enum.Current) if(avlTreeEnum.Current != avlTree2Enum.Current)
{ {
@@ -31,7 +31,7 @@ namespace System.Collections.Tests
{ {
try try
{ {
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
binaryHeap.Add(i * 20 - (50 + i)); binaryHeap.Add(i * 20 - (50 + i));
} }
@@ -52,7 +52,7 @@ namespace System.Collections.Tests
{ {
try try
{ {
int tries = binaryHeap.Count; var tries = binaryHeap.Count;
while (binaryHeap.Count > 0) while (binaryHeap.Count > 0)
{ {
if (tries == 0) if (tries == 0)
@@ -72,7 +72,7 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void MinMaxTest() public void MinMaxTest()
{ {
for (int i = 0; i < 1000; i++) for (var i = 0; i < 1000; i++)
{ {
binaryHeap.Add(i); binaryHeap.Add(i);
} }
@@ -85,7 +85,7 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void ClearTest() public void ClearTest()
{ {
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
binaryHeap.Add(i); binaryHeap.Add(i);
} }
@@ -99,12 +99,12 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void ClearTest2() public void ClearTest2()
{ {
for (int i = 100; i < 200; i++) for (var i = 100; i < 200; i++)
{ {
binaryHeap.Add(i); binaryHeap.Add(i);
} }
binaryHeap.Clear(false); binaryHeap.Clear(false);
int[] array = binaryHeap.ToArray(); var array = binaryHeap.ToArray();
if (binaryHeap.Count > 0 || binaryHeap.Capacity == 10) if (binaryHeap.Count > 0 || binaryHeap.Capacity == 10)
{ {
Assert.Fail(); Assert.Fail();
@@ -133,11 +133,11 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void ToArrayTest() public void ToArrayTest()
{ {
for(int i = 0; i < 1000; i++) for(var i = 0; i < 1000; i++)
{ {
binaryHeap.Add(i); binaryHeap.Add(i);
} }
int[] array = binaryHeap.ToArray(); var array = binaryHeap.ToArray();
if(array.Length != binaryHeap.Count) if(array.Length != binaryHeap.Count)
{ {
Assert.Fail(); Assert.Fail();
@@ -151,12 +151,12 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void GetEnumeratorTest() public void GetEnumeratorTest()
{ {
for (int i = 0; i < 1000; i++) for (var i = 0; i < 1000; i++)
{ {
binaryHeap.Add(i); binaryHeap.Add(i);
} }
int count = 0; var count = 0;
foreach(int value in binaryHeap) foreach(var value in binaryHeap)
{ {
System.Diagnostics.Debug.WriteLine(value); System.Diagnostics.Debug.WriteLine(value);
count++; count++;
@@ -173,22 +173,22 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void Serialize() public void Serialize()
{ {
BinaryHeap<int> binaryHeap2 = new BinaryHeap<int>(); var binaryHeap2 = new BinaryHeap<int>();
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
binaryHeap.Add(i); binaryHeap.Add(i);
} }
BinaryFormatter serializer = new BinaryFormatter(); var serializer = new BinaryFormatter();
string s = string.Empty; var s = string.Empty;
using (var stream = new MemoryStream()) { using (var stream = new MemoryStream()) {
serializer.Serialize(stream, binaryHeap); serializer.Serialize(stream, binaryHeap);
stream.Position = 0; stream.Position = 0;
binaryHeap2 = (BinaryHeap<int>)serializer.Deserialize(stream); binaryHeap2 = (BinaryHeap<int>)serializer.Deserialize(stream);
} }
IEnumerator<int> binaryHeapEnum = binaryHeap.GetEnumerator(); var binaryHeapEnum = binaryHeap.GetEnumerator();
IEnumerator<int> binaryHeapEnum2 = binaryHeap2.GetEnumerator(); var binaryHeapEnum2 = binaryHeap2.GetEnumerator();
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
if (binaryHeapEnum.Current != binaryHeapEnum2.Current) if (binaryHeapEnum.Current != binaryHeapEnum2.Current)
{ {
@@ -12,7 +12,7 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void InsertTest() public void InsertTest()
{ {
for (int i = 0; i < 1000; i++) for (var i = 0; i < 1000; i++)
{ {
fibonacciHeap.Add(i); fibonacciHeap.Add(i);
} }
@@ -31,21 +31,21 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void MergeTest() public void MergeTest()
{ {
FibonacciHeap<int> fibonacciHeap1 = new FibonacciHeap<int>(); var fibonacciHeap1 = new FibonacciHeap<int>();
FibonacciHeap<int> fibonacciHeap2 = new FibonacciHeap<int>(); var fibonacciHeap2 = new FibonacciHeap<int>();
for(int i = 0; i < 100; i++) for(var i = 0; i < 100; i++)
{ {
fibonacciHeap1.Add(i); fibonacciHeap1.Add(i);
} }
for(int i = 100; i < 300; i++) for(var i = 100; i < 300; i++)
{ {
fibonacciHeap2.Add(i); fibonacciHeap2.Add(i);
} }
fibonacciHeap1.Merge(fibonacciHeap2); fibonacciHeap1.Merge(fibonacciHeap2);
for(int i = 1; i < 300; i++) for(var i = 1; i < 300; i++)
{ {
if (!fibonacciHeap1.Contains(i)) if (!fibonacciHeap1.Contains(i))
{ {
@@ -70,11 +70,11 @@ namespace System.Collections.Tests
{ {
Assert.Fail(); Assert.Fail();
} }
for (int i = 0; i < 1000; i++) for (var i = 0; i < 1000; i++)
{ {
fibonacciHeap.Add(i); fibonacciHeap.Add(i);
} }
for (int i = 0; i < 1000; i++) for (var i = 0; i < 1000; i++)
{ {
if (fibonacciHeap.Remove() != i) if (fibonacciHeap.Remove() != i)
{ {
@@ -104,7 +104,7 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void ContainsTest() public void ContainsTest()
{ {
for(int i = 0; i < 10000; i++) for(var i = 0; i < 10000; i++)
{ {
fibonacciHeap.Add(i); fibonacciHeap.Add(i);
} }
@@ -117,7 +117,7 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void ClearTest() public void ClearTest()
{ {
for(int i = 0; i < 10000; i++) for(var i = 0; i < 10000; i++)
{ {
fibonacciHeap.Add(i); fibonacciHeap.Add(i);
} }
@@ -132,14 +132,14 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void ToArrayTest() public void ToArrayTest()
{ {
for(int i = 999; i >= 0; i--) for(var i = 999; i >= 0; i--)
{ {
fibonacciHeap.Add(i); fibonacciHeap.Add(i);
} }
fibonacciHeap.Remove(); fibonacciHeap.Remove();
int[] arr = fibonacciHeap.ToArray(); var arr = fibonacciHeap.ToArray();
for(int i = 1; i < 512; i++) for(var i = 1; i < 512; i++)
{ {
if(arr[i - 1] != i) if(arr[i - 1] != i)
{ {
@@ -151,14 +151,14 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void GetEnumeratorTest() public void GetEnumeratorTest()
{ {
for (int i = 999; i >= 0; i--) for (var i = 999; i >= 0; i--)
{ {
fibonacciHeap.Add(i); fibonacciHeap.Add(i);
} }
int count = 0; var count = 0;
foreach(int value in fibonacciHeap) foreach(var value in fibonacciHeap)
{ {
System.Diagnostics.Debug.WriteLine(value); System.Diagnostics.Debug.WriteLine(value);
count++; count++;
@@ -175,23 +175,23 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void Serialize() public void Serialize()
{ {
FibonacciHeap<int> fibonacciHeap2 = new FibonacciHeap<int>(); var fibonacciHeap2 = new FibonacciHeap<int>();
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
fibonacciHeap.Add(i); fibonacciHeap.Add(i);
} }
BinaryFormatter serializer = new BinaryFormatter(); var serializer = new BinaryFormatter();
string s = string.Empty; var s = string.Empty;
using (var stream = new MemoryStream()) using (var stream = new MemoryStream())
{ {
serializer.Serialize(stream, fibonacciHeap); serializer.Serialize(stream, fibonacciHeap);
stream.Position = 0; stream.Position = 0;
fibonacciHeap2 = (FibonacciHeap<int>)serializer.Deserialize(stream); fibonacciHeap2 = (FibonacciHeap<int>)serializer.Deserialize(stream);
} }
IEnumerator<int> enum1 = fibonacciHeap.GetEnumerator(); var enum1 = fibonacciHeap.GetEnumerator();
IEnumerator<int> enum2 = fibonacciHeap2.GetEnumerator(); var enum2 = fibonacciHeap2.GetEnumerator();
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
if (enum1.Current != enum2.Current) if (enum1.Current != enum2.Current)
{ {
@@ -29,7 +29,7 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void EnqueueTest() public void EnqueueTest()
{ {
for(int i = 0; i < 100; i++) for(var i = 0; i < 100; i++)
{ {
priorityQueue.Enqueue(i); priorityQueue.Enqueue(i);
} }
@@ -42,11 +42,11 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void DequeueTest() public void DequeueTest()
{ {
for(int i = 0; i < 100; i++) for(var i = 0; i < 100; i++)
{ {
priorityQueue.Enqueue(i); priorityQueue.Enqueue(i);
} }
for(int i = 0; i < 100; i++) for(var i = 0; i < 100; i++)
{ {
if(i != priorityQueue.Dequeue()) if(i != priorityQueue.Dequeue())
{ {
@@ -81,23 +81,23 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void Serialize() public void Serialize()
{ {
PriorityQueue<int> priorityQueue2 = new PriorityQueue<int>(); var priorityQueue2 = new PriorityQueue<int>();
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
priorityQueue.Enqueue(i); priorityQueue.Enqueue(i);
} }
BinaryFormatter serializer = new BinaryFormatter(); var serializer = new BinaryFormatter();
string s = string.Empty; var s = string.Empty;
using (var stream = new MemoryStream()) using (var stream = new MemoryStream())
{ {
serializer.Serialize(stream, priorityQueue); serializer.Serialize(stream, priorityQueue);
stream.Position = 0; stream.Position = 0;
priorityQueue2 = (PriorityQueue<int>)serializer.Deserialize(stream); priorityQueue2 = (PriorityQueue<int>)serializer.Deserialize(stream);
} }
IEnumerator<int> enum1 = priorityQueue.GetEnumerator(); var enum1 = priorityQueue.GetEnumerator();
IEnumerator<int> enum2 = priorityQueue2.GetEnumerator(); var enum2 = priorityQueue2.GetEnumerator();
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
if (enum1.Current != enum2.Current) if (enum1.Current != enum2.Current)
{ {
@@ -12,19 +12,19 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void SkipListTest() public void SkipListTest()
{ {
SkipList<int> skipList = new SkipList<int>(); var skipList = new SkipList<int>();
} }
[TestMethod()] [TestMethod()]
public void SkipListTest2() public void SkipListTest2()
{ {
SkipList<int> skipList = new SkipList<int>(30); var skipList = new SkipList<int>(30);
} }
[TestMethod()] [TestMethod()]
public void AddTest() public void AddTest()
{ {
for(int i = 0; i < 200; i++) for(var i = 0; i < 200; i++)
{ {
skipList.Add(i); skipList.Add(i);
} }
@@ -33,7 +33,7 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void ClearTest() public void ClearTest()
{ {
for (int i = 0; i < 200; i++) for (var i = 0; i < 200; i++)
{ {
skipList.Add(i); skipList.Add(i);
} }
@@ -47,7 +47,7 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void ContainsTest() public void ContainsTest()
{ {
for (int i = 0; i < 200; i++) for (var i = 0; i < 200; i++)
{ {
skipList.Add(i); skipList.Add(i);
} }
@@ -61,13 +61,13 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void CopyToTest() public void CopyToTest()
{ {
for (int i = 0; i < 200; i++) for (var i = 0; i < 200; i++)
{ {
skipList.Add(i); skipList.Add(i);
} }
int[] array = new int[skipList.Count]; var array = new int[skipList.Count];
skipList.CopyTo(array, 0); skipList.CopyTo(array, 0);
for (int i = 0; i < 200; i++) for (var i = 0; i < 200; i++)
{ {
if(array[i] != i) if(array[i] != i)
{ {
@@ -79,13 +79,13 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void ToArrayTest() public void ToArrayTest()
{ {
for (int i = 0; i < 200; i++) for (var i = 0; i < 200; i++)
{ {
skipList.Add(i); skipList.Add(i);
} }
int[] array = skipList.ToArray(); var array = skipList.ToArray();
for (int i = 0; i < 200; i++) for (var i = 0; i < 200; i++)
{ {
if(array[i] != i) if(array[i] != i)
{ {
@@ -97,12 +97,12 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void GetEnumeratorTest() public void GetEnumeratorTest()
{ {
for (int i = 0; i < 200; i++) for (var i = 0; i < 200; i++)
{ {
skipList.Add(i); skipList.Add(i);
} }
foreach(int i in skipList) foreach(var i in skipList)
{ {
System.Diagnostics.Debug.WriteLine(i); System.Diagnostics.Debug.WriteLine(i);
} }
@@ -111,7 +111,7 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void RemoveTest() public void RemoveTest()
{ {
for (int i = 0; i < 200; i++) for (var i = 0; i < 200; i++)
{ {
skipList.Add(i); skipList.Add(i);
} }
@@ -126,23 +126,23 @@ namespace System.Collections.Tests
[Ignore("Binary serialization is obsolete and should not be used anymore")] [Ignore("Binary serialization is obsolete and should not be used anymore")]
public void Serialize() public void Serialize()
{ {
SkipList<int> skipList2 = new SkipList<int>(); var skipList2 = new SkipList<int>();
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
skipList.Add(i); skipList.Add(i);
} }
BinaryFormatter serializer = new BinaryFormatter(); var serializer = new BinaryFormatter();
string s = string.Empty; var s = string.Empty;
using (var stream = new MemoryStream()) using (var stream = new MemoryStream())
{ {
serializer.Serialize(stream, skipList); serializer.Serialize(stream, skipList);
stream.Position = 0; stream.Position = 0;
skipList2 = (SkipList<int>)serializer.Deserialize(stream); skipList2 = (SkipList<int>)serializer.Deserialize(stream);
} }
IEnumerator<int> enum1 = skipList.GetEnumerator(); var enum1 = skipList.GetEnumerator();
IEnumerator<int> enum2 = skipList2.GetEnumerator(); var enum2 = skipList2.GetEnumerator();
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
if (enum1.Current != enum2.Current) if (enum1.Current != enum2.Current)
{ {
@@ -18,8 +18,8 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void InsertTest() public void InsertTest()
{ {
Random random = new Random(); var random = new Random();
for(int i = 0; i < 1000; i++) for(var i = 0; i < 1000; i++)
{ {
treap.Add(random.Next(0, 5000)); treap.Add(random.Next(0, 5000));
} }
@@ -41,8 +41,8 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void ClearTest() public void ClearTest()
{ {
Random random = new Random(); var random = new Random();
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
treap.Add(random.Next(0, 5000)); treap.Add(random.Next(0, 5000));
} }
@@ -71,12 +71,12 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void ToArrayTest() public void ToArrayTest()
{ {
for(int i = 0; i < 1000; i++) for(var i = 0; i < 1000; i++)
{ {
treap.Add(i); treap.Add(i);
} }
int[] arr = treap.ToArray(); var arr = treap.ToArray();
for(int i = 0; i < 1000; i++) for(var i = 0; i < 1000; i++)
{ {
if(arr[i] != i) if(arr[i] != i)
{ {
@@ -88,13 +88,13 @@ namespace System.Collections.Tests
[TestMethod()] [TestMethod()]
public void GetEnumeratorTest() public void GetEnumeratorTest()
{ {
for (int i = 0; i < 1000; i++) for (var i = 0; i < 1000; i++)
{ {
treap.Add(i); treap.Add(i);
} }
int count = 0; var count = 0;
foreach(int value in treap) foreach(var value in treap)
{ {
System.Diagnostics.Debug.WriteLine(value); System.Diagnostics.Debug.WriteLine(value);
count++; count++;
@@ -112,23 +112,23 @@ namespace System.Collections.Tests
[Ignore("Binary serialization is obsolete and should not be used anymore")] [Ignore("Binary serialization is obsolete and should not be used anymore")]
public void Serialize() public void Serialize()
{ {
Treap<int> treap2 = new Treap<int>(); var treap2 = new Treap<int>();
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
treap.Add(i); treap.Add(i);
} }
BinaryFormatter serializer = new BinaryFormatter(); var serializer = new BinaryFormatter();
string s = string.Empty; var s = string.Empty;
using (var stream = new MemoryStream()) using (var stream = new MemoryStream())
{ {
serializer.Serialize(stream, treap); serializer.Serialize(stream, treap);
stream.Position = 0; stream.Position = 0;
treap2 = (Treap<int>)serializer.Deserialize(stream); treap2 = (Treap<int>)serializer.Deserialize(stream);
} }
IEnumerator<int> enum1 = treap.GetEnumerator(); var enum1 = treap.GetEnumerator();
IEnumerator<int> enum2 = treap2.GetEnumerator(); var enum2 = treap2.GetEnumerator();
for (int i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
{ {
if (enum1.Current != enum2.Current) if (enum1.Current != enum2.Current)
{ {
@@ -32,7 +32,7 @@ namespace SystemExtensionsTests.Http
[TestMethod] [TestMethod]
public async Task HttpClientEmitsCorrectMessages() public async Task HttpClientEmitsCorrectMessages()
{ {
int messagesEmitted = 0; var messagesEmitted = 0;
this.httpClient.EventEmitted += (sender, message) => this.httpClient.EventEmitted += (sender, message) =>
{ {
messagesEmitted++; messagesEmitted++;
@@ -309,7 +309,7 @@ namespace SystemExtensionsTests.Http
this.handler.ResponseResolverAsync = async (request) => this.handler.ResponseResolverAsync = async (request) =>
{ {
request.RequestUri.Should().Be(expectedUri); request.RequestUri.Should().Be(expectedUri);
for (int i = 0; i < 10; i++) for (var i = 0; i < 10; i++)
{ {
await Task.Delay(100); await Task.Delay(100);
} }
@@ -53,7 +53,7 @@ namespace System.Structures.BitStructures.Tests
[DataRow(int.MaxValue, int.MinValue)] [DataRow(int.MaxValue, int.MinValue)]
public void TestLowHigh(int low, int high) public void TestLowHigh(int low, int high)
{ {
Int64BitStruct int64 = new Int64BitStruct(low, high); var int64 = new Int64BitStruct(low, high);
Int32BitStruct lowStruct = low; Int32BitStruct lowStruct = low;
Int32BitStruct highStruct = high; Int32BitStruct highStruct = high;
Assert.IsTrue(int64.Low == lowStruct); Assert.IsTrue(int64.Low == lowStruct);
@@ -49,7 +49,7 @@ namespace System.Threading.Tests
Thread.Sleep(100); Thread.Sleep(100);
try try
{ {
int x = threadPool.NumberOfThreads; var x = threadPool.NumberOfThreads;
Assert.Fail(); Assert.Fail();
} }
catch(Exception e) catch(Exception e)
@@ -63,17 +63,17 @@ namespace System.Threading.Tests
{ {
threadPool.Dispose(); threadPool.Dispose();
threadPool = new PriorityThreadPool(); threadPool = new PriorityThreadPool();
for (int i = 0; i < 10; i++) for (var i = 0; i < 10; i++)
{ {
threadPool.QueueUserWorkItem(o => threadPool.QueueUserWorkItem(o =>
{ {
for (int x = 0; x < 100; x++) for (var x = 0; x < 100; x++)
{ {
System.Diagnostics.Debug.WriteLine(Thread.CurrentThread.ManagedThreadId + " - " + x); System.Diagnostics.Debug.WriteLine(Thread.CurrentThread.ManagedThreadId + " - " + x);
} }
}, null); }, null);
} }
for (int i = 0; i < 10; i++) for (var i = 0; i < 10; i++)
{ {
System.Diagnostics.Debug.WriteLine("====================================="); System.Diagnostics.Debug.WriteLine("=====================================");
System.Diagnostics.Debug.WriteLine("Current threads in threadpool: " + threadPool.NumberOfThreads); System.Diagnostics.Debug.WriteLine("Current threads in threadpool: " + threadPool.NumberOfThreads);
@@ -98,11 +98,11 @@ namespace System.Threading.Tests
{ {
Assert.Fail(); Assert.Fail();
} }
for (int i = 0; i < 10; i++) for (var i = 0; i < 10; i++)
{ {
threadPool.QueueUserWorkItem(o => threadPool.QueueUserWorkItem(o =>
{ {
for (int x = 0; x < 100; x++) for (var x = 0; x < 100; x++)
{ {
System.Diagnostics.Debug.WriteLine(Thread.CurrentThread.ManagedThreadId + " - " + x); System.Diagnostics.Debug.WriteLine(Thread.CurrentThread.ManagedThreadId + " - " + x);
} }
@@ -126,11 +126,11 @@ namespace System.Threading.Tests
{ {
Assert.Fail(); Assert.Fail();
} }
for (int i = 0; i < 10; i++) for (var i = 0; i < 10; i++)
{ {
threadPool.QueueUserWorkItem(o => threadPool.QueueUserWorkItem(o =>
{ {
for (int x = 0; x < 100; x++) for (var x = 0; x < 100; x++)
{ {
switch (Thread.CurrentThread.Priority) switch (Thread.CurrentThread.Priority)
{ {
@@ -153,7 +153,7 @@ namespace System.Threading.Tests
} }
}, null); }, null);
} }
for (int i = 0; i < 50; i++) for (var i = 0; i < 50; i++)
{ {
System.Diagnostics.Debug.WriteLine("====================================="); System.Diagnostics.Debug.WriteLine("=====================================");
System.Diagnostics.Debug.WriteLine("Current threads in threadpool: " + threadPool.NumberOfThreads); System.Diagnostics.Debug.WriteLine("Current threads in threadpool: " + threadPool.NumberOfThreads);
@@ -168,9 +168,9 @@ namespace System.Threading.Tests
{ {
threadPool.Dispose(); threadPool.Dispose();
threadPool = new PriorityThreadPool(); threadPool = new PriorityThreadPool();
for (int i = 0; i < 1000; i++) for (var i = 0; i < 1000; i++)
{ {
TaskPriority taskPriority = TaskPriority.Lowest; var taskPriority = TaskPriority.Lowest;
if(i % 10 == 0) if(i % 10 == 0)
{ {
taskPriority = TaskPriority.Highest; taskPriority = TaskPriority.Highest;