ClassLibraryWeiBao/weiweixin/MessageHelper.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml;
namespace WeiWeixiN.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
{
writer.WriteValue(p.GetValue(obj, null));
}
writer.WriteEndElement();
}
writer.Flush();
writer.Close();
return sb.ToString();
后面还有 14 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。