有什么方法可以指定 AttributeTargets.Method
attribute在 expression-bodied member 上在 C# 6 中?考虑以下只读属性:
public bool IsLast { [DebuggerStepThrough] get { return _next == null; } }
缩写的 synax 是:
public bool IsLast => _next == null;
但是似乎没有地方可以放置方法属性。以下均无效:
[DebuggerStepThrough]
public bool IsLast => _next == null; // decorates property, not method
public bool IsLast => [DebuggerStepThrough] _next == null; // error
public bool IsLast [DebuggerStepThrough] => _next == null; // error
[编辑:]表明这不是 'Skip expression bodied property in debugger' 的副本因为这个问题一般询问任何适合方法的属性,而不仅仅是
DebuggerStepThrough
attribute——此处仅作为示例给出——特别是。
最佳答案
您可以将 AttributeTargets.Method
属性应用于表达式主体方法,但不能应用于表达式主体属性。
关于c# - C# expression-bodied 成员的 method 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44478148/