This repository was archived by the owner on Jun 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathTupleTypedArrayWrapper.cs
More file actions
55 lines (47 loc) · 1.61 KB
/
Copy pathTupleTypedArrayWrapper.cs
File metadata and controls
55 lines (47 loc) · 1.61 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;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
namespace Llvm.NET.DebugInfo
{
/// <summary>Generic wrapper to treat an MDTuple as an array of elements of specific type</summary>
/// <typeparam name="T">Type of elements</typeparam>
/// <remarks>
/// This treats the operands of a tuple as the elements of the array
/// </remarks>
[SuppressMessage( "Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification = "Collection doesn't make sense for this type" )]
public class TupleTypedArrayWrapper<T>
: IReadOnlyList<T>
where T : LlvmMetadata
{
public TupleTypedArrayWrapper( MDTuple tuple )
{
Tuple = tuple;
}
public MDTuple Tuple { get; }
public int Count => Tuple.Operands.Count;
public T this[ int index ]
{
get
{
if( Tuple == null )
{
throw new InvalidOperationException( "Wrapped node is null" );
}
if( index > Tuple.Operands.Count )
{
throw new ArgumentOutOfRangeException( nameof( index ) );
}
return Tuple.Operands[ index ].Metadata as T;
}
}
public IEnumerator<T> GetEnumerator( )
{
return Tuple.Operands
.Select( n => n.Metadata as T )
.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator( ) => GetEnumerator();
}
}