Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix documentation and unit test #301

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/securitycodescan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ on:
branches: [ "master" ]
schedule:
- cron: '35 15 * * 1'


env:
DOTNET_ROLL_FORWARD: Major

jobs:
SCS:
runs-on: windows-latest
Expand Down
11 changes: 11 additions & 0 deletions src/System.Net.IPNetwork/IPNetwork2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,17 @@
string[] args = network.Split(new char[] { ' ', '/' }, splitOptions);
byte cidr = 0;

if (args.Length == 0)
{
if (tryParse == false)
{
throw new ArgumentNullException("network");
}

ipnetwork = null;
return;
}

if (args.Length == 1)
{
string cidrlessNetwork = args[0];
Expand Down Expand Up @@ -1429,7 +1440,7 @@
/// Gets 10.0.0.0/8.
/// </summary>
/// <returns>The IANA reserved IPNetwork 10.0.0.0/8.<returns>
public static IPNetwork2 IANA_ABLK_RESERVED1

Check warning on line 1443 in src/System.Net.IPNetwork/IPNetwork2.cs

View workflow job for this annotation

GitHub Actions / build

XML comment has badly formed XML -- 'Expected an end tag for element 'returns'.'

Check warning on line 1443 in src/System.Net.IPNetwork/IPNetwork2.cs

View workflow job for this annotation

GitHub Actions / build

XML comment has badly formed XML -- 'Expected an end tag for element 'returns'.'
{
get
{
Expand All @@ -1453,7 +1464,7 @@
/// Gets 192.168.0.0/16.
/// </summary>
/// <returns>The IANA reserved IPNetwork 192.168.0.0/16.<returns>
public static IPNetwork2 IANA_CBLK_RESERVED1

Check warning on line 1467 in src/System.Net.IPNetwork/IPNetwork2.cs

View workflow job for this annotation

GitHub Actions / build

XML comment has badly formed XML -- 'Expected an end tag for element 'returns'.'

Check warning on line 1467 in src/System.Net.IPNetwork/IPNetwork2.cs

View workflow job for this annotation

GitHub Actions / build

XML comment has badly formed XML -- 'Expected an end tag for element 'returns'.'
{
get
{
Expand Down Expand Up @@ -2338,9 +2349,9 @@
#region ISerializable
internal struct IPNetworkInteral
{
public BigInteger IPAddress;

Check warning on line 2352 in src/System.Net.IPNetwork/IPNetwork2.cs

View workflow job for this annotation

GitHub Actions / build

Field 'IPNetwork2.IPNetworkInteral.IPAddress' is never assigned to, and will always have its default value

Check warning on line 2352 in src/System.Net.IPNetwork/IPNetwork2.cs

View workflow job for this annotation

GitHub Actions / build

Field 'IPNetwork2.IPNetworkInteral.IPAddress' is never assigned to, and will always have its default value
public byte Cidr;

Check warning on line 2353 in src/System.Net.IPNetwork/IPNetwork2.cs

View workflow job for this annotation

GitHub Actions / build

Field 'IPNetwork2.IPNetworkInteral.Cidr' is never assigned to, and will always have its default value 0

Check warning on line 2353 in src/System.Net.IPNetwork/IPNetwork2.cs

View workflow job for this annotation

GitHub Actions / build

Field 'IPNetwork2.IPNetworkInteral.Cidr' is never assigned to, and will always have its default value 0
public AddressFamily AddressFamily;

Check warning on line 2354 in src/System.Net.IPNetwork/IPNetwork2.cs

View workflow job for this annotation

GitHub Actions / build

Field 'IPNetwork2.IPNetworkInteral.AddressFamily' is never assigned to, and will always have its default value

Check warning on line 2354 in src/System.Net.IPNetwork/IPNetwork2.cs

View workflow job for this annotation

GitHub Actions / build

Field 'IPNetwork2.IPNetworkInteral.AddressFamily' is never assigned to, and will always have its default value
}

private IPNetwork2(SerializationInfo info, StreamingContext context)
Expand Down
23 changes: 22 additions & 1 deletion src/System.Net.IPNetwork/IPNetworkCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ namespace System.Net
using System.Collections.Generic;
using System.Numerics;

/// <summary>
/// A collection of IPNetwork2
/// </summary>
public class IPNetworkCollection : IEnumerable<IPNetwork2>, IEnumerator<IPNetwork2>
{
private BigInteger _enumerator;
Expand Down Expand Up @@ -59,6 +62,9 @@ private BigInteger _network

#region Count, Array, Enumerator

/// <summary>
/// Count the nnumber of IPAddresses in a IPNetworkCollection
/// </summary>
public BigInteger Count
{
get
Expand Down Expand Up @@ -102,6 +108,9 @@ IEnumerator IEnumerable.GetEnumerator()

#region IEnumerator<IPNetwork> Members

/// <summary>
/// Gets the current IEnumerator item
/// </summary>
public IPNetwork2 Current
{
get { return this[this._enumerator]; }
Expand All @@ -111,6 +120,9 @@ public IPNetwork2 Current

#region IDisposable Members

/// <summary>
/// Dispose the IPNetwork instance
/// </summary>
public void Dispose()
{
// nothing to dispose
Expand All @@ -120,12 +132,18 @@ public void Dispose()
#endregion

#region IEnumerator Members

/// <summary>
/// Gets the element in the collection at the current position of the enumerator.
/// </summary>
object IEnumerator.Current
{
get { return this.Current; }
}

/// <summary>
/// Advances the enumerator to the next element of the collection.
/// </summary>
/// <returns>true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.</returns>
public bool MoveNext()
{
this._enumerator++;
Expand All @@ -137,6 +155,9 @@ public bool MoveNext()
return true;
}

/// <summary>
/// Sets the enumerator to its initial position, which is before the first element in the collection.
/// </summary>
public void Reset()
{
this._enumerator = -1;
Expand Down
10 changes: 10 additions & 0 deletions src/TestProject/TryParseUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,5 +333,15 @@ public void Test_IPAddress_TryParse(string ipaddress, bool parsed)
}

#endregion

#region Issue294

[TestMethod]
public void Test_IPNetwork_TryParse_Issue294()
{
bool result = IPNetwork2.TryParse("*", out IPNetwork2 ipaddress1);
Assert.AreEqual(false, result, "parsed1");
}
#endregion
}
}
Loading