c# - C# expression-bodied 成员的 method 属性

标签 c# syntax properties attributes c#-6.0

有什么方法可以指定 AttributeTargets.Method attributeexpression-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/

相关文章:

c# - "using"构造和异常处理

svn 提交 : to which "--encoding" parameter applies?

svn - 添加svn :executable的正确方法

ios - 无法识别的选择器发送到实例并在 iOS 应用程序的 main.m 中崩溃

c# - 带有类型参数的类型层次结构?

c# - 使用哪种写入文件的方法?

c# - Nuget 版本不正确?

输出 HTML 的 C# 语法荧光笔

java - 将特定格式的多个输入作为 java 中的单个输入

excel - ThisMonth 正确使用和替代品(如果有)