* MulticastOption.Group no longer accepts null.
MulticastOption.Group is not supposed to accept null. If someone sets it to null, we will NRE inside of the Sockets implementation.
I also fixed two small double-cast problems while I was in here.
Fix #32490
return !(packetInformation1 == packetInformation2);
}
- public override bool Equals(object comparand)
- {
- return comparand is IPPacketInformation && this == (IPPacketInformation)comparand;
- }
+ public override bool Equals(object comparand) =>
+ comparand is IPPacketInformation other && this == other;
public override int GetHashCode()
{
}
set
{
- _group = value;
+ _group = value ?? throw new ArgumentNullException(nameof(value));
}
}
}
set
{
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- _group = value;
+ _group = value ?? throw new ArgumentNullException(nameof(value));
}
}
/// </summary>
/// <param name="obj">The object to compare with this instance</param>
/// <returns>true if obj is an instance of <see cref="UdpReceiveResult"/> and equals the value of the instance; otherwise, false</returns>
- public override bool Equals(object obj)
- {
- if (!(obj is UdpReceiveResult))
- {
- return false;
- }
-
- return Equals((UdpReceiveResult)obj);
- }
+ public override bool Equals(object obj) =>
+ obj is UdpReceiveResult other && Equals(other);
/// <summary>
/// Returns a value that indicates whether this instance is equal to a specified object
var option = new MulticastOption(IPAddress.Any);
Assert.Same(IPAddress.Any, option.Group);
- option.Group = null;
- Assert.Null(option.Group);
+ AssertExtensions.Throws<ArgumentNullException>("value", () => option.Group = null);
option.Group = IPAddress.Broadcast;
Assert.Same(IPAddress.Broadcast, option.Group);