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

SamboyCoding / Cpp2IL / 15953064765

29 Jun 2025 07:58AM UTC coverage: 34.323% (+0.02%) from 34.308%
15953064765

Pull #475

github

web-flow
Merge 2bb66031a into 9ce22e911
Pull Request #475: Expand API functionality

1786 of 6576 branches covered (27.16%)

Branch coverage included in aggregate %.

11 of 21 new or added lines in 5 files covered. (52.38%)

1 existing line in 1 file now uncovered.

4189 of 10832 relevant lines covered (38.67%)

183464.28 hits per line

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

53.66
/Cpp2IL.Core/Model/Contexts/FieldAnalysisContext.cs
1
using System.Reflection;
2
using Cpp2IL.Core.Utils;
3
using LibCpp2IL.BinaryStructures;
4
using LibCpp2IL.Reflection;
5
using StableNameDotNet.Providers;
6

7
namespace Cpp2IL.Core.Model.Contexts;
8

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

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

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

26
    public override AssemblyAnalysisContext CustomAttributeAssembly => DeclaringType.DeclaringAssembly;
653,604✔
27

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

30
    private Il2CppType? RawFieldType => BackingData?.Field.RawFieldType;
58,895!
31

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

34
    public virtual FieldAttributes? OverrideAttributes { get; set; }
59,155✔
35

36
    public FieldAttributes Attributes => OverrideAttributes ?? DefaultAttributes;
59,155!
37

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

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

42
    public virtual object? OverrideConstantValue { get; set; }
21,365✔
43

44
    public object? ConstantValue => OverrideConstantValue ?? DefaultConstantValue;
21,365✔
45

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

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

51
    public TypeAnalysisContext? OverrideFieldType { get; set; }
58,896✔
52

53
    public TypeAnalysisContext FieldType => OverrideFieldType ?? DefaultFieldType;
58,896✔
54

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

57
    public virtual byte[]? OverrideStaticArrayInitialValue { get; set; }
540✔
58

59
    public byte[] StaticArrayInitialValue => OverrideStaticArrayInitialValue ?? DefaultStaticArrayInitialValue;
540✔
60

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

73

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

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

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

85
    #region StableNameDotNet
86

87
    ITypeInfoProvider IFieldInfoProvider.FieldTypeInfoProvider
88
        => GetGenericParamName(FieldType) is { } name
×
89
            ? new GenericParameterTypeInfoProviderWrapper(name)
×
90
            : TypeAnalysisContext.GetSndnProviderForType(AppContext, RawFieldType!);
×
91

92
    string IFieldInfoProvider.FieldName => Name;
×
93

94
    FieldAttributes IFieldInfoProvider.FieldAttributes => Attributes;
×
95

96
    private static string? GetGenericParamName(TypeAnalysisContext type) => type switch
×
97
    {
×
98
        GenericParameterTypeAnalysisContext genericParam => genericParam.Name,
×
99
        WrappedTypeAnalysisContext wrapped => GetGenericParamName(wrapped.ElementType),
×
100
        _ => null
×
101
    };
×
102

103
    #endregion
104
}
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