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 dc7f008
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions Exiled.API/Features/Core/Generic/EBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ protected virtual void FindOwner()
// 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 dc7f008

Please sign in to comment.