BsMonoMethod.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. /** @addtogroup Mono
  9. * @{
  10. */
  11. /**
  12. * Encapsulates information about a single Mono (managed) method belonging to some managed class. This object also
  13. * allows you to invoke the method.
  14. */
  15. class BS_MONO_EXPORT MonoMethod
  16. {
  17. public:
  18. ~MonoMethod();
  19. /**
  20. * Invokes the method on the provided object instance. This does not respect polymorphism and will invoke the exact
  21. * method of the class this object was retrieved from. Use invokeVirtual() if you need polymorphism.
  22. *
  23. * @param[in] instance Instance of the object to invoke the method on. Can be null for static methods.
  24. * @param[in] 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. * @return A boxed return value, or null if method has no return value.
  28. */
  29. MonoObject* invoke(MonoObject* instance, void** params);
  30. /**
  31. * Invokes the method on the provided object instance. If the instance has an override of this method it will be
  32. * called.
  33. *
  34. * @param[in] instance Instance of the object to invoke the method on.
  35. * @param[in] param Array of parameters to pass to the method. Caller must ensure they match method
  36. * parameter count and type. For value types parameters should be pointers to the
  37. * values and for reference types they should be pointers to MonoObject.
  38. * @return A boxed return value, or null if method has no return value.
  39. */
  40. MonoObject* invokeVirtual(MonoObject* instance, void** params);
  41. /**
  42. * Gets a thunk for this method. A thunk is a C++ like function 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. /** Returns the name of the method. */
  48. String getName() const;
  49. /** Returns the type of the return value. Returns null if method has no return value. */
  50. MonoClass* getReturnType() const;
  51. /** Returns the number of parameters the method expects. */
  52. UINT32 getNumParameters() const;
  53. /** Returns the type of the method parameter at the specified index. */
  54. MonoClass* getParameterType(UINT32 paramIdx) const;
  55. /** Returns true if the method doesn't require a class instance. */
  56. bool isStatic() const;
  57. /** Checks if method has an attribute of the specified type. */
  58. bool hasAttribute(MonoClass* monoClass) const;
  59. /**
  60. * Returns an instance of an attribute of the specified type. Returns null if the method doesn't have such an
  61. * attribute.
  62. */
  63. MonoObject* getAttribute(MonoClass* monoClass) const;
  64. private:
  65. friend class MonoClass;
  66. friend class MonoProperty;
  67. MonoMethod(::MonoMethod* method);
  68. void cacheSignature() const;
  69. ::MonoMethod* mMethod;
  70. mutable MonoClass* mCachedReturnType;
  71. mutable MonoClass** mCachedParameters;
  72. mutable UINT32 mCachedNumParameters;
  73. mutable bool mIsStatic;
  74. mutable bool mHasCachedSignature;
  75. };
  76. /** @} */
  77. }