Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit dc7f008

Browse files
committed
Add check returning type for 'get'reflection call in EBehaviour
1 parent 1e9555c commit dc7f008

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

Exiled.API/Features/Core/Generic/EBehaviour.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,13 @@ protected virtual void FindOwner()
6363
// Or create an specific Interaface requesting to implement this method
6464
MethodInfo method = typeof(T).GetMethod("Get", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(GameObject) }, null);
6565

66-
if (method != null)
67-
{
68-
Owner = (T)method.Invoke(null, new object[] { Base });
69-
}
70-
else
71-
{
66+
if (method == null)
7267
throw new MissingMethodException($"Method 'Get(GameObject)' not found in class '{typeof(T).Name}'.");
73-
}
68+
69+
if (typeof(T).IsAssignableFrom(method.ReturnType))
70+
throw new MissingMethodException($"Method 'Get(GameObject)' in class '{typeof(T).Name}' do not return an instance of {typeof(T).Name} but {method.ReturnType}.");
71+
72+
Owner = (T)method.Invoke(null, new object[] { Base });
7473
}
7574

7675
/// <inheritdoc/>

0 commit comments

Comments
 (0)