nGallery源码分析(关于对xml反序列化的一点猜想)---比较菜:)

前段时间应bestcomy兄弟的,提议,我对nGallery一个开源的WEB电子相册项目(见http://www.ngallery.org)做了部分本地化的工作.

当时纯属偶然我修改了它的数据配置文件ngallery.config把

<?xml version="1.0"?>
<Configuration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

......

.....
</Configuration>
我把上面改为
<Configuration1 xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

......

.....
</Configuration1>

结果出在类Configuration中出现异常

using  System;
using  System.Web;
using  System.IO;
using  System.Xml.Serialization;

namespace  nGallery.Lib
{
    
    
    
RewriteType Enum

    
    
/// <summary>
    
/// <c>Configuration</c> provides an object that contains all
    
/// the application configuration settings.
    
/// </summary>

    [Serializable]
    
public class Configuration
    
{


        
Private Members


        
Constructor


        
Public Properties


        
Static Methods


    }

}

然出现异常的代码是Load()方法里的这一句
_currentConfiguration = (Configuration) ser.Deserialize(reader);显然是因为没有  [XmlRoot("Configuration", Namespace=nGrallery.Lib)]

于是我上面类Configuration里的几个属性改为只读(去掉set属性),结果反序列化可以成功,查看得知那几个被我修改为只读属性的字段值为null。还不死心,我把配置文件ngallery.config里部分结点给去掉,反序列化还是可以成功。。。。

那可想,.net框架底层在处理反序列化时在内存中的映射是通过命名空间(或[XmlRoot(name)]/[XmlElement(name)]/[XmlAttribute("name")..])来映射的,至于对配置节到类属性字段的映射则是匹配不成功就跳过呢?
如果这样的话,那些没有加载到内存中的XML数据很多将会没有什么意义,有没有好的算法来解决这个问题呢?期待中...
有点迷惑

 


 

 

你可能感兴趣的:(gallery)