Ejemplo n.º 1
0
        /// <summary>
        /// 从XmlDocument中读取数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="xDoc"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static T ReadFromXmlDocument <T>(XmlDocument xDoc, string name)
        {
            var Root = xDoc["Root"];
            var res  = (T)ReXmlSerializer.ReadAny(Root, "TestClass", typeof(T), null);

            return(res);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 写入文档
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static XmlDocument WriteToXmlDocument(string name, object value)
        {
            XmlDocument xDoc = new XmlDocument();
            var         Root = xDoc.CreateElement("Root");

            xDoc.AppendChild(Root);
            ReXmlSerializer.WriteAny(Root, name, value);
            return(xDoc);
        }
Ejemplo n.º 3
0
        private static CodeStatement GetToXElementCodeStatement(FieldInfo info)
        {
            var type = info.FieldType;

            if (ReXmlSerializer.IsPrimitive(type))
            {
                return(new CodeSnippetStatement(
                           string.Format("\t\t\tReXmlSerializer.Write(xElement, \"{0}\", obj.{0});", info.Name)));
            }
            else
            {
                return(new CodeSnippetStatement(
                           string.Format("\t\t\tCustomSerializer.GetSerializer<{0}>().Write(xElement, \"{1}\", obj. {1});",
                                         type.FullName, info.Name)));
            }
        }