wms_serve_m_jingwangchengpin/WmsMobileServe/Utils/XmlUtils.cs

33 lines
711 B
C#
Raw Permalink Normal View History

2025-01-08 15:43:26 +08:00
using System.Reflection.PortableExecutable;
using System.Xml.Serialization;
namespace WmsMobileServe.Utils;
/// <summary>
/// XML 工具类
/// </summary>
public class XmlUtils
{
/// <summary>
/// 格式化xml字符串到实体类
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="xmlString"></param>
/// <returns></returns>
public static T? Deserialize<T>(string xmlString) where T : class
{
try
{
using StringReader reader = new(xmlString);
XmlSerializer xs = new(typeof(T));
T? ret = xs.Deserialize(reader) as T;
return ret;
}
catch { }
return default;
}
}