using System; using System.Collections.Generic; using ModestTree; namespace Zenject { // Zero params [NoReflectionBaking] public class MethodProviderWithContainer : IProvider { readonly Func _method; public MethodProviderWithContainer(Func method) { _method = method; } public bool IsCached { get { return false; } } public bool TypeVariesBasedOnMemberType { get { return false; } } public Type GetInstanceType(InjectContext context) { return typeof(TValue); } public void GetAllInstancesWithInjectSplit( InjectContext context, List args, out Action injectAction, List buffer) { Assert.IsEmpty(args); Assert.IsNotNull(context); Assert.That(typeof(TValue).DerivesFromOrEqual(context.MemberType)); injectAction = null; if (context.Container.IsValidating) { // Don't do anything when validating, we can't make any assumptions on the given method buffer.Add(new ValidationMarker(typeof(TValue))); } else { buffer.Add(_method(context.Container)); } } } // One params [NoReflectionBaking] public class MethodProviderWithContainer : IProvider { readonly Func _method; public MethodProviderWithContainer(Func method) { _method = method; } public bool IsCached { get { return false; } } public bool TypeVariesBasedOnMemberType { get { return false; } } public Type GetInstanceType(InjectContext context) { return typeof(TValue); } public void GetAllInstancesWithInjectSplit( InjectContext context, List args, out Action injectAction, List buffer) { Assert.IsEqual(args.Count, 1); Assert.IsNotNull(context); Assert.That(typeof(TValue).DerivesFromOrEqual(context.MemberType)); Assert.That(args[0].Type.DerivesFromOrEqual(typeof(TParam1))); injectAction = null; if (context.Container.IsValidating) { // Don't do anything when validating, we can't make any assumptions on the given method buffer.Add(new ValidationMarker(typeof(TValue))); } else { buffer.Add( _method( context.Container, (TParam1)args[0].Value)); } } } // Two params [NoReflectionBaking] public class MethodProviderWithContainer : IProvider { readonly Func _method; public MethodProviderWithContainer(Func method) { _method = method; } public bool IsCached { get { return false; } } public bool TypeVariesBasedOnMemberType { get { return false; } } public Type GetInstanceType(InjectContext context) { return typeof(TValue); } public void GetAllInstancesWithInjectSplit( InjectContext context, List args, out Action injectAction, List buffer) { Assert.IsEqual(args.Count, 2); Assert.IsNotNull(context); Assert.That(typeof(TValue).DerivesFromOrEqual(context.MemberType)); Assert.That(args[0].Type.DerivesFromOrEqual(typeof(TParam1))); Assert.That(args[1].Type.DerivesFromOrEqual(typeof(TParam2))); injectAction = null; if (context.Container.IsValidating) { // Don't do anything when validating, we can't make any assumptions on the given method buffer.Add(new ValidationMarker(typeof(TValue))); } else { buffer.Add( _method( context.Container, (TParam1)args[0].Value, (TParam2)args[1].Value)); } } } // Three params [NoReflectionBaking] public class MethodProviderWithContainer : IProvider { readonly Func _method; public MethodProviderWithContainer(Func method) { _method = method; } public bool IsCached { get { return false; } } public bool TypeVariesBasedOnMemberType { get { return false; } } public Type GetInstanceType(InjectContext context) { return typeof(TValue); } public void GetAllInstancesWithInjectSplit( InjectContext context, List args, out Action injectAction, List buffer) { Assert.IsEqual(args.Count, 3); Assert.IsNotNull(context); Assert.That(typeof(TValue).DerivesFromOrEqual(context.MemberType)); Assert.That(args[0].Type.DerivesFromOrEqual(typeof(TParam1))); Assert.That(args[1].Type.DerivesFromOrEqual(typeof(TParam2))); Assert.That(args[2].Type.DerivesFromOrEqual(typeof(TParam3))); injectAction = null; if (context.Container.IsValidating) { // Don't do anything when validating, we can't make any assumptions on the given method buffer.Add(new ValidationMarker(typeof(TValue))); } else { buffer.Add( _method( context.Container, (TParam1)args[0].Value, (TParam2)args[1].Value, (TParam3)args[2].Value)); } } } // Four params [NoReflectionBaking] public class MethodProviderWithContainer : IProvider { readonly #if !NET_4_6 ModestTree.Util. #endif Func _method; public MethodProviderWithContainer( #if !NET_4_6 ModestTree.Util. #endif Func method) { _method = method; } public bool IsCached { get { return false; } } public bool TypeVariesBasedOnMemberType { get { return false; } } public Type GetInstanceType(InjectContext context) { return typeof(TValue); } public void GetAllInstancesWithInjectSplit( InjectContext context, List args, out Action injectAction, List buffer) { Assert.IsEqual(args.Count, 4); Assert.IsNotNull(context); Assert.That(typeof(TValue).DerivesFromOrEqual(context.MemberType)); Assert.That(args[0].Type.DerivesFromOrEqual(typeof(TParam1))); Assert.That(args[1].Type.DerivesFromOrEqual(typeof(TParam2))); Assert.That(args[2].Type.DerivesFromOrEqual(typeof(TParam3))); Assert.That(args[3].Type.DerivesFromOrEqual(typeof(TParam4))); injectAction = null; if (context.Container.IsValidating) { // Don't do anything when validating, we can't make any assumptions on the given method buffer.Add(new ValidationMarker(typeof(TValue))); } else { buffer.Add( _method( context.Container, (TParam1)args[0].Value, (TParam2)args[1].Value, (TParam3)args[2].Value, (TParam4)args[3].Value)); } } } // Five params [NoReflectionBaking] public class MethodProviderWithContainer : IProvider { readonly #if !NET_4_6 ModestTree.Util. #endif Func _method; public MethodProviderWithContainer( #if !NET_4_6 ModestTree.Util. #endif Func method) { _method = method; } public bool IsCached { get { return false; } } public bool TypeVariesBasedOnMemberType { get { return false; } } public Type GetInstanceType(InjectContext context) { return typeof(TValue); } public void GetAllInstancesWithInjectSplit( InjectContext context, List args, out Action injectAction, List buffer) { Assert.IsEqual(args.Count, 5); Assert.IsNotNull(context); Assert.That(typeof(TValue).DerivesFromOrEqual(context.MemberType)); Assert.That(args[0].Type.DerivesFromOrEqual(typeof(TParam1))); Assert.That(args[1].Type.DerivesFromOrEqual(typeof(TParam2))); Assert.That(args[2].Type.DerivesFromOrEqual(typeof(TParam3))); Assert.That(args[3].Type.DerivesFromOrEqual(typeof(TParam4))); Assert.That(args[4].Type.DerivesFromOrEqual(typeof(TParam5))); injectAction = null; if (context.Container.IsValidating) { // Don't do anything when validating, we can't make any assumptions on the given method buffer.Add(new ValidationMarker(typeof(TValue))); } else { buffer.Add( _method( context.Container, (TParam1)args[0].Value, (TParam2)args[1].Value, (TParam3)args[2].Value, (TParam4)args[3].Value, (TParam5)args[4].Value)); } } } // Six params [NoReflectionBaking] public class MethodProviderWithContainer : IProvider { readonly #if !NET_4_6 ModestTree.Util. #endif Func _method; public MethodProviderWithContainer( #if !NET_4_6 ModestTree.Util. #endif Func method) { _method = method; } public bool IsCached { get { return false; } } public bool TypeVariesBasedOnMemberType { get { return false; } } public Type GetInstanceType(InjectContext context) { return typeof(TValue); } public void GetAllInstancesWithInjectSplit( InjectContext context, List args, out Action injectAction, List buffer) { Assert.IsEqual(args.Count, 5); Assert.IsNotNull(context); Assert.That(typeof(TValue).DerivesFromOrEqual(context.MemberType)); Assert.That(args[0].Type.DerivesFromOrEqual(typeof(TParam1))); Assert.That(args[1].Type.DerivesFromOrEqual(typeof(TParam2))); Assert.That(args[2].Type.DerivesFromOrEqual(typeof(TParam3))); Assert.That(args[3].Type.DerivesFromOrEqual(typeof(TParam4))); Assert.That(args[4].Type.DerivesFromOrEqual(typeof(TParam5))); Assert.That(args[5].Type.DerivesFromOrEqual(typeof(TParam6))); injectAction = null; if (context.Container.IsValidating) { // Don't do anything when validating, we can't make any assumptions on the given method buffer.Add(new ValidationMarker(typeof(TValue))); } else { buffer.Add( _method( context.Container, (TParam1)args[0].Value, (TParam2)args[1].Value, (TParam3)args[2].Value, (TParam4)args[3].Value, (TParam5)args[4].Value, (TParam6)args[5].Value)); } } } // Ten params [NoReflectionBaking] public class MethodProviderWithContainer : IProvider { readonly #if !NET_4_6 ModestTree.Util. #endif Func _method; public MethodProviderWithContainer( #if !NET_4_6 ModestTree.Util. #endif Func method) { _method = method; } public bool IsCached { get { return false; } } public bool TypeVariesBasedOnMemberType { get { return false; } } public Type GetInstanceType(InjectContext context) { return typeof(TValue); } public void GetAllInstancesWithInjectSplit( InjectContext context, List args, out Action injectAction, List buffer) { Assert.IsEqual(args.Count, 10); Assert.IsNotNull(context); Assert.That(typeof(TValue).DerivesFromOrEqual(context.MemberType)); Assert.That(args[0].Type.DerivesFromOrEqual(typeof(TParam1))); Assert.That(args[1].Type.DerivesFromOrEqual(typeof(TParam2))); Assert.That(args[2].Type.DerivesFromOrEqual(typeof(TParam3))); Assert.That(args[3].Type.DerivesFromOrEqual(typeof(TParam4))); Assert.That(args[4].Type.DerivesFromOrEqual(typeof(TParam5))); Assert.That(args[5].Type.DerivesFromOrEqual(typeof(TParam6))); Assert.That(args[6].Type.DerivesFromOrEqual(typeof(TParam7))); Assert.That(args[7].Type.DerivesFromOrEqual(typeof(TParam8))); Assert.That(args[8].Type.DerivesFromOrEqual(typeof(TParam9))); Assert.That(args[9].Type.DerivesFromOrEqual(typeof(TParam10))); injectAction = null; if (context.Container.IsValidating) { // Don't do anything when validating, we can't make any assumptions on the given method buffer.Add(new ValidationMarker(typeof(TValue))); } else { buffer.Add( _method( context.Container, (TParam1)args[0].Value, (TParam2)args[1].Value, (TParam3)args[2].Value, (TParam4)args[3].Value, (TParam5)args[4].Value, (TParam6)args[5].Value, (TParam7)args[6].Value, (TParam8)args[7].Value, (TParam9)args[8].Value, (TParam10)args[9].Value)); } } } }