From e266fa8b32d928d1bdcb4f81f7a0ff489b460835 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Wed, 20 Jul 2016 18:04:18 -0400 Subject: [PATCH] Cleaned up bugs in DependencyMap and ReflectionUtils --- src/Discord.Net.Commands/Dependencies/DependencyMap.cs | 5 +++++ src/Discord.Net.Commands/ReflectionUtils.cs | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Discord.Net.Commands/Dependencies/DependencyMap.cs b/src/Discord.Net.Commands/Dependencies/DependencyMap.cs index 20d9a60c5..4495a906b 100644 --- a/src/Discord.Net.Commands/Dependencies/DependencyMap.cs +++ b/src/Discord.Net.Commands/Dependencies/DependencyMap.cs @@ -8,6 +8,11 @@ namespace Discord.Commands { private Dictionary map; + public DependencyMap() + { + map = new Dictionary(); + } + public T Get() where T : class { var t = typeof(T); diff --git a/src/Discord.Net.Commands/ReflectionUtils.cs b/src/Discord.Net.Commands/ReflectionUtils.cs index 98f1989be..d1eeccb4c 100644 --- a/src/Discord.Net.Commands/ReflectionUtils.cs +++ b/src/Discord.Net.Commands/ReflectionUtils.cs @@ -16,23 +16,23 @@ namespace Discord.Commands if (constructor.GetParameters().Length == 0) return constructor.Invoke(null); else if (constructor.GetParameters().Length > 1) - throw new InvalidOperationException($"Could not find a valid constructor for \"{typeInfo.FullName}\""); + throw new InvalidOperationException($"Could not find a valid constructor for \"{typeInfo.FullName}\" (Found too many parameters)"); var parameter = constructor.GetParameters().FirstOrDefault(); if (parameter == null) - throw new InvalidOperationException($"Could not find a valid constructor for \"{typeInfo.FullName}\""); - if (parameter.GetType() == typeof(CommandService)) + throw new InvalidOperationException($"Could not find a valid constructor for \"{typeInfo.FullName}\" (No valid parameters)"); + if (parameter.ParameterType == typeof(CommandService)) return constructor.Invoke(new object[1] { commands }); - else if (parameter is IDependencyMap) + else if (parameter.ParameterType == typeof(IDependencyMap)) { if (map == null) throw new InvalidOperationException($"The constructor for \"{typeInfo.FullName}\" requires a Dependency Map."); return constructor.Invoke(new object[1] { map }); } else - throw new InvalidOperationException($"Could not find a valid constructor for \"{typeInfo.FullName}\""); + throw new InvalidOperationException($"Could not find a valid constructor for \"{typeInfo.FullName}\" (Invalid Parameter Type: \"{parameter.ParameterType.FullName}\")"); } - catch + catch (Exception e) { - throw new InvalidOperationException($"Could not find a valid constructor for \"{typeInfo.FullName}\""); + throw new InvalidOperationException($"Could not find a valid constructor for \"{typeInfo.FullName}\" (Error invoking constructor)"); } } }