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

SamboyCoding / Cpp2IL / 15025228993

14 May 2025 03:48PM UTC coverage: 34.685% (-0.1%) from 34.826%
15025228993

Pull #452

github

web-flow
Merge 08a645b97 into e93c0fecc
Pull Request #452: Expand type system to support more types

1813 of 6512 branches covered (27.84%)

Branch coverage included in aggregate %.

22 of 101 new or added lines in 12 files covered. (21.78%)

4 existing lines in 3 files now uncovered.

4158 of 10703 relevant lines covered (38.85%)

160402.6 hits per line

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

45.1
/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;
188,464!
25

26
    public override AssemblyAnalysisContext CustomAttributeAssembly => DeclaringType.DeclaringAssembly;
294,388✔
27

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

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

32
    public virtual FieldAttributes Attributes => BackingData!.Attributes;
59,155✔
33

34
    public bool IsStatic => Attributes.HasFlag(FieldAttributes.Static);
260✔
35

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

38
    public virtual TypeAnalysisContext FieldTypeContext => DeclaringType.DeclaringAssembly.ResolveIl2CppType(FieldType)
58,895!
39
                                                           ?? throw new($"Field type {FieldType} could not be resolved.");
58,895✔
40

41

42
    public FieldAnalysisContext(Il2CppFieldReflectionData? backingData, TypeAnalysisContext parent) : base(backingData?.Field.token ?? 0, parent.AppContext)
241,468✔
43
    {
44
        DeclaringType = parent;
241,468✔
45
        BackingData = backingData;
241,468✔
46

47
        if (BackingData != null)
241,468✔
48
            InitCustomAttributeData();
241,426✔
49
    }
241,468✔
50

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

53
    #region StableNameDotNet
54

55
    public ITypeInfoProvider FieldTypeInfoProvider
NEW
56
        => GetGenericParamName(FieldTypeContext) is { } name
×
NEW
57
            ? new GenericParameterTypeInfoProviderWrapper(name)
×
UNCOV
58
            : TypeAnalysisContext.GetSndnProviderForType(AppContext, FieldType!);
×
59

60
    public string FieldName => Name;
58,895✔
61

NEW
62
    public FieldAttributes FieldAttributes => Attributes;
×
63

NEW
64
    private static string? GetGenericParamName(TypeAnalysisContext type) => type switch
×
65
    {
×
NEW
66
        GenericParameterTypeAnalysisContext genericParam => genericParam.Name,
×
NEW
67
        WrappedTypeAnalysisContext wrapped => GetGenericParamName(wrapped.ElementType),
×
NEW
68
        _ => null
×
UNCOV
69
    };
×
70

71
    #endregion
72
}
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