-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathWrap.AsList.cs
More file actions
55 lines (46 loc) · 1.67 KB
/
Wrap.AsList.cs
File metadata and controls
55 lines (46 loc) · 1.67 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
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections;
using System.Collections.Generic;
namespace NetFabric.Hyperlinq
{
public static partial class Wrap
{
public static ListWrapper<T> AsList<T>(T[] source)
=> source switch
{
null => throw new ArgumentNullException(nameof(source)),
// ReSharper disable once HeapView.ObjectAllocation.Evident
_ => new ListWrapper<T>(source)
};
public class ListWrapper<T>
: ReadOnlyListWrapper<T>
, IList<T>
{
internal ListWrapper(T[] source)
: base(source)
{ }
T IList<T>.this[int index]
{
get => source[index];
set => throw new NotSupportedException();
}
public bool IsReadOnly => true;
public void CopyTo(T[] array, int arrayIndex)
=> source.CopyTo(array, arrayIndex);
public bool Contains(T item)
=> ((ICollection<T>)source).Contains(item);
public int IndexOf(T item)
=> ((IList<T>)source).IndexOf(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();
void IList<T>.Insert(int index, T item)
=> throw new NotSupportedException();
void IList<T>.RemoveAt(int index)
=> throw new NotSupportedException();
}
}
}