コード例 #1
0
ファイル: PolicyContainer.cs プロジェクト: poke/monodevelop
 /// <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> ());
     }
 }
コード例 #2
0
        public void Set <T> (T value, string scope) where T : class, IEquatable <T>, new ()
        {
            CheckReadOnly();
            PolicyKey key = new PolicyKey(typeof(T), scope);

            System.Diagnostics.Debug.Assert(key.Scope == scope);

            if (policies == null)
            {
                policies = new PolicyDictionary();
            }
            else if (value != null)
            {
                object oldVal = null;
                policies.TryGetValue(key, out oldVal);
                if (oldVal != null && ((IEquatable <T>)oldVal).Equals(value))
                {
                    return;
                }
            }

            policies[key] = value;
            OnPolicyChanged(key.PolicyType, key.Scope);
        }