2017-06-10 5 views
1

C#6のexpression-bodied memberAttributeTargets.Methodattributeを指定する方法はありますか?省略SYNAXは次のようになりメソッドC#式身体メンバの属性

public bool IsLast { [DebuggerStepThrough] get { return _next == null; } } 

:次の読み取り専用プロパティを考えてみましょう

public bool IsLast => _next == null; 

しかし、method属性を置くためにどこにもないように思われます。次の作業のいずれも:

[DebuggerStepThrough] 
public bool IsLast => _next == null;  // decorates property, not method 

public bool IsLast => [DebuggerStepThrough] _next == null; // error 

public bool IsLast [DebuggerStepThrough] => _next == null; // error 

答えて

0

私自身の質問に答える:次の構文は機能しますが、質問に表示されている(動作していない)試みほどコンパクトではありません。

public bool IsLast { [DebuggerStepThrough] get => _next == null; } 
2

あなたは表現ボディプロパティにではなく、表現ボディ方法AttributeTargets.Method属性を適用することはできません。