fix(openai): 修复无法 XML 序列化派生类的问题

This commit is contained in:
Fu Diwei
2022-11-21 13:55:13 +08:00
parent 508ef1f72a
commit 154eea7ac2
2 changed files with 22 additions and 0 deletions

View File

@@ -60,6 +60,11 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Utilities
return Serialize(typeof(T), obj);
}
public static string Serialize(object obj)
{
return Serialize(obj.GetType(), obj);
}
public static object Deserialize(Type type, string xml)
{
using var reader = new StringReader(xml);

View File

@@ -0,0 +1,17 @@
using Xunit;
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests
{
public class TestCase_XmlUtilityTests
{
[Fact(DisplayName = "测试用例XML 序列化派生类")]
public void TestXmlSerializeSubClass()
{
Assert.Null(Record.Exception(() =>
{
object obj = new Models.SignRequest() { UserId = "TEST" };
Utilities.XmlUtility.Serialize(obj);
}));
}
}
}