internal static ReadOnlyCollection <IAuthorizationPolicy> CloneAuthorizationPoliciesIfNecessary(ReadOnlyCollection <IAuthorizationPolicy> authorizationPolicies) { if (authorizationPolicies != null && authorizationPolicies.Count > 0) { bool clone = false; for (int i = 0; i < authorizationPolicies.Count; ++i) { UnconditionalPolicy policy = authorizationPolicies[i] as UnconditionalPolicy; if (policy != null && policy.IsDisposable) { clone = true; break; } } if (clone) { List <IAuthorizationPolicy> ret = new List <IAuthorizationPolicy>(authorizationPolicies.Count); for (int i = 0; i < authorizationPolicies.Count; ++i) { UnconditionalPolicy policy = authorizationPolicies[i] as UnconditionalPolicy; if (policy != null) { ret.Add(policy.Clone()); } else { ret.Add(authorizationPolicies[i]); } } return(new ReadOnlyCollection <IAuthorizationPolicy>(ret)); } } return(authorizationPolicies); }
internal static ReadOnlyCollection <IAuthorizationPolicy> CloneAuthorizationPoliciesIfNecessary(ReadOnlyCollection <IAuthorizationPolicy> authorizationPolicies) { if ((authorizationPolicies == null) || (authorizationPolicies.Count <= 0)) { return(authorizationPolicies); } bool flag = false; for (int i = 0; i < authorizationPolicies.Count; i++) { UnconditionalPolicy policy = authorizationPolicies[i] as UnconditionalPolicy; if ((policy != null) && policy.IsDisposable) { flag = true; break; } } if (!flag) { return(authorizationPolicies); } List <IAuthorizationPolicy> list = new List <IAuthorizationPolicy>(authorizationPolicies.Count); for (int j = 0; j < authorizationPolicies.Count; j++) { UnconditionalPolicy policy2 = authorizationPolicies[j] as UnconditionalPolicy; if (policy2 != null) { list.Add(policy2.Clone()); } else { list.Add(authorizationPolicies[j]); } } return(list.AsReadOnly()); }