-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathWrap.AsCollection.cs
More file actions
43 lines (37 loc) · 1.31 KB
/
Wrap.AsCollection.cs
File metadata and controls
43 lines (37 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Collections;
using System.Collections.Generic;
using Xunit.Sdk;
namespace NetFabric.Hyperlinq
{
public static partial class Wrap
{
public static CollectionWrapper<T> AsCollection<T>(T[] source)
=> source switch
{
null => throw new ArgumentNullException(nameof(source)),
// ReSharper disable once HeapView.ObjectAllocation.Evident
_ => new CollectionWrapper<T>(source)
};
public class CollectionWrapper<T>
: ReadOnlyCollectionWrapper<T>
, ICollection<T>
{
internal CollectionWrapper(T[] source)
: base(source)
{ }
bool ICollection<T>.IsReadOnly
=> true;
void ICollection<T>.CopyTo(T[] array, int arrayIndex)
=> source.CopyTo(array, arrayIndex);
bool ICollection<T>.Contains(T item)
=> ((ICollection<T>)source).Contains(item);
void ICollection<T>.Add(T item)
=> throw new NotSupportedException();
bool ICollection<T>.Remove(T item)
=> throw new NotSupportedException();
void ICollection<T>.Clear()
=> throw new NotSupportedException();
}
}
}