/// <summary> /// Gets an individual policy. /// </summary> /// <param name="list"></param> /// <param name="policyInterface">The interface the policy is registered under.</param> /// <param name="buildKey">The key the policy applies.</param> /// <param name="containingPolicyList">The policy list in the chain that the searched for policy was found in, null if the policy was /// not found.</param> /// <returns>The policy in the list, if present; returns null otherwise.</returns> public static IBuilderPolicy GetOrDefault(this IPolicyList list, Type policyInterface, object buildKey, out IPolicyList containingPolicyList) { Type buildType; if (buildKey is INamedType basedBuildKey) { buildType = basedBuildKey.Type; } else { buildType = buildKey as Type; } return(list.GetPolicyForKey(policyInterface, buildKey, out containingPolicyList) ?? list.GetPolicyForOpenGenericKey(policyInterface, buildKey, buildType, out containingPolicyList) ?? list.GetPolicyForType(policyInterface, buildType, out containingPolicyList) ?? list.GetPolicyForOpenGenericType(policyInterface, buildType, out containingPolicyList) ?? list.GetDefaultForPolicy(policyInterface, out containingPolicyList)); }