我们有这段代码:
// 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/