PageRenderTime 36ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/NekoKun.Serialization.RubyMarshal/Objects/RubyArray.cs

https://bitbucket.org/nekokun/nekokun
C# | 160 lines | 150 code | 10 blank | 0 comment | 0 complexity | ba1a753ff24391593a5fa878eb11890a MD5 | raw file
Possible License(s): MIT, CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace NekoKun.Serialization.RubyMarshal
  5. {
  6. [Serializable]
  7. [System.Diagnostics.DebuggerDisplay("RubyArray: Count = {Count}")]
  8. [System.Diagnostics.DebuggerTypeProxy(typeof(RubyArrayDebugView))]
  9. public class RubyArray : RubyObject, IEnumerable<object>, System.Collections.IEnumerable
  10. {
  11. private List<object> list;
  12. public object this[int index]
  13. {
  14. get
  15. {
  16. return list[index];
  17. }
  18. set
  19. {
  20. list[index] = value;
  21. }
  22. }
  23. IEnumerator<object> IEnumerable<object>.GetEnumerator()
  24. {
  25. return list.GetEnumerator();
  26. }
  27. System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
  28. {
  29. return list.GetEnumerator();
  30. }
  31. public static implicit operator List<object>(RubyArray that)
  32. {
  33. return that.list;
  34. }
  35. public static implicit operator RubyArray(List<object> that)
  36. {
  37. return new RubyArray(that);
  38. }
  39. public RubyArray()
  40. {
  41. list = new List<object>();
  42. this.ClassName = RubySymbol.GetSymbol("Array");
  43. }
  44. public RubyArray(IEnumerable<object> collection)
  45. {
  46. list = new List<object>(collection);
  47. this.ClassName = RubySymbol.GetSymbol("Array");
  48. }
  49. public RubyArray(int capacity)
  50. {
  51. list = new List<object>(capacity);
  52. this.ClassName = RubySymbol.GetSymbol("Array");
  53. }
  54. public int Capacity { get { return list.Capacity; } set { list.Capacity = value; } }
  55. public int Count { get { return list.Count; } }
  56. public int Size { get { return list.Count; } }
  57. public int Length { get { return list.Count; } }
  58. public void Add(object item) { list.Add(item); }
  59. public void AddRange(IEnumerable<object> collection) { list.AddRange(collection); }
  60. public System.Collections.ObjectModel.ReadOnlyCollection<object> AsReadOnly() { return list.AsReadOnly(); }
  61. public int BinarySearch(object item) { return list.BinarySearch(item); }
  62. public int BinarySearch(object item, IComparer<object> comparer) { return list.BinarySearch(item, comparer); }
  63. public int BinarySearch(int index, int count, object item, IComparer<object> comparer) { return list.BinarySearch(index, count, item, comparer); }
  64. public void Clear() { list.Clear(); }
  65. public bool Contains(object item) { return list.Contains(item); }
  66. public List<TOutput> ConvertAll<TOutput>(Converter<object, TOutput> converter) { return list.ConvertAll<TOutput>(converter); }
  67. public void CopyTo(object[] array) { list.CopyTo(array); }
  68. public void CopyTo(object[] array, int arrayIndex) { list.CopyTo(array, arrayIndex); }
  69. public void CopyTo(int index, object[] array, int arrayIndex, int count) { list.CopyTo(index, array, arrayIndex, count); }
  70. public bool Exists(Predicate<object> match) { return list.Exists(match); }
  71. public object Find(Predicate<object> match) { return list.Find(match); }
  72. public List<object> FindAll(Predicate<object> match) { return list.FindAll(match); }
  73. public int FindIndex(Predicate<object> match) { return list.FindIndex(match); }
  74. public int FindIndex(int startIndex, Predicate<object> match) { return list.FindIndex(startIndex, match); }
  75. public int FindIndex(int startIndex, int count, Predicate<object> match) { return list.FindIndex(startIndex, count, match); }
  76. public object FindLast(Predicate<object> match) { return list.FindLast(match); }
  77. public int FindLastIndex(Predicate<object> match) { return list.FindLastIndex(match); }
  78. public int FindLastIndex(int startIndex, Predicate<object> match) { return list.FindLastIndex(startIndex, match); }
  79. public int FindLastIndex(int startIndex, int count, Predicate<object> match) { return list.FindLastIndex(startIndex, count, match); }
  80. public void ForEach(Action<object> action) { list.ForEach(action); }
  81. public List<object>.Enumerator GetEnumerator() { return list.GetEnumerator(); }
  82. public List<object> GetRange(int index, int count) { return list.GetRange(index, count); }
  83. public int IndexOf(object item) { return list.IndexOf(item); }
  84. public int IndexOf(object item, int index) { return list.IndexOf(item, index); }
  85. public int IndexOf(object item, int index, int count) { return list.IndexOf(item, index); }
  86. public void Insert(int index, object item) { list.Insert(index, item); }
  87. public void InsertRange(int index, IEnumerable<object> collection) { list.InsertRange(index, collection); }
  88. public int LastIndexOf(object item) { return list.LastIndexOf(item); }
  89. public int LastIndexOf(object item, int index) { return list.LastIndexOf(item, index); }
  90. public int LastIndexOf(object item, int index, int count) { return list.LastIndexOf(item, index, count); }
  91. public bool Remove(object item) { return list.Remove(item); }
  92. public int RemoveAll(Predicate<object> match) { return list.RemoveAll(match); }
  93. public void RemoveAt(int index) { list.RemoveAt(index); }
  94. public void RemoveRange(int index, int count) { list.RemoveRange(index, count); }
  95. public void Reverse() { list.Reverse(); }
  96. public void Reverse(int index, int count) { list.Reverse(index, count); }
  97. public void Sort() { list.Sort(); }
  98. public void Sort(Comparison<object> comparison) { list.Sort(comparison); }
  99. public void Sort(IComparer<object> comparer) { list.Sort(comparer); }
  100. public void Sort(int index, int count, IComparer<object> comparer) { list.Sort(index, count, comparer); }
  101. public object[] ToArray() { return list.ToArray(); }
  102. public void TrimExcess() { list.TrimExcess(); }
  103. public bool TrueForAll(Predicate<object> match) { return list.TrueForAll(match); }
  104. public List<TOutput> Map<TOutput>(Converter<object, TOutput> converter) { return list.ConvertAll<TOutput>(converter); }
  105. public List<TOutput> Collect<TOutput>(Converter<object, TOutput> converter) { return list.ConvertAll<TOutput>(converter); }
  106. public void Each(Action<object> action) { Array.ForEach<object>(this.ToArray(), action); }
  107. public void Push(object item) {
  108. list.Add(item);
  109. }
  110. public void Push(params object[] items)
  111. {
  112. list.AddRange(items);
  113. }
  114. public object Pop() {
  115. object obj = list[list.Count - 1];
  116. list.RemoveAt(list.Count - 1);
  117. return obj;
  118. }
  119. public object Shift()
  120. {
  121. object obj = list[0];
  122. list.RemoveAt(0);
  123. return obj;
  124. }
  125. public void Unshift(object item)
  126. {
  127. list.Insert(0, item);
  128. }
  129. public void Unshift(params object[] items)
  130. {
  131. list.InsertRange(0, items);
  132. }
  133. internal class RubyArrayDebugView
  134. {
  135. private RubyArray hashtable;
  136. public RubyArrayDebugView(RubyArray hashtable)
  137. {
  138. this.hashtable = hashtable;
  139. }
  140. [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.RootHidden)]
  141. public object[] Objects
  142. {
  143. get
  144. {
  145. return this.hashtable.ToArray();
  146. }
  147. }
  148. }
  149. }
  150. }