From 2a7a051f1fdb605ad573290c7a94b279d8d23188 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 22 Oct 2020 12:17:37 -0400 Subject: [PATCH] chore: Added validation and [NotNull] attributes to ReflectionUtils --- ICD.Common.Utils/ReflectionUtils.cs | 38 +++++++++++++++++------------ 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/ICD.Common.Utils/ReflectionUtils.cs b/ICD.Common.Utils/ReflectionUtils.cs index be25099..af806d5 100644 --- a/ICD.Common.Utils/ReflectionUtils.cs +++ b/ICD.Common.Utils/ReflectionUtils.cs @@ -26,7 +26,7 @@ namespace ICD.Common.Utils /// /// /// - public static bool MatchesConstructorParameters(ConstructorInfo constructor, IEnumerable parameters) + public static bool MatchesConstructorParameters([NotNull] ConstructorInfo constructor, [NotNull] IEnumerable parameters) { if (constructor == null) throw new ArgumentNullException("constructor"); @@ -43,7 +43,7 @@ namespace ICD.Common.Utils /// /// /// - public static bool MatchesMethodParameters(MethodBase method, IEnumerable parameters) + public static bool MatchesMethodParameters([NotNull] MethodBase method, [NotNull] IEnumerable parameters) { if (method == null) throw new ArgumentNullException("method"); @@ -69,7 +69,7 @@ namespace ICD.Common.Utils /// /// /// - public static bool MatchesPropertyParameter(PropertyInfo property, object parameter) + public static bool MatchesPropertyParameter([NotNull] PropertyInfo property, object parameter) { if (property == null) throw new ArgumentNullException("property"); @@ -83,7 +83,7 @@ namespace ICD.Common.Utils /// /// /// - private static bool ParametersMatchTypes(IEnumerable types, IEnumerable parameters) + private static bool ParametersMatchTypes([NotNull] IEnumerable types, [NotNull] IEnumerable parameters) { if (types == null) throw new ArgumentNullException("types"); @@ -104,7 +104,7 @@ namespace ICD.Common.Utils /// /// /// - private static bool ParameterMatchesType(Type type, object parameter) + private static bool ParameterMatchesType([NotNull] Type type, object parameter) { if (type == null) throw new ArgumentNullException("type"); @@ -129,7 +129,7 @@ namespace ICD.Common.Utils /// /// [CanBeNull] - public static object GetDefaultValue(Type type) + public static object GetDefaultValue([NotNull] Type type) { if (type == null) throw new ArgumentNullException("type"); @@ -151,8 +151,14 @@ namespace ICD.Common.Utils /// /// [NotNull] - public static Delegate CreateDelegate(Type type, object firstArgument, MethodInfo method) + public static Delegate CreateDelegate([NotNull] Type type, object firstArgument, [NotNull] MethodInfo method) { + if (type == null) + throw new ArgumentNullException("type"); + + if (method == null) + throw new ArgumentNullException("method"); + return #if SIMPLSHARP CDelegate @@ -167,7 +173,7 @@ namespace ICD.Common.Utils /// /// [NotNull] - public static T CreateInstance(Type type) + public static T CreateInstance([NotNull] Type type) { if (type == null) throw new ArgumentNullException("type"); @@ -194,7 +200,7 @@ namespace ICD.Common.Utils /// /// [NotNull] - public static object CreateInstance(Type type, params object[] parameters) + public static object CreateInstance([NotNull] Type type, params object[] parameters) { if (type == null) throw new ArgumentNullException("type"); @@ -230,7 +236,7 @@ namespace ICD.Common.Utils /// /// [NotNull] - public static ConstructorInfo GetConstructor(Type type, params object[] parameters) + public static ConstructorInfo GetConstructor([NotNull] Type type, params object[] parameters) { if (type == null) throw new ArgumentNullException("type"); @@ -258,7 +264,7 @@ namespace ICD.Common.Utils /// /// [NotNull] - public static Assembly LoadAssemblyFromPath(string path) + public static Assembly LoadAssemblyFromPath([NotNull] string path) { if (path == null) throw new ArgumentNullException("path"); @@ -299,7 +305,7 @@ namespace ICD.Common.Utils /// /// [CanBeNull] - public static object ChangeType(object value, Type type) + public static object ChangeType(object value, [NotNull] Type type) { if (type == null) throw new ArgumentNullException("type"); @@ -348,7 +354,7 @@ namespace ICD.Common.Utils /// The EventHandler for the callback. /// [NotNull] - public static Delegate SubscribeEvent(object instance, EventInfo eventInfo, Action eventHandler) + public static Delegate SubscribeEvent(object instance, [NotNull] EventInfo eventInfo, [NotNull] Action eventHandler) { if (eventInfo == null) throw new ArgumentNullException("eventInfo"); @@ -372,7 +378,7 @@ namespace ICD.Common.Utils /// The EventHandler for the callback. /// [NotNull] - public static Delegate SubscribeEvent(object instance, EventInfo eventInfo, Action eventHandler) + public static Delegate SubscribeEvent(object instance, [NotNull] EventInfo eventInfo, [NotNull] Action eventHandler) { if (eventInfo == null) throw new ArgumentNullException("eventInfo"); @@ -397,7 +403,7 @@ namespace ICD.Common.Utils /// The MethodInfo for the eventHandler method. /// [NotNull] - public static Delegate SubscribeEvent(object instance, EventInfo eventInfo, object handler, MethodInfo callback) + public static Delegate SubscribeEvent(object instance, [NotNull] EventInfo eventInfo, object handler, [NotNull] MethodInfo callback) { if (eventInfo == null) throw new ArgumentNullException("eventInfo"); @@ -416,7 +422,7 @@ namespace ICD.Common.Utils /// The instance with the event. Null for static types. /// The EventInfo for the event. /// The Delegate to be removed from the event. - public static void UnsubscribeEvent(object instance, EventInfo eventInfo, Delegate callback) + public static void UnsubscribeEvent(object instance, [NotNull] EventInfo eventInfo, [NotNull] Delegate callback) { if (eventInfo == null) throw new ArgumentNullException("eventInfo");