Skip to content

Commit 8f7694b

Browse files
author
Robert El-Soudani
committed
Polish ReadOnlyHashSet
* Fix compiler break in ReadOnlyHashSet. * Add a bit of documentation. * Hide the ICollection<T> members that aren't supported via explicit interface implementation.
1 parent 9d09428 commit 8f7694b

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Assets/HoloToolkit/Utilities/Scripts/ReadOnlyHashSet.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
using HoloToolkit.Diagnostics;
54
using System;
65
using System.Collections;
76
using System.Collections.Generic;
7+
using UnityEngine;
88

99
namespace HoloToolkit.Unity
1010
{
11+
/// <summary>
12+
/// A wrapper for <see cref="HashSet{T}"/> that doesn't allow modification of the set. This is
13+
/// useful for handing out references to a set that is going to be modified internally, without
14+
/// giving external consumers the opportunity to accidentally modify the set.
15+
/// </summary>
1116
public class ReadOnlyHashSet<TElement> :
1217
ICollection<TElement>,
1318
IEnumerable<TElement>,
@@ -17,7 +22,7 @@ public class ReadOnlyHashSet<TElement> :
1722

1823
public ReadOnlyHashSet(HashSet<TElement> underlyingSet)
1924
{
20-
Assert.IsTrue(DiagnosticContext.Create(), underlyingSet != null, "underlyingSet cannot be null.");
25+
Debug.Assert(underlyingSet != null, "underlyingSet cannot be null.");
2126

2227
this.underlyingSet = underlyingSet;
2328
}
@@ -27,17 +32,17 @@ public int Count
2732
get { return underlyingSet.Count; }
2833
}
2934

30-
public bool IsReadOnly
35+
bool ICollection<TElement>.IsReadOnly
3136
{
3237
get { return true; }
3338
}
3439

35-
public void Add(TElement item)
40+
void ICollection<TElement>.Add(TElement item)
3641
{
3742
throw NewWriteDeniedException();
3843
}
3944

40-
public void Clear()
45+
void ICollection<TElement>.Clear()
4146
{
4247
throw NewWriteDeniedException();
4348
}
@@ -57,7 +62,7 @@ public IEnumerator<TElement> GetEnumerator()
5762
return underlyingSet.GetEnumerator();
5863
}
5964

60-
public bool Remove(TElement item)
65+
bool ICollection<TElement>.Remove(TElement item)
6166
{
6267
throw NewWriteDeniedException();
6368
}

0 commit comments

Comments
 (0)