Skip to content

Commit ec613ab

Browse files
ds5678SamboyCoding
authored andcommitted
Use a separate class for concrete generic parameters
1 parent 69627a4 commit ec613ab

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

Cpp2IL.Core/Model/Contexts/ConcreteGenericMethodAnalysisContext.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using System;
2-
using System.Linq;
32
using System.Reflection;
43
using Cpp2IL.Core.Utils;
54
using LibCpp2IL;
6-
using LibCpp2IL.BinaryStructures;
75
using LibCpp2IL.Reflection;
86

97
namespace Cpp2IL.Core.Model.Contexts;
@@ -107,15 +105,12 @@ private ConcreteGenericMethodAnalysisContext(Cpp2IlMethodRef? methodRef, MethodA
107105
for (var i = 0; i < BaseMethodContext.Parameters.Count; i++)
108106
{
109107
var parameter = BaseMethodContext.Parameters[i];
110-
var parameterType = parameter.ParameterTypeContext;
111108
var instantiatedType = GenericInstantiation.Instantiate(
112109
parameter.ParameterTypeContext,
113110
typeGenericParameters,
114111
methodGenericParameters);
115112

116-
Parameters.Add(parameterType == instantiatedType
117-
? parameter
118-
: new InjectedParameterAnalysisContext(parameter.Name, instantiatedType, parameter.ParameterAttributes, i, BaseMethodContext));
113+
Parameters.Add(new ConcreteGenericParameterAnalysisContext(parameter, instantiatedType, this));
119114
}
120115

121116
InjectedReturnType = GenericInstantiation.Instantiate(BaseMethodContext.ReturnTypeContext, typeGenericParameters, methodGenericParameters);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Reflection;
4+
using LibCpp2IL.BinaryStructures;
5+
6+
namespace Cpp2IL.Core.Model.Contexts;
7+
8+
public class ConcreteGenericParameterAnalysisContext : ParameterAnalysisContext
9+
{
10+
public ParameterAnalysisContext BaseParameterContext { get; }
11+
public override TypeAnalysisContext ParameterTypeContext { get; }
12+
public override ParameterAttributes ParameterAttributes => BaseParameterContext.ParameterAttributes;
13+
public override Il2CppType ParameterType => throw new NotSupportedException($"Instantiated generic parameters don't have an {nameof(Il2CppType)}");
14+
public override string DefaultName => BaseParameterContext.DefaultName;
15+
public override string? OverrideName { get => BaseParameterContext.OverrideName; set => BaseParameterContext.OverrideName = value; }
16+
protected override int CustomAttributeIndex => -1;
17+
18+
public ConcreteGenericParameterAnalysisContext(ParameterAnalysisContext baseParameter, TypeAnalysisContext parameterType, ConcreteGenericMethodAnalysisContext declaringMethod) : base(null, baseParameter.ParamIndex, declaringMethod)
19+
{
20+
BaseParameterContext = baseParameter;
21+
ParameterTypeContext = parameterType;
22+
}
23+
}

0 commit comments

Comments
 (0)