mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-12 03:57:32 +00:00
feat: Adding CallMethod reflection extensions
This commit is contained in:
parent
80b1412632
commit
9882febede
1 changed files with 35 additions and 0 deletions
|
|
@ -195,6 +195,41 @@ namespace ICD.Common.Utils.Extensions
|
||||||
value = currentObject;
|
value = currentObject;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool CallMethod([NotNull] this object extends, string methodName)
|
||||||
|
{
|
||||||
|
object value;
|
||||||
|
return CallMethod(extends, methodName, out value, new object[] { });
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool CallMethod([NotNull] this object extends, string methodName, [CanBeNull] out object value)
|
||||||
|
{
|
||||||
|
return CallMethod(extends, methodName, out value, new object[] { });
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool CallMethod([NotNull] this object extends, string methodName, [NotNull] params object[] parameters)
|
||||||
|
{
|
||||||
|
object value;
|
||||||
|
return CallMethod(extends, methodName, out value, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool CallMethod([NotNull] this object extends, string methodName, [CanBeNull] out object value, [NotNull] params object[] parameters)
|
||||||
|
{
|
||||||
|
if (extends == null)
|
||||||
|
throw new ArgumentNullException(nameof(extends));
|
||||||
|
if (parameters == null)
|
||||||
|
throw new ArgumentNullException(nameof(parameters));
|
||||||
|
|
||||||
|
value = false;
|
||||||
|
|
||||||
|
MethodInfo method = extends.GetType().GetMethod(methodName);
|
||||||
|
if (method == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
value = method.Invoke(extends, parameters);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue