[英]Sonar Qube Error Update this implementation of 'ISerializable' to conform to the recommended serialization pattern
我目前正在处理 .net 4.6.2 应用程序。
我需要序列化一个 OData Api 调用,它工作得很好。
不幸的是,我遇到了 Sonar Qube 错误:
更新“ISerializable”的此实现以符合推荐的序列化模式。
为了将我的 OData 放入 C#,我使用以下 class 结构:
[Serializable]
public class Record : Dictionary<string, dynamic> { }
[DataContract]
public class Records
{
[DataMember(Name = "@odata.context")]
public string Context { get; set; }
[DataMember(Name = "@odata.count")]
public int Count { get; set; }
[DataMember(Name = "value")]
public IEnumerable<Record> Value { get; set; }
}
序列化工作正常,但我不知道如何解决这个 Sonar Qube 错误。
如何正确使用 ISerializable 和 DataContract,真的可以吗?
你知道如何解决这个问题吗?
正如@Maritn Costello 所建议的
你可以像这样抑制这个警告。
#pragma warning disable S3925 // "ISerializable" should be implemented correctly
public class Record : Dictionary<string, string> { }
#pragma warning restore S3925 // "ISerializable" should be implemented correctly
字典 class 实现ISerializable
public class Dictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable, IDictionary, ICollection, IReadOnlyDictionary<TKey, TValue>, IReadOnlyCollection<KeyValuePair<TKey, TValue>>, ISerializable, IDeserializationCallback
{
在我的例子中,我选择使用本机类型而不是自定义 class。它工作正常。
[DataMember(Name = "value")]
public List<Dictionary<string, dynamic>> Value { get; set; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.