Adding reference source for System.Net
[mono.git] / mcs / class / referencesource / System / net / System / Net / Sockets / UdpReceiveResult.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="UDPClient.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 //------------------------------------------------------------------------------
6
7 namespace System.Net.Sockets
8 {
9     using System.Threading;
10     using System.Threading.Tasks;
11     using System.Security.Permissions;
12     using System.Diagnostics.CodeAnalysis;
13
14     public struct UdpReceiveResult : IEquatable<UdpReceiveResult>
15     {
16         private byte[] m_buffer;
17         private IPEndPoint m_remoteEndPoint;
18
19         public UdpReceiveResult(byte[] buffer, IPEndPoint remoteEndPoint)
20         {
21             if (buffer == null)
22             {
23                 throw new ArgumentNullException("buffer");
24             }
25
26             if (remoteEndPoint == null)
27             {
28                 throw new ArgumentNullException("remoteEndPoint");
29             }
30
31             m_buffer = buffer;
32             m_remoteEndPoint = remoteEndPoint;
33         }
34
35         [SuppressMessage("Microsoft.Performance","CA1819:PropertiesShouldNotReturnArrays",
36             Justification="This is merely strongly type data aggregation")]
37         public byte[] Buffer
38         {
39             get
40             {
41                 return m_buffer;
42             }
43         }
44
45         public IPEndPoint RemoteEndPoint
46         {
47             get
48             {
49                 return m_remoteEndPoint;
50             }
51         }
52
53         public override int GetHashCode()
54         {
55             return (m_buffer != null) ? (m_buffer.GetHashCode() ^ m_remoteEndPoint.GetHashCode()) : 0;
56         }
57
58         public override bool Equals(object obj)
59         {
60             if (!(obj is UdpReceiveResult))
61             {
62                 return false;
63             }
64
65             return Equals((UdpReceiveResult)obj);
66         }
67
68         public bool Equals(UdpReceiveResult other)
69         {
70             return object.Equals(this.m_buffer, other.m_buffer) && object.Equals(this.m_remoteEndPoint, other.m_remoteEndPoint);
71         }
72
73         public static bool operator ==(UdpReceiveResult left, UdpReceiveResult right)
74         {
75             return left.Equals(right);
76         }
77
78         public static bool operator !=(UdpReceiveResult left, UdpReceiveResult right)
79         {
80             return !left.Equals(right);
81         }
82     }
83
84 }
85