From 65a234062a64834a4ec019bae4e4e6df9a772ee5 Mon Sep 17 00:00:00 2001 From: Eugene Sadovoi Date: Sun, 17 Mar 2019 13:22:54 -0400 Subject: [PATCH] More overrides --- src/Extensions/Injection/Override.cs | 49 +++++++++++++++++++--------- src/Extensions/Injection/Resolve.cs | 5 +++ 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/Extensions/Injection/Override.cs b/src/Extensions/Injection/Override.cs index e93b2057..54b6f29b 100644 --- a/src/Extensions/Injection/Override.cs +++ b/src/Extensions/Injection/Override.cs @@ -27,32 +27,41 @@ public static partial class Override #if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static ResolverOverride Parameter(object value) - => new ParameterOverride(typeof(TType), value); + public static ResolverOverride Parameter(object value) + => new ParameterOverride(value?.GetType() ?? throw new ArgumentNullException(nameof(value)), value); + #if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static ResolverOverride Parameter(string name, object value) - => Parameter(typeof(TType), name, value); + public static ResolverOverride Parameter(string name, object value) + => new ParameterOverride(name, value); #if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static ResolverOverride Parameter(Type type, object value) + public static ResolverOverride Parameter(Type type, object value) => new ParameterOverride(type, value); + #if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static ResolverOverride Parameter(Type type, string name, object value) + public static ResolverOverride Parameter(Type type, string name, object value) => new ParameterOverride(type, name, value); + #if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static ResolverOverride Parameter(string name, object value) - => new ParameterOverride(name, value); + public static ResolverOverride Parameter(object value) + => new ParameterOverride(typeof(TType), value); + +#if !NET40 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#endif + public static ResolverOverride Parameter(string name, object value) + => Parameter(typeof(TType), name, value); #endregion @@ -62,14 +71,8 @@ public static ResolverOverride Parameter(string name, object value) #if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif - public static ResolverOverride Dependency(object value) - => new DependencyOverride(typeof(TType), value); - - #if !NET40 - [MethodImpl(MethodImplOptions.AggressiveInlining)] -#endif - public static ResolverOverride Dependency(string name, object value) - => new DependencyOverride(typeof(TType), name, value); + public static ResolverOverride Dependency(object value) + => Dependency(value?.GetType() ?? throw new ArgumentNullException(nameof(value)), null, value); #if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -77,6 +80,7 @@ public static ResolverOverride Dependency(string name, object value) public static ResolverOverride Dependency(string name, object value) => Dependency(value?.GetType() ?? throw new ArgumentNullException(nameof(value)), name, value); + #if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif @@ -93,6 +97,19 @@ public static ResolverOverride Dependency(Type type, string name, object value) return new DependencyOverride(type, name, value); } + +#if !NET40 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#endif + public static ResolverOverride Dependency(object value) + => new DependencyOverride(typeof(TType), value); + + #if !NET40 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#endif + public static ResolverOverride Dependency(string name, object value) + => new DependencyOverride(typeof(TType), name, value); + #endregion } } diff --git a/src/Extensions/Injection/Resolve.cs b/src/Extensions/Injection/Resolve.cs index 9b35a78b..6d834f5e 100644 --- a/src/Extensions/Injection/Resolve.cs +++ b/src/Extensions/Injection/Resolve.cs @@ -8,6 +8,11 @@ public static partial class Resolve { #region Dependency +#if !NET40 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#endif + public static ParameterBase Dependency() => new ResolvedParameter(typeof(TTarget), null); + #if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif