BsMonoAssembly.h 3.3 KB

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