Skip to content

Commit

Permalink
Add check returning type for 'get'reflection call in EBehaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
warquys committed Sep 14, 2024
1 parent 1e9555c commit 9e3ef36
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions Exiled.API/Features/Core/Generic/EBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,15 @@ protected EBehaviour()
/// </remarks>
protected virtual void FindOwner()
{
// @Nao T is a GameEntity, why not add in inisde of it the method a abstract.
// Or create an specific Interaface requesting to implement this method
MethodInfo method = typeof(T).GetMethod("Get", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(GameObject) }, null);

if (method != null)
{
Owner = (T)method.Invoke(null, new object[] { Base });
}
else
{
if (method == null)
throw new MissingMethodException($"Method 'Get(GameObject)' not found in class '{typeof(T).Name}'.");
}

if (typeof(T).IsAssignableFrom(method.ReturnType))
throw new MissingMethodException($"Method 'Get(GameObject)' in class '{typeof(T).Name}' do not return an instance of {typeof(T).Name} but {method.ReturnType}.");

Owner = (T)method.Invoke(null, new object[] { Base });
}

/// <inheritdoc/>
Expand Down

0 comments on commit 9e3ef36

Please sign in to comment.