42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using System;
|
|
using System.Linq;
|
|
using ModestTree;
|
|
|
|
namespace Zenject
|
|
{
|
|
[NoReflectionBaking]
|
|
public class ConditionCopyNonLazyBinder : CopyNonLazyBinder
|
|
{
|
|
public ConditionCopyNonLazyBinder(BindInfo bindInfo)
|
|
: base(bindInfo)
|
|
{
|
|
}
|
|
|
|
public CopyNonLazyBinder When(BindingCondition condition)
|
|
{
|
|
BindInfo.Condition = condition;
|
|
return this;
|
|
}
|
|
|
|
public CopyNonLazyBinder WhenInjectedIntoInstance(object instance)
|
|
{
|
|
return When(r => ReferenceEquals(r.ObjectInstance, instance));
|
|
}
|
|
|
|
public CopyNonLazyBinder WhenInjectedInto(params Type[] targets)
|
|
{
|
|
return When(r => targets.Where(x => r.ObjectType != null && r.ObjectType.DerivesFromOrEqual(x)).Any());
|
|
}
|
|
|
|
public CopyNonLazyBinder WhenInjectedInto<T>()
|
|
{
|
|
return When(r => r.ObjectType != null && r.ObjectType.DerivesFromOrEqual(typeof(T)));
|
|
}
|
|
|
|
public CopyNonLazyBinder WhenNotInjectedInto<T>()
|
|
{
|
|
return When(r => r.ObjectType == null || !r.ObjectType.DerivesFromOrEqual(typeof(T)));
|
|
}
|
|
}
|
|
}
|