示例#1
0
 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);
     }
 }
示例#2
0
 internal object Get(Type type, IEnumerable <string> scopes)
 {
     // The search is done vertically, looking first at the parents
     foreach (string scope in scopes)
     {
         PolicyContainer currentBag = this;
         while (currentBag != null)
         {
             if (currentBag.DirectHas(type, scope))
             {
                 object pol = currentBag.DirectGet(type, 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;
             }
         }
     }
     return(GetDefaultPolicy(type, scopes));
 }