BsMonoMethod.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. ~MonoMethod();
  15. /**
  16. * @brief Invokes the method on the provided object instance.
  17. * This does not respect polymorphism and will invoke the exact method
  18. * of the class this object was retrieved from. Use "invokeVirtual" if you
  19. * need polymorphism.
  20. *
  21. * @param instance Instance of the object to invoke the method on. Can be null for static methods.
  22. * @param param Array of parameters to pass to the method. Caller must ensure they match method
  23. * parameter count and type. For value types parameters should be pointers to the
  24. * values and for reference types they should be pointers to MonoObject.
  25. *
  26. @returns A boxed return value, or null if method has no return value.
  27. */
  28. MonoObject* invoke(MonoObject* instance, void** params);
  29. /**
  30. * @brief Invokes the method on the provided object instance. If the instance has an override of this
  31. * method it will be called.
  32. *
  33. * @param instance Instance of the object to invoke the method on.
  34. * @param param Array of parameters to pass to the method. Caller must ensure they match method
  35. * parameter count and type. For value types parameters should be pointers to the
  36. * values and for reference types they should be pointers to MonoObject.
  37. *
  38. * @returns A boxed return value, or null if method has no return value.
  39. */
  40. MonoObject* invokeVirtual(MonoObject* instance, void** params);
  41. /**
  42. * @brief Gets a thunk for this method. A thunk is a C++ like function
  43. * pointer that you can use for calling the method.
  44. *
  45. * @note This is the fastest way of calling managed code.
  46. */
  47. void* getThunk() const;
  48. /**
  49. * @brief Returns the name of the method.
  50. */
  51. String getName() const;
  52. /**
  53. * @brief Returns the type of the return value. Returns null if method
  54. * has no return value.
  55. */
  56. MonoClass* getReturnType() const;
  57. /**
  58. * @brief Returns the number of parameters the method expects.
  59. */
  60. UINT32 getNumParameters() const;
  61. /**
  62. * @brief Returns the type of the method parameter at the specified index.
  63. */
  64. MonoClass* getParameterType(UINT32 paramIdx) const;
  65. /**
  66. * @brief Returns true if the method doesn't require a class instance.
  67. */
  68. bool isStatic() const;
  69. /**
  70. * @brief Checks if method has an attribute of the specified type.
  71. */
  72. bool hasAttribute(MonoClass* monoClass) const;
  73. /**
  74. * @brief Returns an instance of an attribute of the specified type. Returns null
  75. * if the method doesn't have such an attribute.
  76. */
  77. MonoObject* getAttribute(MonoClass* monoClass) const;
  78. private:
  79. friend class MonoClass;
  80. friend class MonoProperty;
  81. MonoMethod(::MonoMethod* method);
  82. void cacheSignature() const;
  83. ::MonoMethod* mMethod;
  84. mutable MonoClass* mCachedReturnType;
  85. mutable MonoClass** mCachedParameters;
  86. mutable UINT32 mCachedNumParameters;
  87. mutable bool mIsStatic;
  88. mutable bool mHasCachedSignature;
  89. };
  90. }