BsMonoMethod.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsMonoPrerequisites.h"
  5. #include <mono/jit/jit.h>
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Encapsulates information about a single Mono (i.e. managed) method
  10. * belonging to some managed class. This object also allows you to invoke
  11. * the method.
  12. */
  13. class BS_MONO_EXPORT MonoMethod
  14. {
  15. public:
  16. ~MonoMethod();
  17. /**
  18. * @brief Invokes the method on the provided object instance.
  19. * This does not respect polymorphism and will invoke the exact method
  20. * of the class this object was retrieved from. Use "invokeVirtual" if you
  21. * need polymorphism.
  22. *
  23. * @param instance Instance of the object to invoke the method on. Can be null for static methods.
  24. * @param param Array of parameters to pass to the method. Caller must ensure they match method
  25. * parameter count and type. For value types parameters should be pointers to the
  26. * values and for reference types they should be pointers to MonoObject.
  27. *
  28. @returns A boxed return value, or null if method has no return value.
  29. */
  30. MonoObject* invoke(MonoObject* instance, void** params);
  31. /**
  32. * @brief Invokes the method on the provided object instance. If the instance has an override of this
  33. * method it will be called.
  34. *
  35. * @param instance Instance of the object to invoke the method on.
  36. * @param param Array of parameters to pass to the method. Caller must ensure they match method
  37. * parameter count and type. For value types parameters should be pointers to the
  38. * values and for reference types they should be pointers to MonoObject.
  39. *
  40. * @returns A boxed return value, or null if method has no return value.
  41. */
  42. MonoObject* invokeVirtual(MonoObject* instance, void** params);
  43. /**
  44. * @brief Gets a thunk for this method. A thunk is a C++ like function
  45. * pointer that you can use for calling the method.
  46. *
  47. * @note This is the fastest way of calling managed code.
  48. */
  49. void* getThunk() const;
  50. /**
  51. * @brief Returns the name of the method.
  52. */
  53. String getName() const;
  54. /**
  55. * @brief Returns the type of the return value. Returns null if method
  56. * has no return value.
  57. */
  58. MonoClass* getReturnType() const;
  59. /**
  60. * @brief Returns the number of parameters the method expects.
  61. */
  62. UINT32 getNumParameters() const;
  63. /**
  64. * @brief Returns the type of the method parameter at the specified index.
  65. */
  66. MonoClass* getParameterType(UINT32 paramIdx) const;
  67. /**
  68. * @brief Returns true if the method doesn't require a class instance.
  69. */
  70. bool isStatic() const;
  71. /**
  72. * @brief Checks if method has an attribute of the specified type.
  73. */
  74. bool hasAttribute(MonoClass* monoClass) const;
  75. /**
  76. * @brief Returns an instance of an attribute of the specified type. Returns null
  77. * if the method doesn't have such an attribute.
  78. */
  79. MonoObject* getAttribute(MonoClass* monoClass) const;
  80. private:
  81. friend class MonoClass;
  82. friend class MonoProperty;
  83. MonoMethod(::MonoMethod* method);
  84. void cacheSignature() const;
  85. ::MonoMethod* mMethod;
  86. mutable MonoClass* mCachedReturnType;
  87. mutable MonoClass** mCachedParameters;
  88. mutable UINT32 mCachedNumParameters;
  89. mutable bool mIsStatic;
  90. mutable bool mHasCachedSignature;
  91. };
  92. }