bitnet /Main/Source/Bittorrent/Source/Bittorrent/Bencode/Collections/List.cs

Language C# Lines 126
MD5 Hash 799666f954f682d71075948b74eee868 Estimated Cost $2,231 (why?)
Repository https://bitnet.svn.codeplex.com/svn View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;

namespace Bittorrent.Bencode.Collections {
    internal class List : Object, IList<Object> {
        private readonly List<Object> _list = new List<Object>();

        public int IndexOf(Object item) {
            Contract.Requires(item != null);

            return _list.IndexOf(item);
        }

        public void Insert(int index, Object item) {
            Contract.Requires(index > 0);
            Contract.Requires(index < _list.Count);
            Contract.Requires(item != null);

            _list.Insert(index, item);
        }

        public void RemoveAt(int index) {
            Contract.Requires(index > 0);
            Contract.Requires(index < _list.Count);

            _list.RemoveAt(index);
        }

        public Object this[int index] {
            get {
                Contract.Requires(index > 0);
                Contract.Requires(index < _list.Count);

                return _list[index]; 
            }
            set {
                Contract.Requires(index > 0);
                Contract.Requires(index < _list.Count);
                Contract.Requires(value != null);

                _list[index] = value; 
            }
        }

        public int Count {
            get { return _list.Count; }
        }

        public bool IsReadOnly {
            get { return false; }
        }

        public void Add(Object item) {
            Contract.Requires(item != null);

            _list.Add(item);
        }

        public void Clear() {
            _list.Clear();
        }

        public bool Contains(Object item) {
            Contract.Requires(item != null);

            return _list.Contains(item);
        }

        public void CopyTo(Object[] array, int arrayIndex) {
            Contract.Requires(array != null);
            Contract.Requires(arrayIndex > 0);
            Contract.Requires(arrayIndex < array.Length);

            _list.CopyTo(array, arrayIndex);
        }

        public bool Remove(Object item) {
            Contract.Requires(item != null);

            return _list.Remove(item);
        }

        public IEnumerator<Object> GetEnumerator() {
            return _list.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator() {
            return GetEnumerator();
        }

        internal override int ByteSize {
            get {
                int size = Encoding.UTF8.GetByteCount("l");

                foreach (var item in _list) {
                    size += item.ByteSize;
                }

                size += Encoding.UTF8.GetByteCount("e");

                return size;
            }
        }

        internal override int Encode(byte[] data, int offset) {
            Contract.Requires(data != null);
            Contract.Requires(offset > 0);
            Contract.Requires(offset < data.Length);

            int written = Encoding.UTF8.GetBytes("l", 0, 1, data, offset);

            foreach (var item in _list) {
                written += item.Encode(data, offset + written);
            }

            written += Encoding.UTF8.GetBytes("e", 0, 1, data, offset + written);

            return written;
        }
    }
}
Back to Top