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

SamboyCoding / Cpp2IL / 17684316232

12 Sep 2025 07:36PM UTC coverage: 34.302% (-0.02%) from 34.326%
17684316232

push

github

web-flow
Add some additional methods for working with concrete generics (#485)

1791 of 6592 branches covered (27.17%)

Branch coverage included in aggregate %.

0 of 8 new or added lines in 3 files covered. (0.0%)

1 existing line in 1 file now uncovered.

4191 of 10847 relevant lines covered (38.64%)

180612.93 hits per line

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

50.57
/Cpp2IL.Core/Model/Contexts/FieldAnalysisContext.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Reflection;
4
using Cpp2IL.Core.Utils;
5
using LibCpp2IL.BinaryStructures;
6
using LibCpp2IL.Reflection;
7
using StableNameDotNet.Providers;
8

9
namespace Cpp2IL.Core.Model.Contexts;
10

11
/// <summary>
12
/// Represents a field in a managed type.
13
/// </summary>
14
public class FieldAnalysisContext : HasCustomAttributesAndName, IFieldInfoProvider
15
{
16
    /// <summary>
17
    /// The analysis context for the type that this field belongs to.
18
    /// </summary>
19
    public readonly TypeAnalysisContext DeclaringType;
20

21
    /// <summary>
22
    /// The underlying field metadata.
23
    /// </summary>
24
    public readonly Il2CppFieldReflectionData? BackingData;
25

26
    protected override int CustomAttributeIndex => BackingData?.Field.customAttributeIndex ?? -1;
247,359!
27

28
    public override AssemblyAnalysisContext CustomAttributeAssembly => DeclaringType.DeclaringAssembly;
653,604✔
29

30
    public override string DefaultName => BackingData?.Field.Name!;
58,895!
31

32
    private Il2CppType? RawFieldType => BackingData?.Field.RawFieldType;
58,895!
33

34
    public virtual FieldAttributes DefaultAttributes => BackingData?.Attributes ?? throw new($"Subclass must override {nameof(DefaultAttributes)}");
59,155!
35

36
    public virtual FieldAttributes? OverrideAttributes { get; set; }
59,155✔
37

38
    public FieldAttributes Attributes => OverrideAttributes ?? DefaultAttributes;
59,155!
39

40
    public bool IsStatic => (Attributes & FieldAttributes.Static) != 0;
260✔
41

42
    public virtual object? DefaultConstantValue => BackingData?.Field.DefaultValue?.Value;
21,365!
43

44
    public virtual object? OverrideConstantValue { get; set; }
21,365✔
45

46
    public object? ConstantValue => OverrideConstantValue ?? DefaultConstantValue;
21,365✔
47

48
    public int Offset => BackingData == null ? 0 : AppContext.Binary.GetFieldOffsetFromIndex(DeclaringType.Definition!.TypeIndex, BackingData.IndexInParent, BackingData.Field.FieldIndex, DeclaringType.Definition.IsValueType, IsStatic);
×
49

50
    public virtual TypeAnalysisContext DefaultFieldType => DeclaringType.DeclaringAssembly.ResolveIl2CppType(RawFieldType)
58,895!
51
                                                           ?? throw new($"Field type {RawFieldType} could not be resolved.");
58,895✔
52

53
    public TypeAnalysisContext? OverrideFieldType { get; set; }
58,896✔
54

55
    public TypeAnalysisContext FieldType => OverrideFieldType ?? DefaultFieldType;
58,896✔
56

57
    public virtual byte[] DefaultStaticArrayInitialValue => BackingData?.Field.StaticArrayInitialValue ?? [];
540!
58

59
    public virtual byte[]? OverrideStaticArrayInitialValue { get; set; }
540✔
60

61
    public byte[] StaticArrayInitialValue => OverrideStaticArrayInitialValue ?? DefaultStaticArrayInitialValue;
540✔
62

63
    public FieldAttributes Visibility
64
    {
65
        get
66
        {
67
            return Attributes & FieldAttributes.FieldAccessMask;
×
68
        }
69
        set
70
        {
71
            OverrideAttributes = (Attributes & ~FieldAttributes.FieldAccessMask) | (value & FieldAttributes.FieldAccessMask);
×
72
        }
×
73
    }
74

75

76
    public FieldAnalysisContext(Il2CppFieldReflectionData? backingData, TypeAnalysisContext parent) : base(backingData?.Field.token ?? 0, parent.AppContext)
300,363✔
77
    {
78
        DeclaringType = parent;
300,363✔
79
        BackingData = backingData;
300,363✔
80

81
        if (BackingData != null)
300,363✔
82
            InitCustomAttributeData();
300,321✔
83
    }
300,363✔
84

85
    public ConcreteGenericFieldAnalysisContext MakeConcreteGenericField(params IEnumerable<TypeAnalysisContext> typeGenericParameters)
86
    {
NEW
87
        if (this is ConcreteGenericFieldAnalysisContext)
×
88
        {
NEW
89
            throw new InvalidOperationException($"Attempted to make a {nameof(ConcreteGenericFieldAnalysisContext)} concrete: {this}");
×
90
        }
91
        else
92
        {
NEW
93
            return new ConcreteGenericFieldAnalysisContext(this, typeGenericParameters);
×
94
        }
95
    }
96

UNCOV
97
    public override string ToString() => $"Field: {DeclaringType.Definition?.Name}::{BackingData?.Field.Name}";
×
98

99
    #region StableNameDotNet
100

101
    ITypeInfoProvider IFieldInfoProvider.FieldTypeInfoProvider
102
        => GetGenericParamName(FieldType) is { } name
×
103
            ? new GenericParameterTypeInfoProviderWrapper(name)
×
104
            : TypeAnalysisContext.GetSndnProviderForType(AppContext, RawFieldType!);
×
105

106
    string IFieldInfoProvider.FieldName => Name;
×
107

108
    FieldAttributes IFieldInfoProvider.FieldAttributes => Attributes;
×
109

110
    private static string? GetGenericParamName(TypeAnalysisContext type) => type switch
×
111
    {
×
112
        GenericParameterTypeAnalysisContext genericParam => genericParam.Name,
×
113
        WrappedTypeAnalysisContext wrapped => GetGenericParamName(wrapped.ElementType),
×
114
        _ => null
×
115
    };
×
116

117
    #endregion
118
}
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