Csharp/C#教程:将JsonDictionary属性应用于字典分享


将JsonDictionary属性应用于字典

如果我尝试将JsonDictionary属性添加到.net Dictionary(Of Integer,MyClass),编译器告诉我,该属性无法应用。 为什么是这样?

 Public ReadOnly Property monatswerte As Dictionary(Of Integer, MyClass) 

我基本上找不到任何关于如何在线使用JsonDictionary的例子。

可以应用于类型(类或接口),以强制Json.NET的默认合约解析器 (及其子类)生成该类型的字典合约 。 它是三个相似属性的一部分:

从表面似乎没有用,因为DefaultContractResolver.CreateContract(Type objectType)在检查任何其他接口实现之前检查传入类型是否实现了IDictionary 。 但是,该属性有几个属性可用于自定义字典的序列化方式,包括:

@ dbc的答案很棒,+ 1(并且这种方法比明确的TypeConverter路由要麻烦得多)。 这是一个F#riff / rip-off / port:

上述就是C#学习教程:将JsonDictionary属性应用于字典分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 [)>] type VerbatimKeyDictionary<'value>(values : IDictionary) = inherit Dictionary(values) override this.Equals other = let that = other :?> IDictionary that <> null && this.Count = that.Count && Seq.isEmpty (this |> Seq.except that) override __.GetHashCode () = 0 and VerbatimKeyDictionaryNamingStrategy() = inherit Newtonsoft.Json.Serialization.DefaultNamingStrategy( ProcessDictionaryKeys = false) 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1296347.html

(0)
上一篇 2022年12月6日
下一篇 2022年12月6日

精彩推荐