• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NetFabric / NetFabric.CodeAnalysis / 6277898578

22 Sep 2023 06:35PM UTC coverage: 73.953% (-9.2%) from 83.158%
6277898578

Pull #28

github

aalmada
Add IsIndexable
Pull Request #28: Add IsIndexable

323 of 452 branches covered (0.0%)

Branch coverage included in aggregate %.

349 of 349 new or added lines in 18 files covered. (100.0%)

648 of 861 relevant lines covered (75.26%)

20.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

33.33
/NetFabric.Reflection/Reflection/IndexableInfo.cs
1
using System;
2
using System.Reflection;
3

4
namespace NetFabric.Reflection;
5

6
/// <summary>
7
/// Contains information about methods and properties that will be used to enumerate a given type using the indexer.
8
/// </summary>
9
public class IndexableInfo
10
{
11
    /// <summary>
12
    /// Information on the indexer with a single parameter of type <see cref="int"/>.
13
    /// </summary>
14
    /// <remarks><c>null</c> if indexable is an array.</remarks>
15
    public PropertyInfo? Indexer { get; }
13✔
16
    
17
    /// <summary>
18
    /// Information on the indexer with a single parameter of type <see cref="int"/>.
19
    /// </summary>
20
    public PropertyInfo CountOrLength { get; }
19✔
21

22
    internal IndexableInfo(PropertyInfo indexer, PropertyInfo countOrLength)
13✔
23
    {
24
        Indexer = indexer;
13✔
25
        CountOrLength = countOrLength;
13✔
26
    }
13✔
27

28
    public object? InvokeIndexer(object instance, int index)
29
    {
30
        try
31
        {
32
            return Indexer is null
×
33
                ? ((Array)instance).GetValue(index)
×
34
                : Indexer.GetValue(instance, new object[] { index });
×
35
        }
36
        catch (TargetInvocationException exception)
×
37
        {
38
            throw new EnumerationException($"Unhandled exception in {Indexer.DeclaringType!.Name}.{Indexer!.Name}", exception.InnerException!);
×
39
        }
40
    }
×
41

42
    public int InvokeCountOrLength(object instance)
43
    {
44
        try
45
        {
46
            return (int)CountOrLength.GetValue(instance);
×
47
        }
48
        catch (TargetInvocationException exception)
×
49
        {
50
            throw new EnumerationException($"Unhandled exception in {CountOrLength.DeclaringType!.Name}.{CountOrLength!.Name}", exception.InnerException!);
×
51
        }
52
    }
×
53
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc