1
0

Solution restructured to use multiple test projects

This commit is contained in:
2024-07-04 18:22:26 +02:00
parent 508379d704
commit df6763b99b
144 changed files with 387 additions and 1693 deletions

View File

@@ -0,0 +1,52 @@
namespace System.Net
{
/// <summary>
/// Provides extension methods for <see cref="IPAddress"/>es.
/// </summary>
public static class IPAddressExtensions
{
/// <summary>
/// Increments the <see cref="IPAddress"/> by one and returns a new instance.
/// </summary>
/// <param name="address">The <see cref="IPAddress"/> to increment.</param>
public static IPAddress Increment(this IPAddress address)
{
byte[] bytes = address.GetAddressBytes();
int bytePos = bytes.Length - 1;
while (bytes[bytePos] == byte.MaxValue)
{
bytes[bytePos] = 0;
bytePos--;
if (bytePos < 0)
return new IPAddress(bytes);
}
bytes[bytePos]++;
return new IPAddress(bytes);
}
/// <summary>
/// Decrements the <see cref="IPAddress"/> by one and returns a new instance.
/// </summary>
/// <param name="address">The <see cref="IPAddress"/> to decrement.</param>
public static IPAddress Decrement(this IPAddress address)
{
byte[] bytes = address.GetAddressBytes();
int bytePos = bytes.Length - 1;
while (bytes[bytePos] == 0)
{
bytes[bytePos] = byte.MaxValue;
bytePos--;
if (bytePos < 0)
return new IPAddress(bytes);
}
bytes[bytePos]--;
return new IPAddress(bytes);
}
}
}