Add more objects types checks and casting utilities to ScriptingObject
This commit is contained in:
@@ -131,12 +131,30 @@ public:
|
||||
return obj ? obj->GetOrCreateManagedInstance() : nullptr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if can cast one scripting object type into another type.
|
||||
/// </summary>
|
||||
/// <param name="from">The object type for the cast.</param>
|
||||
/// <param name="to">The destination type to the cast.</param>
|
||||
/// <returns>True if can, otherwise false.</returns>
|
||||
static bool CanCast(const ScriptingTypeHandle& from, const ScriptingTypeHandle& to);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if can cast one scripting object type into another type.
|
||||
/// </summary>
|
||||
/// <param name="from">The object class for the cast.</param>
|
||||
/// <param name="to">The destination class to the cast.</param>
|
||||
/// <returns>True if can, otherwise false.</returns>
|
||||
static bool CanCast(MClass* from, MClass* to);
|
||||
|
||||
template<typename T>
|
||||
static T* Cast(ScriptingObject* obj)
|
||||
{
|
||||
return obj && CanCast(obj->GetClass(), T::GetStaticClass()) ? (T*)obj : nullptr;
|
||||
}
|
||||
|
||||
bool Is(const ScriptingTypeHandle& type) const;
|
||||
|
||||
bool Is(MClass* type) const
|
||||
{
|
||||
return CanCast(GetClass(), type);
|
||||
@@ -185,10 +203,6 @@ public:
|
||||
/// </summary>
|
||||
void UnregisterObject();
|
||||
|
||||
private:
|
||||
|
||||
static bool CanCast(MClass* from, MClass* to);
|
||||
|
||||
protected:
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user