From bca549851e2b24eceb1968a4a8ebab5f2ba4f7f2 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 5 Sep 2019 17:15:13 -0400 Subject: [PATCH] Fix IDE0026 (use expression-bodied members for indexers) Signed-off-by: dotnet-bot --- .../ObjectModel/ReadOnlyCollection.cs | 5 +- .../System/Globalization/DateTimeParse.cs | 8 +- src/Common/src/CoreLib/System/ParamsArray.cs | 5 +- src/Common/src/CoreLib/System/Tuple.cs | 161 +++++++----------- src/Common/src/CoreLib/System/ValueTuple.cs | 140 ++++++--------- 5 files changed, 118 insertions(+), 201 deletions(-) diff --git a/src/Common/src/CoreLib/System/Collections/ObjectModel/ReadOnlyCollection.cs b/src/Common/src/CoreLib/System/Collections/ObjectModel/ReadOnlyCollection.cs index 4791ae7dd80b..59f92233267e 100644 --- a/src/Common/src/CoreLib/System/Collections/ObjectModel/ReadOnlyCollection.cs +++ b/src/Common/src/CoreLib/System/Collections/ObjectModel/ReadOnlyCollection.cs @@ -26,10 +26,7 @@ public ReadOnlyCollection(IList list) public int Count => list.Count; - public T this[int index] - { - get { return list[index]; } - } + public T this[int index] => list[index]; public bool Contains(T value) { diff --git a/src/Common/src/CoreLib/System/Globalization/DateTimeParse.cs b/src/Common/src/CoreLib/System/Globalization/DateTimeParse.cs index e2f754745d47..dcde531546ea 100644 --- a/src/Common/src/CoreLib/System/Globalization/DateTimeParse.cs +++ b/src/Common/src/CoreLib/System/Globalization/DateTimeParse.cs @@ -5896,13 +5896,7 @@ internal ref struct DTSubString internal DTSubStringType type; internal int value; - internal char this[int relativeIndex] - { - get - { - return s[index + relativeIndex]; - } - } + internal char this[int relativeIndex] => s[index + relativeIndex]; } // diff --git a/src/Common/src/CoreLib/System/ParamsArray.cs b/src/Common/src/CoreLib/System/ParamsArray.cs index 88277b3376d3..9ab86fa51675 100644 --- a/src/Common/src/CoreLib/System/ParamsArray.cs +++ b/src/Common/src/CoreLib/System/ParamsArray.cs @@ -62,10 +62,7 @@ public ParamsArray(object?[] args) public int Length => _args.Length; - public object? this[int index] - { - get { return index == 0 ? _arg0 : GetAtSlow(index); } - } + public object? this[int index] => index == 0 ? _arg0 : GetAtSlow(index); private object? GetAtSlow(int index) { diff --git a/src/Common/src/CoreLib/System/Tuple.cs b/src/Common/src/CoreLib/System/Tuple.cs index 8ef95d2f673c..17d9fd987527 100644 --- a/src/Common/src/CoreLib/System/Tuple.cs +++ b/src/Common/src/CoreLib/System/Tuple.cs @@ -292,18 +292,13 @@ string ITupleInternal.ToString(StringBuilder sb) /// /// Get the element at position . /// - object? ITuple.this[int index] - { - get + object? ITuple.this[int index] => + index switch { - return index switch - { - 0 => Item1, - 1 => Item2, - _ => throw new IndexOutOfRangeException(), - }; - } - } + 0 => Item1, + 1 => Item2, + _ => throw new IndexOutOfRangeException(), + }; } [Serializable] @@ -409,19 +404,14 @@ string ITupleInternal.ToString(StringBuilder sb) /// /// Get the element at position . /// - object? ITuple.this[int index] - { - get + object? ITuple.this[int index] => + index switch { - return index switch - { - 0 => Item1, - 1 => Item2, - 2 => Item3, - _ => throw new IndexOutOfRangeException(), - }; - } - } + 0 => Item1, + 1 => Item2, + 2 => Item3, + _ => throw new IndexOutOfRangeException(), + }; } [Serializable] @@ -536,20 +526,15 @@ string ITupleInternal.ToString(StringBuilder sb) /// /// Get the element at position . /// - object? ITuple.this[int index] - { - get + object? ITuple.this[int index] => + index switch { - return index switch - { - 0 => Item1, - 1 => Item2, - 2 => Item3, - 3 => Item4, - _ => throw new IndexOutOfRangeException(), - }; - } - } + 0 => Item1, + 1 => Item2, + 2 => Item3, + 3 => Item4, + _ => throw new IndexOutOfRangeException(), + }; } [Serializable] @@ -673,21 +658,16 @@ string ITupleInternal.ToString(StringBuilder sb) /// /// Get the element at position . /// - object? ITuple.this[int index] - { - get + object? ITuple.this[int index] => + index switch { - return index switch - { - 0 => Item1, - 1 => Item2, - 2 => Item3, - 3 => Item4, - 4 => Item5, - _ => throw new IndexOutOfRangeException(), - }; - } - } + 0 => Item1, + 1 => Item2, + 2 => Item3, + 3 => Item4, + 4 => Item5, + _ => throw new IndexOutOfRangeException(), + }; } [Serializable] @@ -820,22 +800,17 @@ string ITupleInternal.ToString(StringBuilder sb) /// /// Get the element at position . /// - object? ITuple.this[int index] - { - get + object? ITuple.this[int index] => + index switch { - return index switch - { - 0 => Item1, - 1 => Item2, - 2 => Item3, - 3 => Item4, - 4 => Item5, - 5 => Item6, - _ => throw new IndexOutOfRangeException(), - }; - } - } + 0 => Item1, + 1 => Item2, + 2 => Item3, + 3 => Item4, + 4 => Item5, + 5 => Item6, + _ => throw new IndexOutOfRangeException(), + }; } [Serializable] @@ -977,23 +952,18 @@ string ITupleInternal.ToString(StringBuilder sb) /// /// Get the element at position . /// - object? ITuple.this[int index] - { - get + object? ITuple.this[int index] => + index switch { - return index switch - { - 0 => Item1, - 1 => Item2, - 2 => Item3, - 3 => Item4, - 4 => Item5, - 5 => Item6, - 6 => Item7, - _ => throw new IndexOutOfRangeException(), - }; - } - } + 0 => Item1, + 1 => Item2, + 2 => Item3, + 3 => Item4, + 4 => Item5, + 5 => Item6, + 6 => Item7, + _ => throw new IndexOutOfRangeException(), + }; } [Serializable] @@ -1171,23 +1141,18 @@ string ITupleInternal.ToString(StringBuilder sb) /// /// Get the element at position . /// - object? ITuple.this[int index] - { - get + object? ITuple.this[int index] => + index switch { - return index switch - { - 0 => Item1, - 1 => Item2, - 2 => Item3, - 3 => Item4, - 4 => Item5, - 5 => Item6, - 6 => Item7, - - _ => ((ITupleInternal)Rest)[index - 7], - }; - } - } + 0 => Item1, + 1 => Item2, + 2 => Item3, + 3 => Item4, + 4 => Item5, + 5 => Item6, + 6 => Item7, + + _ => ((ITupleInternal)Rest)[index - 7], + }; } } diff --git a/src/Common/src/CoreLib/System/ValueTuple.cs b/src/Common/src/CoreLib/System/ValueTuple.cs index 749d172f5034..9792b840a801 100644 --- a/src/Common/src/CoreLib/System/ValueTuple.cs +++ b/src/Common/src/CoreLib/System/ValueTuple.cs @@ -137,13 +137,7 @@ string IValueTupleInternal.ToStringEnd() /// /// Get the element at position . /// - object? ITuple.this[int index] - { - get - { - throw new IndexOutOfRangeException(); - } - } + object? ITuple.this[int index] => throw new IndexOutOfRangeException(); /// Creates a new struct 0-tuple. /// A 0-tuple. @@ -654,18 +648,13 @@ string IValueTupleInternal.ToStringEnd() /// /// Get the element at position . /// - object? ITuple.this[int index] - { - get + object? ITuple.this[int index] => + index switch { - return index switch - { - 0 => Item1, - 1 => Item2, - _ => throw new IndexOutOfRangeException(), - }; - } - } + 0 => Item1, + 1 => Item2, + _ => throw new IndexOutOfRangeException(), + }; } /// @@ -857,19 +846,14 @@ string IValueTupleInternal.ToStringEnd() /// /// Get the element at position . /// - object? ITuple.this[int index] - { - get + object? ITuple.this[int index] => + index switch { - return index switch - { - 0 => Item1, - 1 => Item2, - 2 => Item3, - _ => throw new IndexOutOfRangeException(), - }; - } - } + 0 => Item1, + 1 => Item2, + 2 => Item3, + _ => throw new IndexOutOfRangeException(), + }; } /// @@ -1078,20 +1062,15 @@ string IValueTupleInternal.ToStringEnd() /// /// Get the element at position . /// - object? ITuple.this[int index] - { - get + object? ITuple.this[int index] => + index switch { - return index switch - { - 0 => Item1, - 1 => Item2, - 2 => Item3, - 3 => Item4, - _ => throw new IndexOutOfRangeException(), - }; - } - } + 0 => Item1, + 1 => Item2, + 2 => Item3, + 3 => Item4, + _ => throw new IndexOutOfRangeException(), + }; } /// @@ -1317,21 +1296,16 @@ string IValueTupleInternal.ToStringEnd() /// /// Get the element at position . /// - object? ITuple.this[int index] - { - get + object? ITuple.this[int index] => + index switch { - return index switch - { - 0 => Item1, - 1 => Item2, - 2 => Item3, - 3 => Item4, - 4 => Item5, - _ => throw new IndexOutOfRangeException(), - }; - } - } + 0 => Item1, + 1 => Item2, + 2 => Item3, + 3 => Item4, + 4 => Item5, + _ => throw new IndexOutOfRangeException(), + }; } /// @@ -1574,22 +1548,17 @@ string IValueTupleInternal.ToStringEnd() /// /// Get the element at position . /// - object? ITuple.this[int index] - { - get + object? ITuple.this[int index] => + index switch { - return index switch - { - 0 => Item1, - 1 => Item2, - 2 => Item3, - 3 => Item4, - 4 => Item5, - 5 => Item6, - _ => throw new IndexOutOfRangeException(), - }; - } - } + 0 => Item1, + 1 => Item2, + 2 => Item3, + 3 => Item4, + 4 => Item5, + 5 => Item6, + _ => throw new IndexOutOfRangeException(), + }; } /// @@ -1849,23 +1818,18 @@ string IValueTupleInternal.ToStringEnd() /// /// Get the element at position . /// - object? ITuple.this[int index] - { - get + object? ITuple.this[int index] => + index switch { - return index switch - { - 0 => Item1, - 1 => Item2, - 2 => Item3, - 3 => Item4, - 4 => Item5, - 5 => Item6, - 6 => Item7, - _ => throw new IndexOutOfRangeException(), - }; - } - } + 0 => Item1, + 1 => Item2, + 2 => Item3, + 3 => Item4, + 4 => Item5, + 5 => Item6, + 6 => Item7, + _ => throw new IndexOutOfRangeException(), + }; } ///