【发布时间】:2011-02-23 20:47:20
【问题描述】:
我知道您可以进入每个属性或不进入每个属性,但我真的希望能够进入特定属性,而不是其他属性。这可能吗? (我也知道我可以使用键盘命令,但我想问是否有更永久的解决方案。)我有很多属性,我的 setter 做重要的事情,所以跳过它们很愚蠢,但我的大多数 getter 都是无意义。我正在寻找类似的东西:
public string ImportantProperty
{
get { return _importantProperty; }
[DebuggerStepThrough(false)]
set
{
if (this.State != ConnectionState.Closed)
throw new InvalidOperationException(
"Important Property cannot be changed unless This is closed.");
if (ImportantProperty == value)
return;
_importantProperty = value;
OnImportantPropertyChanged(new EventArgs());
}
}
不幸的是,我找不到像[DebuggerStepThrough(false)] 这样的东西,我必须求助于turning off 属性跨步并将[DebuggerStepThrough] 放置在任何地方 我不想跨步-通过。
【问题讨论】:
-
1.有趣的问题。我可能会向 John Robbins 寻求解决方案。 2. 最好使用 EventArgs.Empty,而不是 new EventArgs()。
-
另外,在引发之前检查是否有人订阅了该事件,否则将引发异常。即: if(OnImportantPropertyChanged != null) OnImportantPropertyChanged(EventArgs.Empty);
标签: c# .net debugging visual-studio-2010 attributes