WCF 自定义 DataContract/DataMember 和 CA1811:避免未调用的私有代码
我得到了一个WCF服务,返回对象之一是:
[DataContract]
sealed class Class1
{
[DataMember]
public int Prop1 { get; private set; }
...
}
顺便说一句,属性之一,假设是这个Prop1
,我只在服务内部设置,然后在客户端读取。
但是,这会产生 CA1811:避免在
。Prop1
的 .get()
上调用未调用的私有代码
我是否做错了什么,或者我应该忽略这个警告,或者我应该做一些不同的事情?
I got a WCF service, and one of the return objects is:
[DataContract]
sealed class Class1
{
[DataMember]
public int Prop1 { get; private set; }
...
}
Incidentially, one of the properties, let's say it's this Prop1
, I only set within the service, and then read in the client.
This, however, produces CA1811: Avoid uncalled private code
on the .get()
of Prop1
.
Am I doing something wrong, or should I ignore this warning, or should I do something differently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你并没有真正做错什么。发出警告是因为服务端从未调用 getter;这是分析的代码所在的位置。我认为您可以安全地忽略该警告
You are not really doing anything wrong. The warning is raised because the getter is never called on the service side; which is where the analyzed code resides. I think you can safely ignore the warning