public SpyExtension(IBuilderStrategy strategy, UnityBuildStage stage, IBuilderPolicy policy, Type policyType) { this.strategy = strategy; this.stage = stage; this.policy = policy; this.policyType = policyType; }
public void Set(Type policyInterface, IBuilderPolicy policy, object buildKey) { lock (lockObject) policies[new PolicyKey(policyInterface, buildKey)] = policy; }
public void Set(Type type, string name, Type policyInterface, IBuilderPolicy policy) { if (type != _store.Type || name != _store.Name) { _policies.Set(type, name, policyInterface, policy); } ((IPolicySet)_store).Set(policyInterface, policy); }
/// <summary> /// Sets an individual policy. /// </summary> /// <param name="policyInterface">The interface to register the policy under.</param> /// <param name="policy">The policy to be registered.</param> /// <param name="typePolicyAppliesTo">The type the policy applies to.</param> /// <param name="idPolicyAppliesTo">The ID the policy applies to.</param> public void Set(Type policyInterface, IBuilderPolicy policy, Type typePolicyAppliesTo, string idPolicyAppliesTo) { BuilderPolicyKey key = new BuilderPolicyKey(policyInterface, typePolicyAppliesTo, idPolicyAppliesTo); lock (lockObject) { policies[key] = policy; } }
public void PolicyRegisteredForTypeIsUsedIfKeyIsNotFound() { PolicyList list = new PolicyList(); FakePolicy policyForType = new FakePolicy(); list.Set(typeof(object), string.Empty, typeof(IBuilderPolicy), policyForType); IBuilderPolicy result = list.GetOrDefault(typeof(IBuilderPolicy), new NamedTypeBuildKey <object>("name"), out _); Assert.AreSame(policyForType, result); }
public void DefaultPolicyUsedWhenSpecificPolicyIsntAvailable() { PolicyList list = new PolicyList(); FakePolicy defaultPolicy = new FakePolicy(); list.Set(null, null, typeof(IBuilderPolicy), defaultPolicy); IBuilderPolicy result = list.GetOrDefault(typeof(IBuilderPolicy), typeof(object), out _); Assert.AreSame(defaultPolicy, result); }
public void CanAddPolicyToBagAndRetrieveIt() { PolicyList list = new PolicyList(); FakePolicy policy = new FakePolicy(); list.Set(typeof(object), string.Empty, typeof(IBuilderPolicy), policy); IBuilderPolicy result = list.GetOrDefault(typeof(IBuilderPolicy), typeof(object), out _); Assert.AreSame(policy, result); }
public void PolicyRegisteredForTypeIsUsedIfKeyIsNotFound() { PolicyList list = new PolicyList(); FakePolicy policyForType = new FakePolicy(); list.Set <IBuilderPolicy>(policyForType, typeof(object)); IBuilderPolicy result = list.Get <IBuilderPolicy>(new NamedTypeBuildKey <object>("name")); Assert.Same(policyForType, result); }
public void PolicyRegisteredForOpenGenericTypeUsedIfKeyIsNotFound() { PolicyList list = new PolicyList(); FakePolicy policyForType = new FakePolicy(); list.Set <IBuilderPolicy>(policyForType, typeof(IDummy <>)); IBuilderPolicy result = list.Get <IBuilderPolicy>(new NamedTypeBuildKey <IDummy <object> >("name")); Assert.AreSame(policyForType, result); }
public void SetDefault(Type policyInterface, IBuilderPolicy policy) { if (policyInterface == typeof(IPropertySelectorPolicy)) { this.PropertySelectorPolicy = (IPropertySelectorPolicy)policy; } else { throw new NotImplementedException(); } }
public void DefaultPolicyUsedWhenSpecificPolicyIsntAvailable() { PolicyList list = new PolicyList(); FakePolicy defaultPolicy = new FakePolicy(); list.SetDefault <IBuilderPolicy>(defaultPolicy); IBuilderPolicy result = list.Get <IBuilderPolicy>(typeof(object)); Assert.AreSame(defaultPolicy, result); }
public void CanAddPolicyToBagAndRetrieveIt() { PolicyList list = new PolicyList(); FakePolicy policy = new FakePolicy(); list.Set <IBuilderPolicy>(policy, typeof(object)); IBuilderPolicy result = list.Get <IBuilderPolicy>(typeof(object)); Assert.AreSame(policy, result); }
/// <summary> /// Sets an individual policy. /// </summary> /// <param name="policyInterface">The <see cref="Type"/> of the policy.</param> /// <param name="policy">The policy to be registered.</param> /// <param name="buildKey">The key the policy applies.</param> public void Set(Type policyInterface, IBuilderPolicy policy, object buildKey) { lock (lockObject) { Dictionary <PolicyKey, IBuilderPolicy> newPolicies = ClonePolicies(); newPolicies[new PolicyKey(policyInterface, buildKey)] = policy; SwapPolicies(newPolicies); } }
public void SetOverwritesExistingPolicy() { PolicyList list = new PolicyList(); FakePolicy policy1 = new FakePolicy(); FakePolicy policy2 = new FakePolicy(); list.Set <IBuilderPolicy>(policy1, typeof(string)); list.Set <IBuilderPolicy>(policy2, typeof(string)); IBuilderPolicy result = list.Get <IBuilderPolicy>(typeof(string)); Assert.AreSame(policy2, result); }
public void PolicyForClosedGenericTypeOverridesPolicyForOpenType() { PolicyList list = new PolicyList(); FakePolicy openTypePolicy = new FakePolicy(); FakePolicy closedTypePolicy = new FakePolicy(); list.Set <IBuilderPolicy>(openTypePolicy, typeof(IDummy <>)); list.Set <IBuilderPolicy>(closedTypePolicy, typeof(IDummy <object>)); IBuilderPolicy result = list.Get <IBuilderPolicy>(new NamedTypeBuildKey <IDummy <object> >("name")); Assert.AreSame(closedTypePolicy, result); }
public void SetOverwritesExistingPolicy() { PolicyList list = new PolicyList(); FakePolicy policy1 = new FakePolicy(); FakePolicy policy2 = new FakePolicy(); list.Set(typeof(string), string.Empty, typeof(IBuilderPolicy), policy1); list.Set(typeof(string), string.Empty, typeof(IBuilderPolicy), policy2); IBuilderPolicy result = list.GetOrDefault(typeof(IBuilderPolicy), typeof(string), out _); Assert.AreSame(policy2, result); }
public void SpecificPolicyOverridesDefaultPolicy() { PolicyList list = new PolicyList(); FakePolicy defaultPolicy = new FakePolicy(); FakePolicy specificPolicy = new FakePolicy(); list.Set(typeof(object), string.Empty, typeof(IBuilderPolicy), specificPolicy); list.Set(null, null, typeof(IBuilderPolicy), defaultPolicy); IBuilderPolicy result = list.GetOrDefault(typeof(IBuilderPolicy), typeof(object), out _); Assert.AreSame(specificPolicy, result); }
public void CanClearDefaultPolicy() { PolicyList list = new PolicyList(); FakePolicy defaultPolicy = new FakePolicy(); list.Set(null, null, typeof(IBuilderPolicy), defaultPolicy); list.Clear(null, null, typeof(IBuilderPolicy)); IBuilderPolicy result = list.GetOrDefault(typeof(IBuilderPolicy), typeof(object), out _); Assert.IsNull(result); }
public void PolicyForClosedGenericTypeOverridesPolicyForOpenType() { PolicyList list = new PolicyList(); FakePolicy openTypePolicy = new FakePolicy(); FakePolicy closedTypePolicy = new FakePolicy(); list.Set(typeof(IDummy <>), string.Empty, typeof(IBuilderPolicy), openTypePolicy); list.Set(typeof(IDummy <object>), string.Empty, typeof(IBuilderPolicy), closedTypePolicy); IBuilderPolicy result = list.GetOrDefault(typeof(IBuilderPolicy), new NamedTypeBuildKey <IDummy <object> >("name"), out _); Assert.AreSame(closedTypePolicy, result); }
public void SpecificPolicyOverridesDefaultPolicy() { PolicyList list = new PolicyList(); FakePolicy defaultPolicy = new FakePolicy(); FakePolicy specificPolicy = new FakePolicy(); list.Set <IBuilderPolicy>(specificPolicy, typeof(object)); list.SetDefault <IBuilderPolicy>(defaultPolicy); IBuilderPolicy result = list.Get <IBuilderPolicy>(typeof(object)); Assert.AreSame(specificPolicy, result); }
public IBuilderPolicy Get(Type type, string name, Type policyInterface, out IPolicyList list) { list = null; IBuilderPolicy policy = null; if (_policies?.TryGetValue(new PolicyKey(type, name, policyInterface), out policy) ?? false) { list = this; return(policy); } return(_innerPolicyList?.Get(type, name, policyInterface, out list)); }
public void TestSettingAndRetrievePolicy() { PolicyList policies = new PolicyList(); MockCreationPolicy policy = new MockCreationPolicy(); policies.Set <IBuilderPolicy>(policy, typeof(object), null); BuilderContext context = new BuilderContext(null, null, policies); IBuilderPolicy outPolicy = context.Policies.Get <IBuilderPolicy>(typeof(object), null); Assert.IsNotNull(outPolicy); Assert.AreSame(policy, outPolicy); }
public void CanClearDefaultPolicy() { PolicyList list = new PolicyList(); FakePolicy defaultPolicy = new FakePolicy(); list.SetDefault <IBuilderPolicy>(defaultPolicy); list.ClearDefault <IBuilderPolicy>(); IBuilderPolicy result = list.Get <IBuilderPolicy>(typeof(object)); Assert.IsNull(result); }
public void Set(Type type, string name, Type policyInterface, IBuilderPolicy policy) { if (null == _policies) { lock (_sync) { if (null == _policies) { _policies = new Dictionary <PolicyKey, IBuilderPolicy>(PolicyKeyEqualityComparer.Default); } } } _policies[new PolicyKey(type, name, policyInterface)] = policy; }
public static void Set(this IPolicyList policies, Type policyInterface, IBuilderPolicy policy, object buildKey = null) { var key = ParseBuildKey(buildKey); (policies ?? throw new ArgumentNullException(nameof(policies))).Set(key.Item1, key.Item2, policyInterface, policy); }
/// <summary> /// Sets a default policy. When checking for a policy, if no specific individual policy /// is available, the default will be used. /// </summary> /// <param name="policies"></param> /// <param name="policyInterface">The interface to register the policy under.</param> /// <param name="policy">The default policy to be registered.</param> public static void SetDefault(this IPolicyList policies, Type policyInterface, IBuilderPolicy policy) { (policies ?? throw new ArgumentNullException(nameof(policies))).Set(null, null, policyInterface, policy); }
public void SetDefault(Type policyInterface, IBuilderPolicy policy) { throw new NotImplementedException(); }
public void Set(Type policyInterface, IBuilderPolicy policy, object buildKey) { throw new NotImplementedException(); }
/// <summary> /// Sets a default policy. When checking for a policy, if no specific individual policy /// is available, the default will be used. /// </summary> /// <param name="policyInterface">The interface to register the policy under.</param> /// <param name="policy">The default policy to be registered.</param> public void SetDefault(Type policyInterface, IBuilderPolicy policy) { Set(policyInterface, policy, null); }
/// <summary> /// Sets an individual policy. /// </summary> /// <param name="policyInterface">The <see cref="Type"/> of the policy.</param> /// <param name="policy">The policy to be registered.</param> /// <param name="buildKey">The key the policy applies.</param> public void Set(Type policyInterface, IBuilderPolicy policy, object buildKey) { lock (lockObject) { Dictionary<PolicyKey, IBuilderPolicy> newPolicies = ClonePolicies(); newPolicies[new PolicyKey(policyInterface, buildKey)] = policy; SwapPolicies(newPolicies); } }
public void SetPolicy(Type policyType, IBuilderPolicy policy, Type typeToRegisterFor) { policies.Set(policyType, policy, typeToRegisterFor); }
public void SetDefaultPolicy(Type policyType, IBuilderPolicy policy) { policies.SetDefault(policyType, policy); }