BsMonoMethod.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #include "BsMonoPrerequisites.h"
  3. #include <mono/jit/jit.h>
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Encapsulates information about a single Mono (i.e. managed) method
  8. * belonging to some managed class. This object also allows you to invoke
  9. * the method.
  10. */
  11. class BS_MONO_EXPORT MonoMethod
  12. {
  13. public:
  14. /**
  15. * @brief Invokes the method on the provided object instance.
  16. * This does not respect polymorphism and will invoke the exact method
  17. * of the class this object was retrieved from. Use "invokeVirtual" if you
  18. * need polymorphism.
  19. *
  20. * @param instance Instance of the object to invoke the method on. Can be null for static methods.
  21. * @param param Array of parameters to pass to the method. Caller must ensure they match method
  22. * parameter count and type. For value types parameters should be pointers to the
  23. * values and for reference types they should be pointers to MonoObject.
  24. *
  25. @returns A boxed return value, or null if method has no return value.
  26. */
  27. MonoObject* invoke(MonoObject* instance, void** params);
  28. /**
  29. * @brief Invokes the method on the provided object instance. If the instance has an override of this
  30. * method it will be called.
  31. *
  32. * @param instance Instance of the object to invoke the method on.
  33. * @param param Array of parameters to pass to the method. Caller must ensure they match method
  34. * parameter count and type. For value types parameters should be pointers to the
  35. * values and for reference types they should be pointers to MonoObject.
  36. *
  37. * @returns A boxed return value, or null if method has no return value.
  38. */
  39. MonoObject* invokeVirtual(MonoObject* instance, void** params);
  40. /**
  41. * @brief Gets a thunk for this method. A thunk is a C++ like function
  42. * pointer that you can use for calling the method.
  43. *
  44. * @note This is the fastest way of calling managed code.
  45. */
  46. void* getThunk() const;
  47. /**
  48. * @brief Returns the name of the method.
  49. */
  50. String getName() const;
  51. /**
  52. * @brief Returns the type of the return value. Returns null if method
  53. * has no return value.
  54. */
  55. MonoClass* getReturnType();
  56. private:
  57. friend class MonoClass;
  58. friend class MonoProperty;
  59. MonoMethod(::MonoMethod* method);
  60. ::MonoMethod* mMethod;
  61. MonoClass* mReturnType;
  62. void* mThunk;
  63. };
  64. }