Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions Cpp2IL.Core/Model/Contexts/InjectedMethodAnalysisContext.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Reflection;

namespace Cpp2IL.Core.Model.Contexts;
Expand All @@ -23,20 +24,28 @@ public InjectedMethodAnalysisContext(
string name,
TypeAnalysisContext returnType,
MethodAttributes attributes,
TypeAnalysisContext[] injectedParameterTypes,
string[]? injectedParameterNames = null,
ParameterAttributes[]? injectedParameterAttributes = null,
ReadOnlySpan<TypeAnalysisContext> injectedParameterTypes,
ReadOnlySpan<string> injectedParameterNames = default,
ReadOnlySpan<ParameterAttributes> injectedParameterAttributes = default,
MethodImplAttributes defaultImplAttributes = MethodImplAttributes.Managed) : base(null, parent)
{
DefaultName = name;
DefaultReturnType = returnType;
DefaultAttributes = attributes;

var hasParameterNames = !injectedParameterNames.IsEmpty;
var hasParameterAttributes = !injectedParameterAttributes.IsEmpty;

if (hasParameterNames && injectedParameterNames.Length != injectedParameterTypes.Length)
throw new ArgumentException("Length of injected parameter names must match length of injected parameter types.", nameof(injectedParameterNames));
if (hasParameterAttributes && injectedParameterAttributes.Length != injectedParameterTypes.Length)
throw new ArgumentException("Length of injected parameter attributes must match length of injected parameter types.", nameof(injectedParameterAttributes));

for (var i = 0; i < injectedParameterTypes.Length; i++)
{
var injectedParameterType = injectedParameterTypes[i];
var injectedParameterName = injectedParameterNames?[i];
var injectedParameterAttribute = injectedParameterAttributes?[i] ?? ParameterAttributes.None;
var injectedParameterName = hasParameterNames ? injectedParameterNames[i] : null;
var injectedParameterAttribute = hasParameterAttributes ? injectedParameterAttributes[i] : ParameterAttributes.None;

Parameters.Add(new InjectedParameterAnalysisContext(injectedParameterName, injectedParameterType, injectedParameterAttribute, i, this));
}
Expand Down
3 changes: 2 additions & 1 deletion Cpp2IL.Core/Model/Contexts/InjectedTypeAnalysisContext.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Reflection;

namespace Cpp2IL.Core.Model.Contexts;
Expand All @@ -22,7 +23,7 @@ public InjectedTypeAnalysisContext(AssemblyAnalysisContext containingAssembly, s
DefaultAttributes = typeAttributes;
}

public InjectedMethodAnalysisContext InjectMethodContext(string methodName, TypeAnalysisContext returnType, MethodAttributes attributes, params TypeAnalysisContext[] args)
public InjectedMethodAnalysisContext InjectMethodContext(string methodName, TypeAnalysisContext returnType, MethodAttributes attributes, params ReadOnlySpan<TypeAnalysisContext> args)
{
var method = new InjectedMethodAnalysisContext(this, methodName, returnType, attributes, args);
Methods.Add(method);
Expand Down
14 changes: 11 additions & 3 deletions Cpp2IL.Core/Model/MultiAssemblyInjectedType.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand All @@ -9,10 +10,17 @@ public class MultiAssemblyInjectedType(InjectedTypeAnalysisContext[] injectedTyp
{
public InjectedTypeAnalysisContext[] InjectedTypes { get; } = injectedTypes;

public Dictionary<AssemblyAnalysisContext, InjectedMethodAnalysisContext> InjectMethodToAllAssemblies(string name, TypeAnalysisContext returnType, MethodAttributes attributes, params TypeAnalysisContext[] args)
=> InjectedTypes.ToDictionary(t => t.DeclaringAssembly, t => t.InjectMethodContext(name, returnType, attributes, args));
public Dictionary<AssemblyAnalysisContext, InjectedMethodAnalysisContext> InjectMethodToAllAssemblies(string name, TypeAnalysisContext returnType, MethodAttributes attributes, params ReadOnlySpan<TypeAnalysisContext> args)
{
var dictionary = new Dictionary<AssemblyAnalysisContext, InjectedMethodAnalysisContext>();
foreach (var type in InjectedTypes)
{
dictionary[type.DeclaringAssembly] = type.InjectMethodContext(name, returnType, attributes, args);
}
return dictionary;
}

public Dictionary<AssemblyAnalysisContext, InjectedMethodAnalysisContext> InjectConstructor(bool isStatic, params TypeAnalysisContext[] args)
public Dictionary<AssemblyAnalysisContext, InjectedMethodAnalysisContext> InjectConstructor(bool isStatic, params ReadOnlySpan<TypeAnalysisContext> args)
{
var attributes = isStatic
? MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName | MethodAttributes.HideBySig | MethodAttributes.Static
Expand Down
Loading