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

SamboyCoding / Cpp2IL / 17385610975

01 Sep 2025 07:15PM UTC coverage: 34.337% (-0.02%) from 34.352%
17385610975

Pull #485

github

web-flow
Merge a6b70dc6c into d5260685f
Pull Request #485: Add some additional methods for working with concrete generics

1789 of 6588 branches covered (27.16%)

Branch coverage included in aggregate %.

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

1 existing line in 1 file now uncovered.

4200 of 10854 relevant lines covered (38.7%)

180496.28 hits per line

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

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

8
namespace Cpp2IL.Core.Model.Contexts;
9

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

74

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

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

84
    public ConcreteGenericFieldAnalysisContext MakeConcreteGenericField(params IEnumerable<TypeAnalysisContext> typeGenericParameters)
85
    {
NEW
86
        return new(this, typeGenericParameters);
×
87
    }
88

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

91
    #region StableNameDotNet
92

93
    ITypeInfoProvider IFieldInfoProvider.FieldTypeInfoProvider
94
        => GetGenericParamName(FieldType) is { } name
×
95
            ? new GenericParameterTypeInfoProviderWrapper(name)
×
96
            : TypeAnalysisContext.GetSndnProviderForType(AppContext, RawFieldType!);
×
97

98
    string IFieldInfoProvider.FieldName => Name;
×
99

100
    FieldAttributes IFieldInfoProvider.FieldAttributes => Attributes;
×
101

102
    private static string? GetGenericParamName(TypeAnalysisContext type) => type switch
×
103
    {
×
104
        GenericParameterTypeAnalysisContext genericParam => genericParam.Name,
×
105
        WrappedTypeAnalysisContext wrapped => GetGenericParamName(wrapped.ElementType),
×
106
        _ => null
×
107
    };
×
108

109
    #endregion
110
}
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