Skip to content

Commit 60e16a0

Browse files
ds5678SamboyCoding
authored andcommitted
ContextToFieldDescriptor helper class
1 parent 9b4dc9c commit 60e16a0

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using AsmResolver.DotNet;
2+
using AsmResolver.DotNet.Signatures;
3+
using Cpp2IL.Core.Model.Contexts;
4+
5+
namespace Cpp2IL.Core.Utils.AsmResolver;
6+
7+
public static class ContextToFieldDescriptor
8+
{
9+
private static FieldDefinition GetFieldDefinition(this FieldAnalysisContext context)
10+
{
11+
return context.GetExtraData<FieldDefinition>("AsmResolverField") ?? throw new($"AsmResolver field not found in method analysis context for {context}");
12+
}
13+
14+
private static FieldSignature ToFieldSignature(this FieldAnalysisContext context, ModuleDefinition parentModule)
15+
{
16+
return new FieldSignature(context.ToTypeSignature(parentModule));
17+
}
18+
19+
public static IFieldDescriptor ToFieldDescriptor(this FieldAnalysisContext context, ModuleDefinition parentModule)
20+
{
21+
return context is ConcreteGenericFieldAnalysisContext concreteField
22+
? concreteField.ToFieldDescriptor(parentModule)
23+
: parentModule.DefaultImporter.ImportField(context.GetFieldDefinition());
24+
}
25+
26+
public static IFieldDescriptor ToFieldDescriptor(this ConcreteGenericFieldAnalysisContext context, ModuleDefinition parentModule)
27+
{
28+
return new MemberReference(
29+
context.DeclaringType.ToTypeSignature(parentModule).ToTypeDefOrRef(),
30+
context.Name,
31+
context.BaseFieldContext.ToFieldSignature(parentModule));
32+
}
33+
}

0 commit comments

Comments
 (0)