moel@165: /*
moel@165:  
moel@344:   This Source Code Form is subject to the terms of the Mozilla Public
moel@344:   License, v. 2.0. If a copy of the MPL was not distributed with this
moel@344:   file, You can obtain one at http://mozilla.org/MPL/2.0/.
moel@165:  
moel@344:   Copyright (C) 2009-2010 Michael Möller <mmoeller@openhardwaremonitor.org>
moel@344: 	
moel@165: */
moel@165: 
moel@165: using System.Collections;
moel@165: using System.Collections.Generic;
moel@165: 
moel@165: namespace OpenHardwareMonitor.Collections {
moel@165: 
moel@165:   public class ReadOnlyArray<T> : IReadOnlyArray<T> {
moel@165: 
moel@195:     private readonly T[] array;
moel@165: 
moel@165:     public ReadOnlyArray(T[] array) {
moel@165:       this.array = array;
moel@165:     }
moel@165: 
moel@165:     public T this[int index] {
moel@165:       get { return array[index]; }
moel@165:     }
moel@165: 
moel@165:     public int Length { get { return array.Length; } }
moel@165: 
moel@165:     public IEnumerator<T> GetEnumerator() {
moel@165:       return ((IEnumerable<T>)array).GetEnumerator();
moel@165:     }
moel@165: 
moel@165:     IEnumerator IEnumerable.GetEnumerator() {
moel@165:       return array.GetEnumerator();
moel@165:     }
moel@165: 
moel@165:     public static implicit operator ReadOnlyArray<T>(T[] array) {
moel@165:       return new ReadOnlyArray<T>(array);
moel@165:     }
moel@167: 
moel@167:     public T[] ToArray() {
moel@167:       return (T[])array.Clone();
moel@167:     }
moel@165:   }
moel@165: }