diff --git a/.editorconfig b/.editorconfig index 8d4baf41..5564dea2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -34,3 +34,6 @@ dotnet_sort_system_directives_first = true # Predefined for members, etc does not create a message because the explicitly sized types are conveient in interop scenarios where the bit size matters. dotnet_style_predefined_type_for_locals_parameters_members = true:none dotnet_style_predefined_type_for_member_access = true:suggestion + +# Instantiate argument exceptions correctly +dotnet_diagnostic.CA2208.severity = warning \ No newline at end of file diff --git a/Bonsai.Core/Dag/DirectedGraph.cs b/Bonsai.Core/Dag/DirectedGraph.cs index 6dc8e01c..eb33e3c9 100644 --- a/Bonsai.Core/Dag/DirectedGraph.cs +++ b/Bonsai.Core/Dag/DirectedGraph.cs @@ -191,7 +191,7 @@ public Edge InsertEdge(Node from ThrowIfEdgeVerticesNullOrNotInGraph(from, to, nameof(to)); if (edgeIndex < 0 || edgeIndex > from.Successors.Count) { - throw new ArgumentOutOfRangeException("The specified edge index is out of range.", nameof(edgeIndex)); + throw new ArgumentOutOfRangeException(nameof(edgeIndex), "The specified edge index is out of range."); } var edge = new Edge(to, label); @@ -216,7 +216,7 @@ public void InsertEdge(Node from, int edgeIndex, Edge from.Successors.Count) { - throw new ArgumentOutOfRangeException("The specified edge index is out of range.", nameof(edgeIndex)); + throw new ArgumentOutOfRangeException(nameof(edgeIndex), "The specified edge index is out of range."); } from.Successors.Insert(edgeIndex, edge); @@ -238,7 +238,7 @@ public Edge SetEdge(Node from, i ThrowIfEdgeVerticesNullOrNotInGraph(from, to, nameof(to)); if (edgeIndex < 0 || edgeIndex >= from.Successors.Count) { - throw new ArgumentOutOfRangeException("The specified edge index is out of range.", nameof(edgeIndex)); + throw new ArgumentOutOfRangeException(nameof(edgeIndex), "The specified edge index is out of range."); } var edge = new Edge(to, label); @@ -263,7 +263,7 @@ public void SetEdge(Node from, int edgeIndex, Edge= from.Successors.Count) { - throw new ArgumentOutOfRangeException("The specified edge index is out of range.", nameof(edgeIndex)); + throw new ArgumentOutOfRangeException(nameof(edgeIndex), "The specified edge index is out of range."); } from.Successors[edgeIndex] = edge; @@ -313,7 +313,7 @@ public Node Insert(int index, TNodeValue value) { if (index < 0 || index > nodes.Count) { - throw new ArgumentOutOfRangeException("The specified index is out of range.", nameof(index)); + throw new ArgumentOutOfRangeException(nameof(index), "The specified index is out of range."); } var node = new Node(value); @@ -343,7 +343,7 @@ public void Insert(int index, Node node) if (index < 0 || index > nodes.Count) { - throw new ArgumentOutOfRangeException("The specified index is out of range.", nameof(index)); + throw new ArgumentOutOfRangeException(nameof(index), "The specified index is out of range."); } InsertInternal(index, new[] { node }); @@ -375,7 +375,7 @@ public void InsertRange(int index, IEnumerable> col if (index < 0 || index > nodes.Count) { - throw new ArgumentOutOfRangeException("The specified index is out of range.", nameof(index)); + throw new ArgumentOutOfRangeException(nameof(index), "The specified index is out of range."); } InsertInternal(index, collection); @@ -471,7 +471,7 @@ public void RemoveAt(int index) { if (index < 0 || index >= nodes.Count) { - throw new ArgumentOutOfRangeException("The specified index is out of range.", nameof(index)); + throw new ArgumentOutOfRangeException(nameof(index), "The specified index is out of range."); } var node = nodes[index]; @@ -524,19 +524,19 @@ public void RemoveRange(int index, int count) { if (index < 0) { - throw new ArgumentOutOfRangeException("The specified index is less than zero.", nameof(index)); + throw new ArgumentOutOfRangeException(nameof(index), "The specified index is less than zero."); } if (count < 0) { - throw new ArgumentOutOfRangeException("The count of elements to remove is less than zero.", nameof(count)); + throw new ArgumentOutOfRangeException(nameof(count), "The count of elements to remove is less than zero."); } if (nodes.Count - index < count) { throw new ArgumentOutOfRangeException( - "The index and count were out of bounds or count is greater than the number of nodes from index.", - nameof(count)); + nameof(count), + "The index and count were out of bounds or count is greater than the number of nodes from index."); } var removed = new HashSet>(); diff --git a/Bonsai.Core/Reactive/Slice.cs b/Bonsai.Core/Reactive/Slice.cs index c45fb95a..3be38fff 100644 --- a/Bonsai.Core/Reactive/Slice.cs +++ b/Bonsai.Core/Reactive/Slice.cs @@ -46,19 +46,19 @@ public override IObservable Process(IObservable sourc var start = Start; if (start < 0) { - throw new ArgumentOutOfRangeException(nameof(start)); + throw new InvalidOperationException("The specified start index is less than zero."); } var step = Step; if (step <= 0) { - throw new ArgumentOutOfRangeException(nameof(step)); + throw new InvalidOperationException("Step size must be a positive number."); } var stop = Stop; if (stop < 0) { - throw new ArgumentOutOfRangeException(nameof(stop)); + throw new InvalidOperationException("The specified stop index is less than zero."); } return (stop - start) <= 0 ? Observable.Empty() : Observable.Create(observer =>