Replace exceptions with null checks to avoid event errors.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user