Skip to content

Commit 0d68359

Browse files
committed
Exceptions.
1 parent a7e8262 commit 0d68359

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

src/Berrysoft.Data/ExceptionHelper.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,25 @@ internal static class ExceptionHelper
77
{
88
public static Exception ArgumentNull(string paramName)
99
=> new ArgumentNullException(paramName);
10-
public static Exception RootHasParent()
11-
=> new ArgumentException("The root can't have a parent.");
1210
public static Exception PairExisted()
13-
=> new ArgumentException("The key pair is existed.");
11+
=> new PairExistedException();
1412
public static Exception KeyNotFound()
1513
=> new KeyNotFoundException();
16-
public static Exception KeyExisted(string keyMessage)
17-
=> new ArgumentException($"{keyMessage} is existed.");
18-
public static Exception KeysExisted()
19-
=> new ArgumentException("Both keys are existed.");
2014
public static Exception ArgumentOutOfRange(string paramName)
2115
=> new ArgumentOutOfRangeException(paramName);
22-
public static Exception NotSupported()
23-
=> new NotSupportedException();
2416
public static Exception ArrayTooSmall()
2517
=> new ArgumentException("The array is too small.");
2618
}
19+
/// <summary>
20+
/// Represents errors that a key pair is existed.
21+
/// </summary>
22+
public class PairExistedException : ArgumentException
23+
{
24+
/// <summary>
25+
/// Initializes a new instance of <see cref="PairExistedException"/> class.
26+
/// </summary>
27+
public PairExistedException()
28+
: base("The key pair is existed.")
29+
{ }
30+
}
2731
}

src/Berrysoft.Unsafe/ByReference.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Runtime.CompilerServices;
34
using static System.Runtime.CompilerServices.Unsafe;
45

@@ -8,6 +9,8 @@ namespace Berrysoft.Unsafe
89
/// Represents a .NET CLR reference.
910
/// </summary>
1011
/// <typeparam name="T">Type of the reference pointed to.</typeparam>
12+
[DebuggerDisplay("{Value}")]
13+
[DebuggerTypeProxy(typeof(PointerDebugView<>))]
1114
public readonly unsafe struct ByReference<T>
1215
{
1316
private readonly void* _ptr;

src/Berrysoft.Unsafe/PointerDebugView.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ public unsafe PointerDebugView(Pointer<T> ptr)
2626
}
2727
}
2828
/// <summary>
29+
/// Initializes a new instance of <see cref="PointerDebugView{T}"/> class. This method is called by the debugger.
30+
/// </summary>
31+
/// <param name="ptr">The reference.</param>
32+
public PointerDebugView(ByReference<T> ptr)
33+
{
34+
target = ptr.Value;
35+
}
36+
/// <summary>
2937
/// Target of the pointer.
3038
/// </summary>
3139
[DebuggerBrowsable(DebuggerBrowsableState.Collapsed)]

tests/Berrysoft.Data.Test/MapTest.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Public Class MapTest
5656
Dim key1values() As String = keylook.GetValuesFromKey1(123).ToArray()
5757
Assert.AreEqual(key1values(0), "123")
5858
Assert.AreEqual(key1values(1), "abc")
59-
Assert.ThrowsException(Of ArgumentException)(Sub() keylook.Add(123, "123"))
59+
Assert.ThrowsException(Of PairExistedException)(Sub() keylook.Add(123, "123"))
6060
End Sub
6161

6262
<TestMethod()>

0 commit comments

Comments
 (0)