核心存取(Indexer)部分还没有开始写,但是半成品大家如果有兴趣可以读一读
using System;
using System.Drawing;
using System.Collections;
namespace mdb_t
{
public class AddItemEventArgs:EventArgs
{
public AddItemEventArgs(int han)
{
hang = han;
}
private int hang;
public int Addnum{get{return hang;}}
}
public class RemoveItemEventArgs:EventArgs
{
public RemoveItemEventArgs(int han)
{
hang = han;
}
private int hang;
public int Movenum{get{return hang;}}
}
public class SetItemEventArgs:EventArgs
{
public SetItemEventArgs(int han,int lies,object Value)
{
hang = han;
lie = lies;
valu = Value;
}
private int lie;
public int Lienum{get{return lie;}}
private int hang;
public int Hangnum{get{return hang;}}
private object valu;
public object val_object{get{return valu;}}
}
public class Collecter
{
public delegate void Delegate_AddItem(object sender,AddItemEventArgs e);//AddItem的delegate
public event Delegate_AddItem OnItemAdd = null;//AddItem的Event
public delegate void Delegate_ReMoveItem(object sender,RemoveItemEventArgs e);//RemoveItem的delegate
public event Delegate_ReMoveItem OnItemRemove = null;//RemoveItem的Event
public delegate void Delegate_SetItem(object sender,SetItemEventArgs e);//设置Item的delegate
public event Delegate_SetItem OnItemSet = null;//设置item的event
public Collecter()
{
}
protected virtual bool AddItem(int hang)//这个方法用来增加行
{
this.OnItemAdd(this,new AddItemEventArgs(hang));//发出AddItem的事件
return true;
}
protected virtual bool RemoveItem(int hang)//这个方法用来删除行
{
this.OnItemRemove(this,new RemoveItemEventArgs(hang));//发出RemoveItem的事件
return true;
}
}
public enum LieType
{
str = 0,
num = 1,
bytes = 2,
image = 3,
}
public class Lie
{
public Lie(LieType l,Collecter c)
{
this._lType=l;
c.OnItemAdd+=new mdb_t.Collecter.Delegate_AddItem(c_OnItemAdd);
c.OnItemRemove+=new mdb_t.Collecter.Delegate_ReMoveItem(c_OnItemRemove);
c.OnItemSet+=new mdb_t.Collecter.Delegate_SetItem(c_OnItemSet);
}
LieType _lType;
public LieType LieType
{
get{return this._lType;}
}
private ArrayList items = new ArrayList();
private void c_OnItemAdd(object sender, AddItemEventArgs e)
{
items.Insert(e.Addnum,getobject());
}
private void c_OnItemRemove(object sender, RemoveItemEventArgs e)
{
this.items.Remove(items[e.Movenum]);
}
private void c_OnItemSet(object sender, SetItemEventArgs e)
{
}
private object getobject()
{
if(_lType == LieType.str)
return "";
else if(_lType == LieType.num)
return 0;
else if(_lType == LieType.bytes)
return (byte)0;
else if(_lType == LieType.image)
return null;
else return null;
}
public static bool operator==(Lie l,object ob)//判断object是否符合这个列的类型
{
if(l.LieType==LieType.str&ob is string)
return true;
else if(l.LieType==LieType.num&ob is double)
return true;
else if(l.LieType==LieType.bytes&ob is byte[])
return true;
else if(l.LieType==LieType.image&ob is Image)
return true;
else return false;
}
public static bool operator!=(Lie l,object ob)//判断object是否不符合这个列的类型
{
if(l.LieType==LieType.str&ob is string)
return false;
else if(l.LieType==LieType.num&ob is double)
return false;
else if(l.LieType==LieType.bytes&ob is byte[])
return false;
else if(l.LieType==LieType.image&ob is Image)
return false;
else return true;
}
}
}