zoukankan      html  css  js  c++  java
  • IXmlSerializable 实现

    #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

      

  • 相关阅读:
    js固定在顶部
    css垂直居中
    HTML 5离线存储
    jdbc数据库操作
    I/O输入输出流
    异常处理
    java实现冒泡排序算法
    Java 方法
    java 循环 基本类型
    Java中Arrays工具类
  • 原文地址:https://www.cnblogs.com/Googler/p/2127814.html
Copyright © 2011-2022 走看看