我们有这样的代码:
// 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吗?
发布于 2013-07-24 18:53:49
这似乎是ServiceStack.Text中的一个bug。我已经将问题追溯到AssemblyTypeDefinition.cs第17行(在撰写本文时)。传入的typeDefinition是System.Core],System.Core“和TypeDefinitionSeperator是',导致字符串在‘’的第一个实例而不是第二个应该被破坏的位置被破坏。模拟正在正确拆分的字符串(在调试器中)从代码中返回正确的结果。
您可能希望将其作为一个bug提交给ServiceStack社区。
发布于 2013-07-24 18:59:48
虽然这不是最好的答案,但您可以通过创建一个从HashSet继承的本地类来解决这个问题。
示例:
public class HashSetHack<T> : HashSet<T> { }然后参考HashSetHack而不是HashSet,它看起来是有效的。
https://stackoverflow.com/questions/17842084
复制相似问题