using Mono.Cecil;
namespace Unity.Jobs.CodeGen
{
static class TypeReferenceExtensions
{
public static TypeDefinition CheckedResolve(this TypeReference typeReference)
{
return typeReference.Resolve() ?? throw new ResolutionException(typeReference);
}
}
static class MethodReferenceExtensions
{
///
/// Generates a closed/specialized MethodReference for the given method and types[]
/// e.g.
/// struct Foo { T Bar(T val) { return default(T); }
///
/// In this case, if one would like a reference to "Foo::int Bar(int val)" this method will construct such a method
/// reference when provided the open "T Bar(T val)" method reference and the TypeReferences to the types you'd like
/// specified as generic arguments (in this case a TypeReference to "int" would be passed in).
///
///
///
///
public static MethodReference MakeGenericInstanceMethod(this MethodReference method,
params TypeReference[] types)
{
var result = new GenericInstanceMethod(method);
foreach (var type in types)
result.GenericArguments.Add(type);
return result;
}
}
}