Skip to content

Commit 891d95a

Browse files
committed
Add some...members.
1 parent 593ba02 commit 891d95a

File tree

7 files changed

+92
-7
lines changed

7 files changed

+92
-7
lines changed

src/Berrysoft.Data/DebugView.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
6+
namespace Berrysoft.Data
7+
{
8+
internal sealed class MapDebugView<K, V>
9+
{
10+
private readonly Map<K, V> map;
11+
public MapDebugView(Map<K, V> map)
12+
{
13+
this.map = map ?? throw ExceptionHelper.ArgumentNull(nameof(map));
14+
}
15+
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
16+
public KeyPair<K, V>[] Items
17+
{
18+
get
19+
{
20+
KeyPair<K, V>[] array = new KeyPair<K, V>[map.Count];
21+
map.CopyTo(array, 0);
22+
return array;
23+
}
24+
}
25+
}
26+
internal sealed class LookupDebugView<K, V>
27+
{
28+
private readonly Lookup<K, V> lookup;
29+
public LookupDebugView(Lookup<K, V> lookup)
30+
{
31+
this.lookup = lookup ?? throw ExceptionHelper.ArgumentNull(nameof(lookup));
32+
}
33+
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
34+
public Lookup<K, V>.Grouping[] Items => ((IEnumerable<Lookup<K, V>.Grouping>)lookup).ToArray();
35+
}
36+
internal sealed class MultiMapDebugView<K, V>
37+
{
38+
private readonly MultiMap<K, V> multiMap;
39+
public MultiMapDebugView(MultiMap<K, V> multiMap)
40+
{
41+
this.multiMap = multiMap ?? throw ExceptionHelper.ArgumentNull(nameof(multiMap));
42+
}
43+
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
44+
public KeyPair<K, V>[] Items
45+
{
46+
get
47+
{
48+
KeyPair<K, V>[] array = new KeyPair<K, V>[multiMap.Count];
49+
multiMap.CopyTo(array, 0);
50+
return array;
51+
}
52+
}
53+
}
54+
}

src/Berrysoft.Data/Lookup.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Collections.ObjectModel;
5+
using System.Diagnostics;
56
using System.Linq;
67

78
namespace Berrysoft.Data
@@ -68,9 +69,11 @@ internal interface ICountableGrouping<TKey, TElement> : IGrouping<TKey, TElement
6869
/// <typeparam name="TKey">The type of the keys in the <see cref="Lookup{TKey, TElement}"/>.</typeparam>
6970
/// <typeparam name="TElement">The type of the elements of each value in the <see cref="Lookup{TKey, TElement}"/>.</typeparam>
7071
[Serializable]
71-
public class Lookup<TKey, TElement> : IMutableLookup<TKey, TElement>, IEnumerable<KeyValuePair<TKey, TElement>>, IEnumerable<ICountableGrouping<TKey, TElement>>
72+
[DebuggerTypeProxy(typeof(LookupDebugView<,>))]
73+
[DebuggerDisplay("Count = {Count}")]
74+
public class Lookup<TKey, TElement> : IMutableLookup<TKey, TElement>, IEnumerable<KeyValuePair<TKey, TElement>>, IEnumerable<Lookup<TKey, TElement>.Grouping>
7275
{
73-
private Dictionary<TKey, Grouping> dic;
76+
private readonly Dictionary<TKey, Grouping> dic;
7477
/// <summary>
7578
/// Initialize a new instance of <see cref="Lookup{TKey, TElement}"/> class.
7679
/// </summary>
@@ -255,7 +258,7 @@ public IEnumerator<KeyValuePair<TKey, TElement>> GetEnumerator()
255258
/// Returns a generic enumerator that iterates through the <see cref="Lookup{TKey, TElement}"/>.
256259
/// </summary>
257260
/// <returns>An enumerator for the <see cref="Lookup{TKey, TElement}"/>.</returns>
258-
IEnumerator<ICountableGrouping<TKey, TElement>> IEnumerable<ICountableGrouping<TKey, TElement>>.GetEnumerator() => GetEnumeratorInternal();
261+
IEnumerator<Grouping> IEnumerable<Grouping>.GetEnumerator() => GetEnumeratorInternal();
259262
/// <summary>
260263
/// Returns an enumerator that iterates through the <see cref="Lookup{TKey, TElement}"/>. This class cannot be inherited.
261264
/// </summary>
@@ -265,7 +268,7 @@ public IEnumerator<KeyValuePair<TKey, TElement>> GetEnumerator()
265268
/// Returns a generic enumerator that iterates through the <see cref="Lookup{TKey, TElement}"/>.
266269
/// </summary>
267270
/// <returns>An enumerator for the <see cref="Lookup{TKey, TElement}"/>.</returns>
268-
private IEnumerator<Grouping> GetEnumeratorInternal()
271+
internal IEnumerator<Grouping> GetEnumeratorInternal()
269272
{
270273
foreach (var item in dic)
271274
{
@@ -275,7 +278,7 @@ private IEnumerator<Grouping> GetEnumeratorInternal()
275278
/// <summary>
276279
/// Represents a key and a sequence of elements.
277280
/// </summary>
278-
private class Grouping : ICountableGrouping<TKey, TElement>, ICollection<TElement>
281+
internal class Grouping : ICountableGrouping<TKey, TElement>, ICollection<TElement>
279282
{
280283
private readonly TKey key;
281284
private readonly Collection<TElement> collection;

src/Berrysoft.Data/Map.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using System.Diagnostics;
45
using System.Text;
56

67
namespace Berrysoft.Data
@@ -203,10 +204,12 @@ public override string ToString()
203204
/// <typeparam name="TKey1">Type of key1.</typeparam>
204205
/// <typeparam name="TKey2">Type of key2.</typeparam>
205206
[Serializable]
207+
[DebuggerTypeProxy(typeof(MapDebugView<,>))]
208+
[DebuggerDisplay("Count = {Count}")]
206209
public class Map<TKey1, TKey2> : IMap<TKey1, TKey2>
207210
{
208-
private Dictionary<TKey1, TKey2> dic;
209-
private Dictionary<TKey2, TKey1> rev;
211+
private readonly Dictionary<TKey1, TKey2> dic;
212+
private readonly Dictionary<TKey2, TKey1> rev;
210213
/// <summary>
211214
/// Initialize a new instance of <see cref="Map{TKey1, TKey2}"/>.
212215
/// </summary>

src/Berrysoft.Data/MultiMap.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using System.Diagnostics;
45
using System.Linq;
56

67
namespace Berrysoft.Data
@@ -155,6 +156,8 @@ public static MultiMap<TKey1, TKey2> ToMultiMap<TSource, TKey1, TKey2>(this IEnu
155156
/// <typeparam name="TKey1">Type of key1.</typeparam>
156157
/// <typeparam name="TKey2">Type of key2.</typeparam>
157158
[Serializable]
159+
[DebuggerTypeProxy(typeof(MultiMapDebugView<,>))]
160+
[DebuggerDisplay("Count = {Count}")]
158161
public class MultiMap<TKey1, TKey2> : IMultiMap<TKey1, TKey2>
159162
{
160163
private Lookup<TKey1, TKey2> dic;

src/Berrysoft.Unsafe/ByReference.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,20 @@ public ref T Value
3232
get => ref AsRef<T>(_ptr);
3333
}
3434
}
35+
[DebuggerDisplay("{Value}")]
36+
[DebuggerTypeProxy(typeof(PointerDebugView<>))]
37+
public readonly unsafe struct ReadOnlyRefrence<T>
38+
{
39+
private readonly void* _ptr;
40+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
41+
public ReadOnlyRefrence(in T value)
42+
{
43+
_ptr = AsPointer(ref AsRef(in value));
44+
}
45+
public ref readonly T Value
46+
{
47+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
48+
get => ref AsRef<T>(_ptr);
49+
}
50+
}
3551
}

src/Berrysoft.Unsafe/PointerDebugView.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public PointerDebugView(ByReference<T> ptr)
3333
{
3434
target = ptr.Value;
3535
}
36+
public PointerDebugView(ReadOnlyRefrence<T> ptr)
37+
{
38+
target = ptr.Value;
39+
}
3640
/// <summary>
3741
/// Target of the pointer.
3842
/// </summary>

src/Berrysoft.Unsafe/UnsafeMethods.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public unsafe static class UnsafeMethods
4040
/// <returns>An instance of <see cref="Unsafe.ByReference{T}"/>.</returns>
4141
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4242
public static ByReference<T> ByReference<T>(ref T value) => new ByReference<T>(ref value);
43+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
44+
public static ByReference<T> AsReference<T>(in T value) => new ByReference<T>(ref AsRef(in value));
4345
/// <summary>
4446
/// Get the target reference of <see cref="Pointer{T}"/>.
4547
/// </summary>

0 commit comments

Comments
 (0)