A game about forced loneliness, made by TACStudios
1using Mono.Cecil;
2
3namespace Unity.Jobs.CodeGen
4{
5 static class TypeReferenceExtensions
6 {
7 public static TypeDefinition CheckedResolve(this TypeReference typeReference)
8 {
9 return typeReference.Resolve() ?? throw new ResolutionException(typeReference);
10 }
11 }
12
13 static class MethodReferenceExtensions
14 {
15 /// <summary>
16 /// Generates a closed/specialized MethodReference for the given method and types[]
17 /// e.g.
18 /// struct Foo { T Bar<T>(T val) { return default(T); }
19 ///
20 /// In this case, if one would like a reference to "Foo::int Bar(int val)" this method will construct such a method
21 /// reference when provided the open "T Bar(T val)" method reference and the TypeReferences to the types you'd like
22 /// specified as generic arguments (in this case a TypeReference to "int" would be passed in).
23 /// </summary>
24 /// <param name="method"></param>
25 /// <param name="types"></param>
26 /// <returns></returns>
27 public static MethodReference MakeGenericInstanceMethod(this MethodReference method,
28 params TypeReference[] types)
29 {
30 var result = new GenericInstanceMethod(method);
31 foreach (var type in types)
32 result.GenericArguments.Add(type);
33 return result;
34 }
35 }
36}