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

SamboyCoding / Cpp2IL / 20488056168

24 Dec 2025 02:19PM UTC coverage: 34.361% (+0.05%) from 34.31%
20488056168

Pull #499

github

web-flow
Merge 482cdd13f into 3a72c253a
Pull Request #499: Add ResolveContextForMethod overload taking Cpp2IlMethodRef as a parameter

1811 of 6624 branches covered (27.34%)

Branch coverage included in aggregate %.

0 of 3 new or added lines in 1 file covered. (0.0%)

187 existing lines in 10 files now uncovered.

4208 of 10893 relevant lines covered (38.63%)

201355.63 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;
294,475!
27

28
    public override AssemblyAnalysisContext CustomAttributeAssembly => DeclaringType.DeclaringAssembly;
747,836✔
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
39
    {
40
        get => OverrideAttributes ?? DefaultAttributes;
59,155!
UNCOV
41
        set => OverrideAttributes = value;
×
42
    }
43

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

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

48
    public virtual object? OverrideConstantValue { get; set; }
21,365✔
49

50
    public object? ConstantValue
51
    {
52
        get => OverrideConstantValue ?? DefaultConstantValue;
21,365✔
UNCOV
53
        set => OverrideConstantValue = value;
×
54
    }
55

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

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

61
    public TypeAnalysisContext? OverrideFieldType { get; set; }
58,896✔
62

63
    public TypeAnalysisContext FieldType
64
    {
65
        get => OverrideFieldType ?? DefaultFieldType;
58,896✔
UNCOV
66
        set => OverrideFieldType = value;
×
67
    }
68

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

71
    public virtual byte[]? OverrideStaticArrayInitialValue { get; set; }
540✔
72

73
    public byte[] StaticArrayInitialValue
74
    {
75
        get => OverrideStaticArrayInitialValue ?? DefaultStaticArrayInitialValue;
540✔
UNCOV
76
        set => OverrideStaticArrayInitialValue = value;
×
77
    }
78

79
    public FieldAttributes Visibility
80
    {
81
        get
82
        {
UNCOV
83
            return Attributes & FieldAttributes.FieldAccessMask;
×
84
        }
85
        set
86
        {
87
            Attributes = (Attributes & ~FieldAttributes.FieldAccessMask) | (value & FieldAttributes.FieldAccessMask);
×
UNCOV
88
        }
×
89
    }
90

91

92
    public FieldAnalysisContext(Il2CppFieldReflectionData? backingData, TypeAnalysisContext parent) : base(backingData?.Field.token ?? 0, parent.AppContext)
347,479✔
93
    {
94
        DeclaringType = parent;
347,479✔
95
        BackingData = backingData;
347,479✔
96

97
        if (BackingData != null)
347,479✔
98
            InitCustomAttributeData();
347,437✔
99
    }
347,479✔
100

101
    public ConcreteGenericFieldAnalysisContext MakeConcreteGenericField(params IEnumerable<TypeAnalysisContext> typeGenericParameters)
102
    {
103
        if (this is ConcreteGenericFieldAnalysisContext)
×
104
        {
UNCOV
105
            throw new InvalidOperationException($"Attempted to make a {nameof(ConcreteGenericFieldAnalysisContext)} concrete: {this}");
×
106
        }
107
        else
108
        {
UNCOV
109
            return new ConcreteGenericFieldAnalysisContext(this, typeGenericParameters);
×
110
        }
111
    }
112

113
    public override string ToString() => $"Field: {DeclaringType.Name}::{Name}";
×
114

115
    #region StableNameDotNet
116

117
    ITypeInfoProvider IFieldInfoProvider.FieldTypeInfoProvider
UNCOV
118
        => GetGenericParamName(FieldType) is { } name
×
UNCOV
119
            ? new GenericParameterTypeInfoProviderWrapper(name)
×
UNCOV
120
            : TypeAnalysisContext.GetSndnProviderForType(AppContext, RawFieldType!);
×
121

UNCOV
122
    string IFieldInfoProvider.FieldName => Name;
×
123

UNCOV
124
    FieldAttributes IFieldInfoProvider.FieldAttributes => Attributes;
×
125

UNCOV
126
    private static string? GetGenericParamName(TypeAnalysisContext type) => type switch
×
UNCOV
127
    {
×
UNCOV
128
        GenericParameterTypeAnalysisContext genericParam => genericParam.Name,
×
UNCOV
129
        WrappedTypeAnalysisContext wrapped => GetGenericParamName(wrapped.ElementType),
×
UNCOV
130
        _ => null
×
UNCOV
131
    };
×
132

133
    #endregion
134
}
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