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

SamboyCoding / Cpp2IL / 15144170590

20 May 2025 05:37PM UTC coverage: 34.277% (+0.2%) from 34.047%
15144170590

Pull #462

github

web-flow
Merge 4a307f12a into 5807d2b6c
Pull Request #462: Support overriding member types

1799 of 6648 branches covered (27.06%)

Branch coverage included in aggregate %.

115 of 202 new or added lines in 33 files covered. (56.93%)

22 existing lines in 6 files now uncovered.

4197 of 10845 relevant lines covered (38.7%)

186399.11 hits per line

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

46.88
/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 int Offset => BackingData == null ? 0 : AppContext.Binary.GetFieldOffsetFromIndex(DeclaringType.Definition!.TypeIndex, BackingData.IndexInParent, BackingData.Field.FieldIndex, DeclaringType.Definition.IsValueType, IsStatic);
×
41

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

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

47
    public TypeAnalysisContext FieldType => OverrideFieldType ?? DefaultFieldType;
58,896✔
48

49
    public FieldAttributes Visibility
50
    {
51
        get
52
        {
NEW
53
            return Attributes & FieldAttributes.FieldAccessMask;
×
54
        }
55
        set
56
        {
NEW
57
            OverrideAttributes = (Attributes & ~FieldAttributes.FieldAccessMask) | (value & FieldAttributes.FieldAccessMask);
×
NEW
58
        }
×
59
    }
60

61

62
    public FieldAnalysisContext(Il2CppFieldReflectionData? backingData, TypeAnalysisContext parent) : base(backingData?.Field.token ?? 0, parent.AppContext)
300,363✔
63
    {
64
        DeclaringType = parent;
300,363✔
65
        BackingData = backingData;
300,363✔
66

67
        if (BackingData != null)
300,363✔
68
            InitCustomAttributeData();
300,321✔
69
    }
300,363✔
70

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

73
    #region StableNameDotNet
74

75
    ITypeInfoProvider IFieldInfoProvider.FieldTypeInfoProvider
NEW
76
        => GetGenericParamName(FieldType) is { } name
×
77
            ? new GenericParameterTypeInfoProviderWrapper(name)
×
NEW
78
            : TypeAnalysisContext.GetSndnProviderForType(AppContext, RawFieldType!);
×
79

NEW
80
    string IFieldInfoProvider.FieldName => Name;
×
81

NEW
82
    FieldAttributes IFieldInfoProvider.FieldAttributes => Attributes;
×
83

84
    private static string? GetGenericParamName(TypeAnalysisContext type) => type switch
×
85
    {
×
86
        GenericParameterTypeAnalysisContext genericParam => genericParam.Name,
×
87
        WrappedTypeAnalysisContext wrapped => GetGenericParamName(wrapped.ElementType),
×
88
        _ => null
×
89
    };
×
90

91
    #endregion
92
}
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