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

NetFabric / NetFabric.CodeAnalysis / 6277926364

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

push

github

web-flow
Add IsIndexable (#28)

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

92.86
/NetFabric.Reflection/Reflection/TypeExtensions.IsIndexable.cs
1
using System;
2
using System.Diagnostics.CodeAnalysis;
3
using System.Reflection;
4

5
namespace NetFabric.Reflection;
6

7
public static partial class TypeExtensions
8
{        
9
    public static bool IsIndexable(this Type type)
10
        => IsIndexable(type, out _, out _);
×
11

12
    public static bool IsIndexable(this Type type, [NotNullWhen(true)] out IndexableInfo? indexableInfo)
13
        => IsIndexable(type, out indexableInfo, out _);
×
14

15
    public static bool IsIndexable(this Type type,
16
        [NotNullWhen(true)] out IndexableInfo? indexableInfo,
17
        out IsIndexableError error)
18
    {
19
        var countOrLength = type.GetPublicReadProperty(NameOf.Count);
16✔
20
        countOrLength ??= type.GetPublicReadProperty(NameOf.Length);
16✔
21
        if (countOrLength is null || !countOrLength.PropertyType.IsIntegerType())
16✔
22
        {
23
            indexableInfo = default;
1✔
24
            error = IsIndexableError.MissingCountOrLength;
1✔
25
            return false;
1✔
26
        }
27

28
        var indexer = default(PropertyInfo);
15✔
29
        if (!type.IsArray)
15✔
30
        {
31
            indexer = type.GetPublicReadIndexer(countOrLength.PropertyType);
8✔
32
            if (indexer is null)
8✔
33
            {
34
                indexableInfo = default;
2✔
35
                error = IsIndexableError.MissingIndexer;
2✔
36
                return false;
2✔
37
            }
38
        }
39

40
        indexableInfo = new IndexableInfo(indexer, countOrLength);
13✔
41
        error = IsIndexableError.None;
13✔
42
        return true;
13✔
43
    }
44
}
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

© 2025 Coveralls, Inc