using System; using Mono.Cecil; namespace Robust.Xaml; /// /// Source: https://github.com/jbevain/cecil/blob/master/Test/Mono.Cecil.Tests/Extensions.cs /// internal static class CecilExtensions { /// /// Specialize some generic parameters of a reference to a generic method. The return value /// is a more monomorphized version. /// /// the original MethodReference /// the specialized arguments /// the monomorphic MethodReference /// if the number of passed arguments is wrong public static MethodReference MakeGenericMethod(this MethodReference self, params TypeReference[] arguments) { if (self.GenericParameters.Count != arguments.Length) throw new ArgumentException(); var instance = new GenericInstanceMethod(self); foreach (var argument in arguments) { instance.GenericArguments.Add(argument); } return instance; } }