c# - ServiceStack JSONSerializer 和 HashSet<x>

标签 c# asp.net json servicestack

我们有这段代码:

// using ServiceStack JSONSerializer
string typeInfoString = JsonSerializer.SerializeToString<Type>(typeof(HashSet<string>));
// yields "System.Collections.Generic.HashSet`1[[System.String, mscorlib]], System.Core"

// this string is the same thing, so it's probably valid json
string jsonTypeInfo = typeof(HashSet<string>).ToJson();

// this should work, I feel like
Type desType = JsonSerializer.DeserializeFromString<Type>(jsonTypeInfo);
// but desType ends up being null :(

ServiceStack 是否存在关于 HashSet 类型的一些问题?

最佳答案

虽然这不是最好的答案,但您可以通过创建一个继承自 HashSet 的本地类来解决这个问题。

例子:

public class HashSetHack<T> : HashSet<T> { }

然后引用 HashSetHack 而不是 HashSet,它似乎可以工作。

关于c# - ServiceStack JSONSerializer 和 HashSet<x>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17842084/

相关文章:

c# - 如何在 C# 中并行处理输入直到某些条件为真

c# - C#中如何设置编码?

json - 在 Circe 中解析原始类型

json - 如何在Flutter中解析长度为1的JSON数组?

c# - 带有自定义表的 Identity 2.0

c# - 使用 C# 进行电子邮件排队

c# - 将日期时间转换为 C# 中的特定格式

c# - Asp.Net 删除模型属性和文本之间的空格

asp.net - SQL Server主-子关系而不是表中的存储过程

c# - 应用程序内的 SQLite 文件版本兼容性