Replace exceptions with null checks to avoid event errors.

This commit is contained in:
2025-11-04 06:59:22 +01:00
parent 21b9cdc77c
commit ea125c7c8f
2 changed files with 12 additions and 23 deletions

View File

@@ -31,14 +31,9 @@ namespace SerializableFunc.Runtime
private Action GetAction()
{
if (targetObject == null || string.IsNullOrWhiteSpace(methodName)) return null;
if (cachedAction == null)
{
if (targetObject == null)
throw new ArgumentNullException(nameof(targetObject), "Target Object is null!");
if (string.IsNullOrWhiteSpace(methodName))
throw new ArgumentNullException(nameof(methodName), "Target Method is null!");
MethodInfo info = targetObject
.GetType()
.GetMethods(SuitableMethodsFlags)
@@ -46,7 +41,9 @@ namespace SerializableFunc.Runtime
if (info == null)
{
throw new MissingMethodException($"Object \"{targetObject.name}\" is missing target void method: {methodName}");
throw new MissingMethodException(
$"Object \"{targetObject.name}\" is missing target void method: {methodName}"
);
}
cachedAction = (Action)Delegate.CreateDelegate(typeof(Action), targetObject, methodName);