public class ModelBase {
public int ID { get; set; }
public ModelBase(){
}
public ModelBase(int id)
{
this.ID = id;
}
}
---------------------------------------------------------------------------------------
public class BaseProxy <T>where T: ModelBase,new() {
protected List<T> modelList;
public BaseProxy()
{
modelList = new List<T>();
}
public bool TryGetModel(int id, out T model)
{
model = this.modelList.FirstOrDefault(a => a.ID == id);
if (model == null)
{
return false;
}
else
{
return true;
}
}
}
--------------------------------------------
public class GoodsProxy:BaseProxy<GoodsModel> {
public GoodsProxy():base()
{
this.AddModelToList(new GoodsModel(this.GetMaxId()+1, "Goods0"));
this.AddModelToList(new GoodsModel(this.GetMaxId()+1, "goods1"));
this.AddModelToList(new GoodsModel(this.GetMaxId()+1, "goods2"));
}
private static GoodsProxy GoodProxy;
internal static GoodsProxy GetIntance()
{
if (GoodProxy==null)
{
GoodProxy = new GoodsProxy();
}
return GoodProxy;
}
}
-------------------------------------------------------
public class PackProxy:BaseProxy<PackModel> {
public PackProxy():base()
{
for (int i = 0; i < 15; i++)
{
this.AddModelToList(new PackModel(i));
}
}
public PackModel GetEmptyModel()
{
return this.modelList.FirstOrDefault(a => a.GoodId == 0);
}
internal bool TryGetGoodModel(int id,out PackModel model)
{
model = null;
model = this.modelList.FirstOrDefault(a => a.GoodId == id);
if (model==null)
{
return false;
}
else
{
return true;
}
}
private static PackProxy packProxy;
internal static PackProxy GetIntance()
{
if (packProxy==null)
{
packProxy = new PackProxy();
}
return packProxy;
}
}
