1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.Collections.Generic; 6 7 namespace System.Net.NetworkInformation 8 { 9 internal class InternalIPAddressCollection : IPAddressCollection 10 { 11 private readonly List<IPAddress> _addresses; 12 InternalIPAddressCollection()13 protected internal InternalIPAddressCollection() 14 { 15 _addresses = new List<IPAddress>(); 16 } 17 InternalIPAddressCollection(List<IPAddress> addresses)18 internal InternalIPAddressCollection(List<IPAddress> addresses) 19 { 20 _addresses = addresses; 21 } 22 CopyTo(IPAddress[] array, int offset)23 public override void CopyTo(IPAddress[] array, int offset) 24 { 25 _addresses.CopyTo(array, offset); 26 } 27 28 public override int Count 29 { 30 get 31 { 32 return _addresses.Count; 33 } 34 } 35 36 public override bool IsReadOnly 37 { 38 get 39 { 40 return true; 41 } 42 } 43 Add(IPAddress address)44 public override void Add(IPAddress address) 45 { 46 throw new NotSupportedException(SR.net_collection_readonly); 47 } 48 InternalAdd(IPAddress address)49 internal void InternalAdd(IPAddress address) 50 { 51 _addresses.Add(address); 52 } 53 Contains(IPAddress address)54 public override bool Contains(IPAddress address) 55 { 56 return _addresses.Contains(address); 57 } 58 59 public override IPAddress this[int index] 60 { 61 get 62 { 63 return _addresses[index]; 64 } 65 } 66 GetEnumerator()67 public override IEnumerator<IPAddress> GetEnumerator() 68 { 69 return _addresses.GetEnumerator(); 70 } 71 } 72 } 73