gpt4 book ai didi

c# - 使用 C# 属性时出现性能问题?

转载 作者:太空狗 更新时间:2023-10-29 20:33:00 25 4
gpt4 key购买 nike

据我所知,属性是在编译时生成的(否则将无法通过反射加载属性)。无论如何,在某些情况下属性可能会导致运行时出现性能问题吗?

最佳答案

Anyhow, are there certain cases where attributes might lead to performance issues at runtime?

仅当您的程序过度寻找代码中的属性时。

属性仅在某些东西正在寻找时才有用。如果您使用 [MyAwsomeAttribute] 装饰您的类并且没有任何东西在寻找它,那么不会有性能差异

性能差异取决于您拥有多少属性;如果被发现;以及执行有问题的属性所花费的时间(假设它具有这种能力,许多属性纯粹是元数据)。

很好的例子是 WCF 自定义行为属性及其详细且可能很复杂的实现方法。

关于c# - 使用 C# 属性时出现性能问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44693976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com