Added FisheryLib.Collections.FishTable and Mono.Cecil extension methods

A bit of refactoring has been done too
This commit is contained in:
bbradson
2023-06-03 20:10:58 +02:00
parent 8fa92f15a6
commit cdf209eb02
72 changed files with 8145 additions and 2098 deletions
@@ -0,0 +1,25 @@
// Copyright (c) 2022 bradson
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v.2.0.If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
using Mono.Cecil;
namespace FisheryLib.Cecil;
public static class CecilReflectionExtensions
{
public static MethodReference ImportMethodWithGenericArguments(this ModuleDefinition module, MethodInfo method,
params Type[] genericArguments)
=> module.ImportReference(method.IsGenericMethodDefinition ? method : method.GetGenericMethodDefinition())
.MakeGenericMethod(genericArguments.GetTypeReferences(module));
public static MethodReference ImportMethodWithGenericArguments(this ModuleDefinition module, Delegate method,
params Type[] genericArguments)
=> module.ImportMethodWithGenericArguments(method.Method, genericArguments);
public static TypeReference ImportTypeWithGenericArguments(this ModuleDefinition module, Type type,
params Type[] genericArguments)
=> module.ImportReference(type.IsGenericTypeDefinition ? type : type.GetElementType())
.MakeGenericType(genericArguments.GetTypeReferences(module));
}