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

SamboyCoding / Cpp2IL / 18664957279

20 Oct 2025 09:07PM UTC coverage: 34.295% (-0.02%) from 34.31%
18664957279

Pull #491

github

web-flow
Merge c3be0c866 into e66a74bb3
Pull Request #491: Add set accessor for Attributes properties

1791 of 6588 branches covered (27.19%)

Branch coverage included in aggregate %.

8 of 19 new or added lines in 7 files covered. (42.11%)

124 existing lines in 6 files now uncovered.

4191 of 10855 relevant lines covered (38.61%)

180479.82 hits per line

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

52.38
/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
39
    {
40
        get => OverrideAttributes ?? DefaultAttributes;
59,155!
NEW
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 => OverrideConstantValue ?? DefaultConstantValue;
21,365✔
51

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

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

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

59
    public TypeAnalysisContext FieldType => OverrideFieldType ?? DefaultFieldType;
58,896✔
60

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

63
    public virtual byte[]? OverrideStaticArrayInitialValue { get; set; }
540✔
64

65
    public byte[] StaticArrayInitialValue => OverrideStaticArrayInitialValue ?? DefaultStaticArrayInitialValue;
540✔
66

67
    public FieldAttributes Visibility
68
    {
69
        get
70
        {
UNCOV
71
            return Attributes & FieldAttributes.FieldAccessMask;
×
72
        }
73
        set
74
        {
NEW
75
            Attributes = (Attributes & ~FieldAttributes.FieldAccessMask) | (value & FieldAttributes.FieldAccessMask);
×
76
        }
×
77
    }
78

79

80
    public FieldAnalysisContext(Il2CppFieldReflectionData? backingData, TypeAnalysisContext parent) : base(backingData?.Field.token ?? 0, parent.AppContext)
300,363✔
81
    {
82
        DeclaringType = parent;
300,363✔
83
        BackingData = backingData;
300,363✔
84

85
        if (BackingData != null)
300,363✔
86
            InitCustomAttributeData();
300,321✔
87
    }
300,363✔
88

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

UNCOV
101
    public override string ToString() => $"Field: {DeclaringType.Name}::{Name}";
×
102

103
    #region StableNameDotNet
104

105
    ITypeInfoProvider IFieldInfoProvider.FieldTypeInfoProvider
UNCOV
106
        => GetGenericParamName(FieldType) is { } name
×
UNCOV
107
            ? new GenericParameterTypeInfoProviderWrapper(name)
×
UNCOV
108
            : TypeAnalysisContext.GetSndnProviderForType(AppContext, RawFieldType!);
×
109

UNCOV
110
    string IFieldInfoProvider.FieldName => Name;
×
111

UNCOV
112
    FieldAttributes IFieldInfoProvider.FieldAttributes => Attributes;
×
113

UNCOV
114
    private static string? GetGenericParamName(TypeAnalysisContext type) => type switch
×
UNCOV
115
    {
×
UNCOV
116
        GenericParameterTypeAnalysisContext genericParam => genericParam.Name,
×
UNCOV
117
        WrappedTypeAnalysisContext wrapped => GetGenericParamName(wrapped.ElementType),
×
118
        _ => null
×
119
    };
×
120

121
    #endregion
122
}
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