#region IXmlSerializable 成员
public static MetaEntity Load(string path)
{
using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read))
{
XmlSerializer serializer = new XmlSerializer(typeof(MetaEntity));
return (MetaEntity)serializer.Deserialize(stream);
}
}
public void Save(string path)
{
using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write))
{
XmlSerializer serializer = new XmlSerializer(this.GetType());
serializer.Serialize(stream, this);
}
}
public System.Xml.Schema.XmlSchema GetSchema()
{
throw new NotSupportedException();
}
public void ReadXml(XmlReader reader)
{
lock (stored)
{
this.MappedName = reader.GetAttribute("name");
string spName, typeQualifiedName, propertyQualifiedName;
BindingFlags bingdingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty;
if (reader.ReadToDescendant("storedProcedure"))
{
do
{
spName = reader.GetAttribute("name");
List<TypeConverter> typeList = new List<TypeConverter>();
if (reader.ReadToDescendant("converter"))
{
do
{
TypeConverter type = new TypeConverter(Type.GetType(typeQualifiedName = reader.GetAttribute("qualifiedName")));
if (reader.ReadToDescendant("add"))
{
do
{
PropertyConverter property = new PropertyConverter(reader.GetAttribute("name"), bool.Parse(reader.GetAttribute("nullable")), type.EntityType.GetProperty(propertyQualifiedName = reader.GetAttribute("qualifiedName"), bingdingFlags));
if (property.EntityProperty == null)
{
throw new MappingException(propertyQualifiedName);
}
type.Add(property);
}
while (reader.ReadToNextSibling("add"));
}
typeList.Add(type);
}
while (reader.ReadToNextSibling("converter"));
}
stored.Add(spName, typeList);
}
while (reader.ReadToNextSibling("storedProcedure"));
}
}
}
public void WriteXml(XmlWriter writer)
{
lock (stored)
{
writer.WriteAttributeString("name", this.MappedName);
ArrayList spNameList = new ArrayList(stored.Keys);
spNameList.Sort();
foreach (string spName in spNameList)
{
List<TypeConverter> list = (List<TypeConverter>)stored[spName];
lock (list)
{
writer.WriteStartElement("storedProcedure");
writer.WriteAttributeString("name", spName);
foreach (TypeConverter typeConverter in list)
{
writer.WriteStartElement("converter");
writer.WriteAttributeString("qualifiedName", typeConverter.EntityType.AssemblyQualifiedName);
foreach (PropertyConverter propertyConverter in typeConverter)
{
writer.WriteStartElement("add");
writer.WriteAttributeString("name", propertyConverter.MappedName);
writer.WriteAttributeString("nullable", propertyConverter.IsNullable.ToString());
writer.WriteAttributeString("qualifiedName", propertyConverter.EntityProperty.Name);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
writer.WriteEndElement();
}
}
}
}
#endregion