BsMonoAssembly.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma once
  2. #include "BsMonoPrerequisites.h"
  3. #include <mono/jit/jit.h>
  4. #include <mono/metadata/assembly.h>
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Contains information about a single Mono (i.e. managed) assembly
  9. */
  10. class BS_MONO_EXPORT MonoAssembly
  11. {
  12. public:
  13. /**
  14. * @brief Used for uniquely identifying a managed class, normally for use
  15. * in containers.
  16. */
  17. struct ClassId
  18. {
  19. struct Hash
  20. {
  21. inline size_t operator()(const ClassId& v) const;
  22. };
  23. struct Equals
  24. {
  25. inline bool operator()(const ClassId &a, const ClassId &b) const;
  26. };
  27. ClassId();
  28. ClassId(const String& namespaceName, String name, ::MonoClass* genericInstance = nullptr);
  29. String namespaceName;
  30. String name;
  31. ::MonoClass* genericInstance;
  32. };
  33. public:
  34. virtual ~MonoAssembly();
  35. /**
  36. * @brief Returns the name of this assembly.
  37. */
  38. const String& getName() const { return mName; }
  39. /**
  40. * @brief Attempts to find a managed class with the specified namespace and name
  41. * in this assembly. Returns null if one cannot be found.
  42. */
  43. MonoClass* getClass(const String& namespaceName, const String& name) const;
  44. /**
  45. * @brief Converts an internal mono representation of a class into engine class.
  46. */
  47. MonoClass* getClass(::MonoClass* rawMonoClass) const;
  48. /**
  49. * @brief Returns a list of all classes in the assembly.
  50. */
  51. const Vector<MonoClass*>& getAllClasses() const;
  52. /**
  53. * @brief Invokes a zero-parameter static method in the format
  54. * "Class::Method". Used primarily for invoking an assembly entry point.
  55. */
  56. void invoke(const String& functionName);
  57. private:
  58. friend class MonoManager;
  59. MonoAssembly();
  60. /**
  61. * @brief Loads an assembly from the specified path.
  62. */
  63. void load(MonoDomain* domain, const String& path, const String& name);
  64. /**
  65. * @brief Loads an assembly from an internal mono image.
  66. *
  67. * @note Normally used for assemblies that were already loaded by the managed runtime
  68. * as dependencies.
  69. */
  70. void loadFromImage(MonoImage* image, const String& name);
  71. /**
  72. * @brief Unloads the assembly and all the types associated with it.
  73. * Caller must ensure not to use any types from this assembly after
  74. * it has been unloaded.
  75. */
  76. void unload();
  77. /**
  78. * @brief Returns true if the provided name represents a generic class.
  79. *
  80. * @note This method only analyzes the name to determine if it is in generic class format.
  81. */
  82. bool isGenericClass(const String& name) const;
  83. String mName;
  84. MonoImage* mMonoImage;
  85. ::MonoAssembly* mMonoAssembly;
  86. bool mIsLoaded;
  87. bool mIsDependency;
  88. mutable UnorderedMap<ClassId, MonoClass*, ClassId::Hash, ClassId::Equals> mClasses;
  89. mutable UnorderedMap<::MonoClass*, MonoClass*> mClassesByRaw;
  90. mutable bool mHaveCachedClassList;
  91. mutable Vector<MonoClass*> mCachedClassList;
  92. };
  93. }