/// <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; } }
/// <summary> /// Gets an individual policy. /// </summary> /// <param name="policyInterface">The interface the policy is registered under.</param> /// <param name="typePolicyAppliesTo">The type the policy applies to.</param> /// <param name="idPolicyAppliesTo">The ID the policy applies to.</param> /// <returns>The policy in the list, if present; returns null otherwise.</returns> public IBuilderPolicy Get(Type policyInterface, Type typePolicyAppliesTo, string idPolicyAppliesTo) { BuilderPolicyKey key = new BuilderPolicyKey(policyInterface, typePolicyAppliesTo, idPolicyAppliesTo); lock (lockObject) { IBuilderPolicy policy; if (policies.TryGetValue(key, out policy)) { return(policy); } BuilderPolicyKey defaultKey = new BuilderPolicyKey(policyInterface, null, null); if (policies.TryGetValue(defaultKey, out policy)) { return(policy); } return(null); } }