暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CecilExtensionMethods.cs 1.4KB

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