将 [DataContract] 和 [DataMember] 添加到所有类是否会影响性能
假设我们有一个代码生成工具,可以创建数千个 C# 类,有时我们需要向它们添加这些属性。
我们正在考虑是否最好将 [DataContract]
和 [DataMember]
放在所有适当的类上,或者我们需要创建一个特殊的策略来确定是否在为了节省一些可能吗? AttributeAll 方法中的性能损失。
最后的问题是添加属性是否会以某种方式影响性能?
我认为在类上添加属性只会保留其类型信息,不会影响任何性能,但希望在这里 100% 确定
Lets say we got a code generating tool that creates thousands of C# classes, and we sometimes need to add those attributes to them.
We are considering whether it is better to put [DataContract]
and [DataMember]
on all appropriate classes or we need to create a special strategy that will determine whether to do so in order to save up some possible? performance lost in AtribbuteAll approach.
In the end the question is whether adding attributes can somehow affect performance?
I am thinking that adding an attribute on a class will simply stay with its type information and should not affect any performance but would like to be 100% certain here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果在代码的某些部分检查这些属性,则添加属性会影响性能,否则,类将拥有更多元数据,但这不会影响性能。
Adding attributes would impact in performance if these are inspected in some part of the code, if not, classes would have more metadata, but this doesn't impact performance.
怀疑这会影响性能,所有这些属性所做的就是将它们标记为可序列化以供 WCF 使用。
Doubtful that this will affect performance, all these attributes do is mark them as serializable for WCF.
影响性能是不可避免的。
但如果你需要属性来完成你的注意力,你别无选择。
如果您不需要,您可以将其删除。
impact performance is unavoidable.
but if you need attribute to complete your attention, you have not other choice.
if you do not need, you may remove it.