<?xml version="1.0"?>
<ArrayOfCodeEntity xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CodeEntity>
<Id>1</Id>
<Key>????</Key>
<Lang>C#</Lang>
<RealContent>e1</RealContent>
</CodeEntity>
<CodeEntity>
<Id>2</Id>
<Key>????1</Key>
<Lang>C#</Lang>
<RealContent>e1</RealContent>
</CodeEntity>
</ArrayOfCodeEntity>

 

???????????????????????????????п???????????????
???????
??????????
???????????????????????????
???????????
?????????????С?????200???????
??????????
????Ч?????
????δ????????????????
????????????????????????????????????????????????ι?????
????????????????

 

using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Xml.Serialization;
namespace Wisdombud.xmldb
{
public class XmlSerializerBll<T>
{
private static XmlSerializerBll<T> instance;
private string dbFile;
public string Dbfile
{
get { return dbFile; }
set
{
if (!string.IsNullOrEmpty(value) && !value.Equals(dbFile))
{
this.entityList.Clear();
}
dbFile = value;
this.ReadDb();
}
}
private List<T> entityList = new List<T>();
private XmlSerializerBll()
{
this.SetDbFile();
this.ReadDb();
}
private void SetDbFile()
{
string folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory?? "data");
try
{
if (Directory.Exists(folder) == false)
{
Directory.CreateDirectory(folder);
}
Type type = typeof(T);
if (string.IsNullOrEmpty(this.Dbfile))
{ this.Dbfile = Path.Combine(folder?? type.Name + ".xml"); }
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public static XmlSerializerBll<T> GetInstance()
{
if (instance == null)
{
instance = new XmlSerializerBll<T>();
}
return instance;
}
public void Insert(T entity)
{
this.entityList.Add(entity);
this.WriteDb();
}
public void InsertRange(IList<T> list)
{
this.entityList.AddRange(list);
this.WriteDb();
}
public System.Collections.Generic.List<T> SelectBy(string name?? Object value)
{
System.Collections.Generic.List<T> list = new List<T>();
if (value == null)
{
return list;
}
Type t = typeof(T);
foreach (var inst in this.entityList)
{
foreach (PropertyInfo pro in t.GetProperties())
{
if (pro.Name.ToLower() == name.ToLower())
{
if (value.ToString() == (pro.GetValue(inst?? null) ?? string.Empty).ToString())
{
list.Add(inst);
}
}
}
}
return list;
}