public T Get <T> (IEnumerable <string> scopes) where T : class, IEquatable <T>, new () { // The search is done vertically, looking first at the parents foreach (string scope in scopes) { PolicyContainer currentBag = this; while (currentBag != null) { if (currentBag.DirectHas <T> (scope)) { T pol = currentBag.DirectGet <T> (scope); if (!PolicyService.IsUndefinedPolicy(pol)) { return(pol); } // If the bag has the policy (Has<> returns true) but the policy is undefined, // then we have to keep looking using the base scopes. // We start looking from the original bag, using the new scope. break; } else { currentBag = currentBag.ParentPolicies; } } } if (InheritDefaultPolicies) { return(PolicyService.GetDefaultPolicy <T>(scopes)); } else { return(null); } }
/// <summary> /// The Get methods return policies taking into account inheritance. If a policy /// can't be found it may return null, but never an 'undefined' policy. /// </summary> /// <returns> /// The policy of the given type, or null if not found. /// </returns> public T Get <T> () where T : class, IEquatable <T>, new () { if (policies != null) { object policy; if (policies.TryGetValue(typeof(T), null, out policy)) { if (!PolicyService.IsUndefinedPolicy(policy)) { return((T)policy); } else if (InheritDefaultPolicies) { return(PolicyService.GetDefaultPolicy <T> ()); } else { return(null); } } } if (!InheritDefaultPolicies) { return(null); } else if (IsRoot) { return(PolicyService.GetDefaultPolicy <T> ()); } else { return(ParentPolicies.Get <T> ()); } }
protected virtual object GetDefaultPolicy(Type type, IEnumerable <string> scopes) { return(PolicyService.GetDefaultPolicy(type, scopes)); }
protected virtual object GetDefaultPolicy(Type type) { return(PolicyService.GetDefaultPolicy(type)); }
protected virtual T GetDefaultPolicy <T> (IEnumerable <string> scopes) where T : class, IEquatable <T>, new () { return(PolicyService.GetDefaultPolicy <T> (scopes)); }
protected virtual T GetDefaultPolicy <T> () where T : class, IEquatable <T>, new () { return(PolicyService.GetDefaultPolicy <T> ()); }