BsMonoMethod.h 3.4 KB

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