问题描述
我有一些看起来像这样的代码:
[DefaultValue(CornerStyle.Rounded)]
public CornerStyle RectCornerMode
{
get {return this [" RectCornerMode"]。GetValue< CornerStyle>(); }
set {this [" RectCornerMode"]。SetValue< CornerStyle>(value); }
}
这个[字符串]中的
我得到了装饰调用方法的属性,并使用
来计算默认值。 br />
现在似乎有时候(在构建发布模式时)属性是通过
传递,调用方法直接调用[string]和GetValue,因此
忽略了装饰属性......
有没有办法避免这种内联?
有什么建议吗?
I have some code which looks like that:
[DefaultValue(CornerStyle.Rounded)]
public CornerStyle RectCornerMode
{
get { return this["RectCornerMode"].GetValue<CornerStyle>(); }
set { this["RectCornerMode"].SetValue<CornerStyle>(value); }
}
in this[string] I get the attribute decorating the calling method, and used
it to compute a default value.
now it seems that sometimes (when build in release mode) the property is by
passed and the calling method call this[string] and GetValue directly, thus
ignoring the decorating attribute....
is there a way to avoid this inlining?
any suggestion?
推荐答案
对我来说听起来像是一个可怕的解决方案。让一个虚拟成员只需要实现这种副作用就好了。你应该只在有意义的情况下创建一个虚拟的
成员,并且你已经准备好了处理你的代码可能被覆盖并且可能永远不会 br />
运行。
如果实际支持CLR的未来版本(或某些其他运行时实现),您的代码将会中断内联虚拟
方法。
Mattias
-
Mattias Sj?gren [C#MVP ] mattias @ mvps.org
|
请回复到新闻组。
Sounds like a horrible solution to me. Making a member virtual just to
achieve this side effect just seems wrong. You should only make a
member virtual when it makes sense to do so and you''re prepared to
handle the fact that your code may be overridden and perhaps never
run.
Plus your code would break if a future version of the CLR (or some
other runtime implementation) actually supported inlining virtual
methods.
Mattias
--
Mattias Sj?gren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
这篇关于如何避免内联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!