From 123c4d1b0666b6d68fda3f39c03c71fd2414a5bd Mon Sep 17 00:00:00 2001 From: Simon G Date: Fri, 14 Apr 2023 00:42:18 +0200 Subject: [PATCH] - eliminate another try-catch --- LightweightIocContainer/IocContainer.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/LightweightIocContainer/IocContainer.cs b/LightweightIocContainer/IocContainer.cs index 10a7712..09ae1e3 100644 --- a/LightweightIocContainer/IocContainer.cs +++ b/LightweightIocContainer/IocContainer.cs @@ -227,7 +227,14 @@ public class IocContainer : IIocContainer, IIocResolver /// Getting resolve stack failed without exception internal (bool success, object resolvedObject, Exception? exception) TryResolveNonGeneric(Type type, object?[]? arguments, List? resolveStack, bool isFactoryResolve = false) { - object? resolvedValue = GenericMethodCaller.CallPrivate(this, nameof(TryResolve), type, arguments, resolveStack, isFactoryResolve); + MethodInfo? method = typeof(IocContainer).GetMethod(nameof(TryResolve), BindingFlags.NonPublic | BindingFlags.Instance); + MethodInfo? genericMethod = method?.MakeGenericMethod(type); + + if (genericMethod == null) + throw new GenericMethodNotFoundException(nameof(TryResolve)); + + object? resolvedValue = genericMethod.Invoke(this, new object?[]{arguments, resolveStack, isFactoryResolve}); + if (resolvedValue is not ValueTuple resolvedTuple) throw new Exception("Invalid return value!");