Skip to content

Instantly share code, notes, and snippets.

@Superbil
Created July 21, 2011 09:30
Show Gist options
  • Save Superbil/1096849 to your computer and use it in GitHub Desktop.
Save Superbil/1096849 to your computer and use it in GitHub Desktop.
ArrayList for Serializable use
using System;
using System.Collections.Generic;
using System.Collections;
namespace Serializable
{
[Serializable]
public class CollectionT<T> : IList, ICollection, IEnumerable<T>
{
private ArrayList list;
public CollectionT()
{
list = new ArrayList();
}
#region IEnumerable 成員
public IEnumerator GetEnumerator()
{
return this.list.GetEnumerator();
}
#endregion
#region IEnumerable<T> 成員
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
foreach (T item in list)
yield return item;
}
#endregion
#region ICollection 成員
// for Serializable use
public void CopyTo(Array array, int index)
{
this.list.CopyTo(array, index);
}
public int Count
{
get { return this.list.Count; }
}
public bool IsSynchronized
{
get { return this.list.IsSynchronized; }
}
public object SyncRoot
{
get { return this.list.SyncRoot; }
}
#endregion
#region IList 成員
public int Add(object item)
{
return this.list.Add(item);
}
public int Add(T item)
{
return this.list.Add(item);
}
public void Clear()
{
this.list.Clear();
}
public bool Contains(object item)
{
return this.list.Contains(item);
}
public int IndexOf(object value)
{
return this.list.IndexOf(value);
}
public void Insert(int index, object value)
{
this.list.Insert(index, value);
}
public bool IsFixedSize
{
get { return false; }
}
public bool IsReadOnly
{
get { return false; }
}
public void Remove(object value)
{
this.list.Remove(value);
}
public void Remove(T item)
{
this.list.Remove(item);
}
public void RemoveAt(int index)
{
this.list.RemoveAt(index);
}
public object this[int index]
{
get { return this.list[index]; }
set { this.list[index] = value; }
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment