Td.Weixin.Public/Message/MessageHelper.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

/*******************************
 *	Author:	Dong [mailto:techdong@hotmail.com] 欢迎交流 Q群:289147891
 *	Date:	2013-09-04 22:51:46
 *	Desc:	
 * 
*******************************/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml;

namespace Td.Weixin.Public.Message
{
    public class MessageHelper
    {
        /// <summary>
        /// 将指定对象的带[Output]标识的属性序列化为xml文本
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string ToXmlText(object obj)
        {
            return ToXmlText(obj, GetOutputPropertyInfos(obj));
        }

        /// <summary>
        /// 将指定对象的指定属性列表序列化为xml文本。
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="ps"></param>
        /// <returns></returns>
        public static string ToXmlText(object obj, IEnumerable<PropertyInfo> ps)
        {
            var sb = new StringBuilder();
            var settings = new XmlWriterSettings
            {
                OmitXmlDeclaration = true,
                ConformanceLevel = ConformanceLevel.Fragment,
                Indent = true,
                CloseOutput = false
            };
            var writer = XmlWriter.Create(sb, settings);
            foreach (var p in ps)
            {
                writer.WriteStartElement(p.Name);
                //字符串返回CDATA节点
                if (p.PropertyType == typeof(string))
                {
                    writer.WriteCData(Convert.ToString(p.GetValue(obj, null)));
                }
                else if (p.PropertyType == typeof(MessageType))
                {
                    writer.WriteCData(MessageTypeAttribute.ObtainMessageType((MessageType)p.GetValue(obj, null)));
                }
                else
                {
后面还有 21 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。