示例#1
0
 public SpyExtension(IBuilderStrategy strategy, UnityBuildStage stage, IBuilderPolicy policy, Type policyType)
 {
     this.strategy = strategy;
     this.stage = stage;
     this.policy = policy;
     this.policyType = policyType;
 }
示例#2
0
 public void Set(Type policyInterface,
                 IBuilderPolicy policy,
                 object buildKey)
 {
     lock (lockObject)
         policies[new PolicyKey(policyInterface, buildKey)] = policy;
 }
示例#3
0
 public SpyExtension(IBuilderStrategy strategy, UnityBuildStage stage, IBuilderPolicy policy, Type policyType)
 {
     this.strategy   = strategy;
     this.stage      = stage;
     this.policy     = policy;
     this.policyType = policyType;
 }
            public void Set(Type type, string name, Type policyInterface, IBuilderPolicy policy)
            {
                if (type != _store.Type || name != _store.Name)
                {
                    _policies.Set(type, name, policyInterface, policy);
                }

                ((IPolicySet)_store).Set(policyInterface, policy);
            }
示例#5
0
        /// <summary>
        /// Sets an individual policy.
        /// </summary>
        /// <param name="policyInterface">The interface to register the policy under.</param>
        /// <param name="policy">The policy to be registered.</param>
        /// <param name="typePolicyAppliesTo">The type the policy applies to.</param>
        /// <param name="idPolicyAppliesTo">The ID the policy applies to.</param>
        public void Set(Type policyInterface, IBuilderPolicy policy, Type typePolicyAppliesTo, string idPolicyAppliesTo)
        {
            BuilderPolicyKey key = new BuilderPolicyKey(policyInterface, typePolicyAppliesTo, idPolicyAppliesTo);

            lock (lockObject)
            {
                policies[key] = policy;
            }
        }
示例#6
0
        public void PolicyRegisteredForTypeIsUsedIfKeyIsNotFound()
        {
            PolicyList list          = new PolicyList();
            FakePolicy policyForType = new FakePolicy();

            list.Set(typeof(object), string.Empty, typeof(IBuilderPolicy), policyForType);

            IBuilderPolicy result = list.GetOrDefault(typeof(IBuilderPolicy), new NamedTypeBuildKey <object>("name"), out _);

            Assert.AreSame(policyForType, result);
        }
示例#7
0
        public void DefaultPolicyUsedWhenSpecificPolicyIsntAvailable()
        {
            PolicyList list          = new PolicyList();
            FakePolicy defaultPolicy = new FakePolicy();

            list.Set(null, null, typeof(IBuilderPolicy), defaultPolicy);

            IBuilderPolicy result = list.GetOrDefault(typeof(IBuilderPolicy), typeof(object), out _);

            Assert.AreSame(defaultPolicy, result);
        }
示例#8
0
        public void CanAddPolicyToBagAndRetrieveIt()
        {
            PolicyList list   = new PolicyList();
            FakePolicy policy = new FakePolicy();

            list.Set(typeof(object), string.Empty, typeof(IBuilderPolicy), policy);

            IBuilderPolicy result = list.GetOrDefault(typeof(IBuilderPolicy), typeof(object), out _);

            Assert.AreSame(policy, result);
        }
示例#9
0
        public void PolicyRegisteredForTypeIsUsedIfKeyIsNotFound()
        {
            PolicyList list          = new PolicyList();
            FakePolicy policyForType = new FakePolicy();

            list.Set <IBuilderPolicy>(policyForType, typeof(object));

            IBuilderPolicy result = list.Get <IBuilderPolicy>(new NamedTypeBuildKey <object>("name"));

            Assert.Same(policyForType, result);
        }
示例#10
0
        public void PolicyRegisteredForOpenGenericTypeUsedIfKeyIsNotFound()
        {
            PolicyList list          = new PolicyList();
            FakePolicy policyForType = new FakePolicy();

            list.Set <IBuilderPolicy>(policyForType, typeof(IDummy <>));

            IBuilderPolicy result = list.Get <IBuilderPolicy>(new NamedTypeBuildKey <IDummy <object> >("name"));

            Assert.AreSame(policyForType, result);
        }
示例#11
0
 public void SetDefault(Type policyInterface, IBuilderPolicy policy)
 {
     if (policyInterface == typeof(IPropertySelectorPolicy))
     {
         this.PropertySelectorPolicy = (IPropertySelectorPolicy)policy;
     }
     else
     {
         throw new NotImplementedException();
     }
 }
示例#12
0
        public void DefaultPolicyUsedWhenSpecificPolicyIsntAvailable()
        {
            PolicyList list          = new PolicyList();
            FakePolicy defaultPolicy = new FakePolicy();

            list.SetDefault <IBuilderPolicy>(defaultPolicy);

            IBuilderPolicy result = list.Get <IBuilderPolicy>(typeof(object));

            Assert.AreSame(defaultPolicy, result);
        }
示例#13
0
        public void CanAddPolicyToBagAndRetrieveIt()
        {
            PolicyList list   = new PolicyList();
            FakePolicy policy = new FakePolicy();

            list.Set <IBuilderPolicy>(policy, typeof(object));

            IBuilderPolicy result = list.Get <IBuilderPolicy>(typeof(object));

            Assert.AreSame(policy, result);
        }
示例#14
0
 /// <summary>
 /// Sets an individual policy.
 /// </summary>
 /// <param name="policyInterface">The <see cref="Type"/> of the policy.</param>
 /// <param name="policy">The policy to be registered.</param>
 /// <param name="buildKey">The key the policy applies.</param>
 public void Set(Type policyInterface,
                 IBuilderPolicy policy,
                 object buildKey)
 {
     lock (lockObject)
     {
         Dictionary <PolicyKey, IBuilderPolicy> newPolicies = ClonePolicies();
         newPolicies[new PolicyKey(policyInterface, buildKey)] = policy;
         SwapPolicies(newPolicies);
     }
 }
示例#15
0
        public void SetOverwritesExistingPolicy()
        {
            PolicyList list    = new PolicyList();
            FakePolicy policy1 = new FakePolicy();
            FakePolicy policy2 = new FakePolicy();

            list.Set <IBuilderPolicy>(policy1, typeof(string));
            list.Set <IBuilderPolicy>(policy2, typeof(string));

            IBuilderPolicy result = list.Get <IBuilderPolicy>(typeof(string));

            Assert.AreSame(policy2, result);
        }
示例#16
0
        public void PolicyForClosedGenericTypeOverridesPolicyForOpenType()
        {
            PolicyList list             = new PolicyList();
            FakePolicy openTypePolicy   = new FakePolicy();
            FakePolicy closedTypePolicy = new FakePolicy();

            list.Set <IBuilderPolicy>(openTypePolicy, typeof(IDummy <>));
            list.Set <IBuilderPolicy>(closedTypePolicy, typeof(IDummy <object>));

            IBuilderPolicy result = list.Get <IBuilderPolicy>(new NamedTypeBuildKey <IDummy <object> >("name"));

            Assert.AreSame(closedTypePolicy, result);
        }
示例#17
0
        public void SetOverwritesExistingPolicy()
        {
            PolicyList list    = new PolicyList();
            FakePolicy policy1 = new FakePolicy();
            FakePolicy policy2 = new FakePolicy();

            list.Set(typeof(string), string.Empty, typeof(IBuilderPolicy), policy1);
            list.Set(typeof(string), string.Empty, typeof(IBuilderPolicy), policy2);

            IBuilderPolicy result = list.GetOrDefault(typeof(IBuilderPolicy), typeof(string), out _);

            Assert.AreSame(policy2, result);
        }
示例#18
0
        public void SpecificPolicyOverridesDefaultPolicy()
        {
            PolicyList list           = new PolicyList();
            FakePolicy defaultPolicy  = new FakePolicy();
            FakePolicy specificPolicy = new FakePolicy();

            list.Set(typeof(object), string.Empty, typeof(IBuilderPolicy), specificPolicy);
            list.Set(null, null, typeof(IBuilderPolicy), defaultPolicy);

            IBuilderPolicy result = list.GetOrDefault(typeof(IBuilderPolicy), typeof(object), out _);

            Assert.AreSame(specificPolicy, result);
        }
示例#19
0
        public void CanClearDefaultPolicy()
        {
            PolicyList list          = new PolicyList();
            FakePolicy defaultPolicy = new FakePolicy();

            list.Set(null, null, typeof(IBuilderPolicy), defaultPolicy);

            list.Clear(null, null, typeof(IBuilderPolicy));

            IBuilderPolicy result = list.GetOrDefault(typeof(IBuilderPolicy), typeof(object), out _);

            Assert.IsNull(result);
        }
示例#20
0
        public void PolicyForClosedGenericTypeOverridesPolicyForOpenType()
        {
            PolicyList list             = new PolicyList();
            FakePolicy openTypePolicy   = new FakePolicy();
            FakePolicy closedTypePolicy = new FakePolicy();

            list.Set(typeof(IDummy <>), string.Empty, typeof(IBuilderPolicy), openTypePolicy);
            list.Set(typeof(IDummy <object>), string.Empty, typeof(IBuilderPolicy), closedTypePolicy);

            IBuilderPolicy result = list.GetOrDefault(typeof(IBuilderPolicy), new NamedTypeBuildKey <IDummy <object> >("name"), out _);

            Assert.AreSame(closedTypePolicy, result);
        }
示例#21
0
        public void SpecificPolicyOverridesDefaultPolicy()
        {
            PolicyList list           = new PolicyList();
            FakePolicy defaultPolicy  = new FakePolicy();
            FakePolicy specificPolicy = new FakePolicy();

            list.Set <IBuilderPolicy>(specificPolicy, typeof(object));
            list.SetDefault <IBuilderPolicy>(defaultPolicy);

            IBuilderPolicy result = list.Get <IBuilderPolicy>(typeof(object));

            Assert.AreSame(specificPolicy, result);
        }
示例#22
0
        public IBuilderPolicy Get(Type type, string name, Type policyInterface, out IPolicyList list)
        {
            list = null;
            IBuilderPolicy policy = null;

            if (_policies?.TryGetValue(new PolicyKey(type, name, policyInterface), out policy) ?? false)
            {
                list = this;
                return(policy);
            }

            return(_innerPolicyList?.Get(type, name, policyInterface, out list));
        }
        public void TestSettingAndRetrievePolicy()
        {
            PolicyList         policies = new PolicyList();
            MockCreationPolicy policy   = new MockCreationPolicy();

            policies.Set <IBuilderPolicy>(policy, typeof(object), null);
            BuilderContext context = new BuilderContext(null, null, policies);

            IBuilderPolicy outPolicy = context.Policies.Get <IBuilderPolicy>(typeof(object), null);

            Assert.IsNotNull(outPolicy);
            Assert.AreSame(policy, outPolicy);
        }
示例#24
0
        public void CanClearDefaultPolicy()
        {
            PolicyList list          = new PolicyList();
            FakePolicy defaultPolicy = new FakePolicy();

            list.SetDefault <IBuilderPolicy>(defaultPolicy);

            list.ClearDefault <IBuilderPolicy>();

            IBuilderPolicy result = list.Get <IBuilderPolicy>(typeof(object));

            Assert.IsNull(result);
        }
示例#25
0
 public void Set(Type type, string name, Type policyInterface, IBuilderPolicy policy)
 {
     if (null == _policies)
     {
         lock (_sync)
         {
             if (null == _policies)
             {
                 _policies = new Dictionary <PolicyKey, IBuilderPolicy>(PolicyKeyEqualityComparer.Default);
             }
         }
     }
     _policies[new PolicyKey(type, name, policyInterface)] = policy;
 }
        public static void Set(this IPolicyList policies, Type policyInterface, IBuilderPolicy policy, object buildKey = null)
        {
            var key = ParseBuildKey(buildKey);

            (policies ?? throw new ArgumentNullException(nameof(policies))).Set(key.Item1, key.Item2, policyInterface, policy);
        }
 /// <summary>
 /// Sets a default policy. When checking for a policy, if no specific individual policy
 /// is available, the default will be used.
 /// </summary>
 /// <param name="policies"></param>
 /// <param name="policyInterface">The interface to register the policy under.</param>
 /// <param name="policy">The default policy to be registered.</param>
 public static void SetDefault(this IPolicyList policies, Type policyInterface, IBuilderPolicy policy)
 {
     (policies ?? throw new ArgumentNullException(nameof(policies))).Set(null, null, policyInterface, policy);
 }
示例#28
0
 public void SetDefault(Type policyInterface,
                        IBuilderPolicy policy)
 {
     throw new NotImplementedException();
 }
示例#29
0
 public void Set(Type policyInterface,
                 IBuilderPolicy policy,
                 object buildKey)
 {
     throw new NotImplementedException();
 }
示例#30
0
 /// <summary>
 /// Sets a default policy. When checking for a policy, if no specific individual policy
 /// is available, the default will be used.
 /// </summary>
 /// <param name="policyInterface">The interface to register the policy under.</param>
 /// <param name="policy">The default policy to be registered.</param>
 public void SetDefault(Type policyInterface,
                        IBuilderPolicy policy)
 {
     Set(policyInterface, policy, null);
 }
示例#31
0
 /// <summary>
 /// Sets an individual policy.
 /// </summary>
 /// <param name="policyInterface">The <see cref="Type"/> of the policy.</param>
 /// <param name="policy">The policy to be registered.</param>
 /// <param name="buildKey">The key the policy applies.</param>
 public void Set(Type policyInterface,
                 IBuilderPolicy policy,
                 object buildKey)
 {
     lock (lockObject)
     {
         Dictionary<PolicyKey, IBuilderPolicy> newPolicies = ClonePolicies();
         newPolicies[new PolicyKey(policyInterface, buildKey)] = policy;
         SwapPolicies(newPolicies);
     }
 }
 public void SetPolicy(Type policyType,
                       IBuilderPolicy policy,
                       Type typeToRegisterFor)
 {
     policies.Set(policyType, policy, typeToRegisterFor);
 }
 public void SetDefaultPolicy(Type policyType,
                              IBuilderPolicy policy)
 {
     policies.SetDefault(policyType, policy);
 }
示例#34
0
 /// <summary>
 /// Sets a default policy. When checking for a policy, if no specific individual policy
 /// is available, the default will be used.
 /// </summary>
 /// <param name="policyInterface">The interface to register the policy under.</param>
 /// <param name="policy">The default policy to be registered.</param>
 public void SetDefault(Type policyInterface,
                        IBuilderPolicy policy)
 {
     Set(policyInterface, policy, null);
 }
示例#35
0
 public void Set(Type policyInterface,
                 IBuilderPolicy policy,
                 object buildKey)
 {
     throw new NotImplementedException();
 }
示例#36
0
 public void SetDefault(Type policyInterface,
                        IBuilderPolicy policy)
 {
     throw new NotImplementedException();
 }