FXCop / 对带有数组的 WCF DataContract 类进行代码分析 - 创建 CA1819 错误
我有以下 WCF 数据协定类:
[DataContract]
public class BinaryResponse : ResponseBase
{
[DataMember]
public byte[] Payload { get; set; }
}
很好且简单,完全按照我的需要工作。不过,我现在正在通过完整的代码分析规则集来运行它。这会生成以下警告:
CA1819 : Microsoft.Performance : Change 'BinaryResponse.Payload' to return a collection or make it a method.
查看了 此错误的帮助页面 解决方案很简单。然而,该解决方案并不真正适合 WCF 数据成员。
所以问题是,如何重构此类,使其仍可用作 WCF 数据契约并通过代码分析?
干杯
I have the following WCF data contract class:
[DataContract]
public class BinaryResponse : ResponseBase
{
[DataMember]
public byte[] Payload { get; set; }
}
Nice and simple, works exactly as I need it to. However I am now running this through the full code analysis ruleset. This generates the following warning:
CA1819 : Microsoft.Performance : Change 'BinaryResponse.Payload' to return a collection or make it a method.
Having looked at the help page for this error the solution is a simple one. However the solution doesn't really fit with WCF datamembers.
So the question is, how can I refactor this class to still be useable as a WCF datacontract and also pass the code analysis?
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将字节数组更改为可枚举或集合,如下所示:
或者您可以将 byte[] 属性保留在私有数组中并将其包装在 ICollection 属性中(如果您需要内部数组):
You can do change the byte array to an enumerable or collection, like tehe following:
or you can keep the byte[] attribute in a private array and wrap it in an ICollection property (if you need the internal array):