aboutsummaryrefslogtreecommitdiff
path: root/cs-dotnet/src/gatslist.cs
diff options
context:
space:
mode:
Diffstat (limited to 'cs-dotnet/src/gatslist.cs')
-rw-r--r--cs-dotnet/src/gatslist.cs135
1 files changed, 135 insertions, 0 deletions
diff --git a/cs-dotnet/src/gatslist.cs b/cs-dotnet/src/gatslist.cs
new file mode 100644
index 0000000..d111bac
--- /dev/null
+++ b/cs-dotnet/src/gatslist.cs
@@ -0,0 +1,135 @@
1using System;
2using System.IO;
3using System.Text;
4using System.Collections;
5using System.Collections.Generic;
6
7namespace Com.Xagasoft.Gats
8{
9 public class GatsList : GatsObject, IList<GatsObject>,
10 ICollection<GatsObject>, IEnumerable<GatsObject>
11// IReadOnlyList<GatsObject>, IReadOnlyCollection<GatsObject>,
12// These two are in .net 4.5, not 4.0, mono can't use them.
13 {
14 private List<GatsObject> Value = new List<GatsObject>();
15
16 public GatsList()
17 {
18 }
19
20 public override string ToString()
21 {
22 StringBuilder bld = new StringBuilder();
23 bld.Append("[");
24 for( int j = 0; j < Value.Count-1; j++ )
25 {
26 bld.Append( Value[j] );
27 bld.Append(", ");
28 }
29 bld.Append( Value[Value.Count-1] );
30 bld.Append("]");
31 return bld.ToString();
32 }
33
34 public override void Read( Stream s, char type )
35 {
36 for(;;)
37 {
38 GatsObject obj = GatsObject.Read( s );
39 if( obj == null )
40 break;
41 Value.Add( obj );
42 }
43 }
44
45 public override void Write( Stream s )
46 {
47 s.WriteByte( (int)'l' );
48 foreach( GatsObject obj in Value )
49 {
50 obj.Write( s );
51 }
52 s.WriteByte( (int)'e' );
53 }
54
55 //
56 // List interface overrides under here.
57 //
58 public int IndexOf( GatsObject obj )
59 {
60 return Value.IndexOf( obj );
61 }
62
63 public void Insert( int idx, GatsObject obj )
64 {
65 Value.Insert( idx, obj );
66 }
67
68 public void RemoveAt( int idx )
69 {
70 Value.RemoveAt( idx );
71 }
72
73 public GatsObject this[int idx] {
74 get { return this.Value[idx]; }
75 set { this.Value[idx] = value; }
76 }
77
78 public int Count {
79 get { return this.Value.Count; }
80 }
81
82 public bool IsReadOnly {
83 get { return false; } // this.Value.IsReadOnly; }
84 }
85
86 public void Add( GatsObject obj )
87 {
88 Value.Add( obj );
89 }
90
91 public void Clear()
92 {
93 Value.Clear();
94 }
95
96 public bool Contains( GatsObject obj )
97 {
98 return Value.Contains( obj );
99 }
100
101 public void CopyTo( GatsObject[] result, int count )
102 {
103 Value.CopyTo( result, count );
104 }
105
106 public bool Remove( GatsObject obj )
107 {
108 return Value.Remove( obj );
109 }
110
111 IEnumerator<GatsObject> IEnumerable<GatsObject>.GetEnumerator()
112 {
113 return Value.GetEnumerator();
114 }
115
116 IEnumerator IEnumerable.GetEnumerator()
117 {
118 return Value.GetEnumerator();
119 }
120
121 public bool IsFixedSize {
122 get { return false; } // this.Value.IsFixedSize; }
123 }
124
125 public bool IsSynchronized {
126 get { return false; } // this.Value.IsSynchronized; }
127 }
128
129 public object SyncRoot {
130 get { return null; } // this.Value.SyncRoot; }
131 }
132
133 }
134}
135