コード例 #1
0
    static public void SetConfig <T>(this XmlDocument Config, string sKey, T pValue)
    {
        string sPath = ATDefine.Path_Config + Path.DirectorySeparatorChar + Config.ChildNodes[1].Name;

        XmlNode     root     = Config.ChildNodes[1];
        XmlNodeList nodeList = root.ChildNodes;
        var         t        = typeof(T);

        foreach (XmlNode xn in nodeList)
        {
            XmlElement xe = (XmlElement)xn;
            if (xe.Name == sKey && xe.GetAttribute(c_sType) == t.Name)
            {
                xe.InnerText = ATHelper_Serialize.Serialize <T>(pValue);
                Config.Save(sPath);
                return;
            }
        }

        XmlElement xe1 = Config.CreateElement(sKey);

        xe1.SetAttribute(c_sType, typeof(T).Name);
        xe1.InnerText = ATHelper_Serialize.Serialize <T>(pValue);
        root.AppendChild(xe1);
        Config.Save(sPath);
    }
コード例 #2
0
    static public bool GetConfig <T>(this XmlDocument Config, string sKey, ref T result)
    {
        XmlNodeList nodeList = Config.ChildNodes[1].ChildNodes;
        var         t        = typeof(T);

        foreach (XmlNode xn in nodeList)
        {
            XmlElement xe = (XmlElement)xn;
            if (xe.Name == sKey && xe.GetAttribute(c_sType) == t.Name)
            {
                result = ATHelper_Serialize.Deserialize <T>(xe.InnerText);
                return(true);
            }
        }
        return(false);
    }