当前位置: 首页>>代码示例>>C#>>正文


C# MutablePropertyValues.Add方法代码示例

本文整理汇总了C#中MutablePropertyValues.Add方法的典型用法代码示例。如果您正苦于以下问题:C# MutablePropertyValues.Add方法的具体用法?C# MutablePropertyValues.Add怎么用?C# MutablePropertyValues.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MutablePropertyValues的用法示例。


在下文中一共展示了MutablePropertyValues.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InitFactory

        private void InitFactory(DefaultListableObjectFactory factory)
        {
            Console.WriteLine("init factory");
            RootObjectDefinition tee = new RootObjectDefinition(typeof(Tee), true);
            tee.IsLazyInit = true;
            ConstructorArgumentValues teeValues = new ConstructorArgumentValues();
            teeValues.AddGenericArgumentValue("test");
            tee.ConstructorArgumentValues = teeValues;

            RootObjectDefinition bar = new RootObjectDefinition(typeof(BBar), false);
            ConstructorArgumentValues barValues = new ConstructorArgumentValues();
            barValues.AddGenericArgumentValue(new RuntimeObjectReference("tee"));
            barValues.AddGenericArgumentValue(5);
            bar.ConstructorArgumentValues = barValues;

            RootObjectDefinition foo = new RootObjectDefinition(typeof(FFoo), false);
            MutablePropertyValues fooValues = new MutablePropertyValues();
            fooValues.Add("i", 5);
            fooValues.Add("bar", new RuntimeObjectReference("bar"));
            fooValues.Add("copy", new RuntimeObjectReference("bar"));
            fooValues.Add("s", "test");
            foo.PropertyValues = fooValues;

            factory.RegisterObjectDefinition("foo", foo);
            factory.RegisterObjectDefinition("bar", bar);
            factory.RegisterObjectDefinition("tee", tee);
        }
开发者ID:fgq841103,项目名称:spring-net,代码行数:27,代码来源:DefaultListableObjectFactoryPerfTests.cs

示例2: ChainedResolution

        public void ChainedResolution()
        {
            StaticApplicationContext ac = new StaticApplicationContext();

            MutablePropertyValues pvs = new MutablePropertyValues();
            pvs.Add("name", "${name}");
            pvs.Add("nickname", "${nickname}");
            ac.RegisterSingleton("tb1", typeof(TestObject), pvs);

            IList variableSources = new ArrayList();
            variableSources.Add(new DictionaryVariableSource(new string[] { "name", "name-value" }));
            variableSources.Add(new DictionaryVariableSource(new string[] { "nickname", "nickname-value" }));
            VariablePlaceholderConfigurer vphc = new VariablePlaceholderConfigurer(variableSources);
            ac.AddObjectFactoryPostProcessor(vphc);
            ac.Refresh();

            TestObject tb1 = (TestObject)ac.GetObject("tb1");
            Assert.AreEqual("name-value", tb1.Name);
            Assert.AreEqual("nickname-value", tb1.Nickname);
        }
开发者ID:serra,项目名称:spring-net,代码行数:20,代码来源:VariablePlaceholderConfigurerTests.cs

示例3: AddPropertyValue

 public void AddPropertyValue()
 {
     StaticApplicationContext ac = new StaticApplicationContext();
     ac.RegisterSingleton("tb1", typeof(TestObject), new MutablePropertyValues());
     ac.RegisterSingleton("tb2", typeof(TestObject), new MutablePropertyValues());
     MutablePropertyValues pvs = new MutablePropertyValues();
     pvs.Add("Properties", "<spring-config><add key=\"tb1.Age\" value=\"99\"/><add key=\"tb2.Name\" value=\"test\"/></spring-config>");
     ac.RegisterSingleton("configurer1", typeof(PropertyOverrideConfigurer), pvs);
     pvs = new MutablePropertyValues();
     pvs.Add("Properties", "<spring-config><add key=\"tb2.Age\" value=\"99\"/><add key=\"tb2.Name\" value=\"test\"/></spring-config>");
     pvs.Add("order", "0");
     ac.RegisterSingleton("configurer2", typeof(PropertyOverrideConfigurer), pvs);
     ac.Refresh();
     TestObject tb1 = (TestObject)ac.GetObject("tb1");
     TestObject tb2 = (TestObject)ac.GetObject("tb2");
     Assert.AreEqual(99, tb1.Age);
     Assert.AreEqual(99, tb2.Age);
     Assert.AreEqual(null, tb1.Name);
     Assert.AreEqual("test", tb2.Name);
 }
开发者ID:adamlepkowski,项目名称:spring-net,代码行数:20,代码来源:PropertyOverrideConfigurerTests.cs

示例4: BailsOnUnresolvableVariable

        public void BailsOnUnresolvableVariable()
        {
            StaticApplicationContext ac = new StaticApplicationContext();

            MutablePropertyValues pvs = new MutablePropertyValues();
            pvs.Add("nickname", "${nickname}");
            ac.RegisterSingleton("tb1", typeof(TestObject), pvs);

            IList variableSources = new ArrayList();
            variableSources.Add(new DictionaryVariableSource(new string[] { }));
            pvs = new MutablePropertyValues();
            pvs.Add("VariableSources", variableSources);
            ac.RegisterSingleton("configurer", typeof(VariablePlaceholderConfigurer), pvs);

            try
            {
                ac.Refresh();
                Assert.Fail("something changed wrt VariablePlaceholder resolution");
            }
            catch (ObjectDefinitionStoreException ex)
            {
                Assert.IsTrue(ex.Message.IndexOf("nickname") > -1);
            }
        }
开发者ID:serra,项目名称:spring-net,代码行数:24,代码来源:VariablePlaceholderConfigurerTests.cs

示例5: TestIInstantiationAwareObjectPostProcessorsPassThrough

        public void TestIInstantiationAwareObjectPostProcessorsPassThrough()
        {
            NullInstantiationAwareObjectPostProcessorStub proc
                = new NullInstantiationAwareObjectPostProcessorStub();

            MutablePropertyValues props = new MutablePropertyValues();
            props.Add("Name", "Rick");
            RootObjectDefinition not
                = new RootObjectDefinition(typeof(TestObject), props);

            DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
            lof.AddObjectPostProcessor(proc);
            lof.RegisterObjectDefinition("notToBeProxied", not);

            object foo = lof["notToBeProxied"];
            Assert.IsNotNull(foo);
            Assert.AreEqual(typeof(TestObject), foo.GetType());
            TestObject to = (TestObject)foo;
            Assert.AreEqual("Rick", to.Name);
        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:20,代码来源:DefaultListableObjectFactoryTests.cs

示例6: SPR_1077

        public void SPR_1077()
        {
            DisposableTestObject sing = null;
            using (DefaultListableObjectFactory lof = new DefaultListableObjectFactory())
            {
                RootObjectDefinition singleton
                    = new RootObjectDefinition(typeof(DisposableTestObject));
                MutablePropertyValues sprops = new MutablePropertyValues();
                sprops.Add("name", "Rick");
                singleton.PropertyValues = sprops;
                lof.RegisterObjectDefinition("singleton", singleton);

                RootObjectDefinition prototype
                    = new RootObjectDefinition(typeof(TestObject));
                MutablePropertyValues pprops = new MutablePropertyValues();
                pprops.Add("name", "Jenny");
                // prototype has dependency on a singleton...
                pprops.Add("spouse", new RuntimeObjectReference("singleton"));
                prototype.PropertyValues = pprops;
                prototype.IsSingleton = false;
                lof.RegisterObjectDefinition("prototype", prototype);

                sing = (DisposableTestObject)lof.GetObject("singleton");

                lof.GetObject("prototype");
                lof.GetObject("prototype");
                lof.GetObject("prototype");
                lof.GetObject("prototype");
            }
            Assert.AreEqual(1, sing.NumTimesDisposed);
        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:31,代码来源:DefaultListableObjectFactoryTests.cs

示例7: TestIInstantiationAwareObjectPostProcessorsInterception

        public void TestIInstantiationAwareObjectPostProcessorsInterception()
        {
            ProxyingInstantiationAwareObjectPostProcessorStub proc
                = new ProxyingInstantiationAwareObjectPostProcessorStub("TheAgony");

            MutablePropertyValues props = new MutablePropertyValues();
            props.Add("Name", "Rick");
            RootObjectDefinition toBeProxied
                = new RootObjectDefinition(typeof(TestObject), props);

            DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
            lof.AddObjectPostProcessor(proc);
            lof.RegisterObjectDefinition("toBeProxied", toBeProxied);

            object proxy = lof["toBeProxied"];
            Assert.IsNotNull(proxy);
            Assert.AreEqual("TheAgony", proxy);
        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:18,代码来源:DefaultListableObjectFactoryTests.cs

示例8: WithEnvironmentPropertyNotUsed

        public void WithEnvironmentPropertyNotUsed()
        {
            StaticApplicationContext ac = new StaticApplicationContext();
            MutablePropertyValues pvs = new MutablePropertyValues();
            pvs.Add("touchy", "${PROCESSOR_ARCHITECTURE}");
            ac.RegisterSingleton("to", typeof (TestObject), pvs);

            pvs = new MutablePropertyValues();
            NameValueCollection nvc = new NameValueCollection();
            nvc.Add("PROCESSOR_ARCHITECTURE", "G5");
            pvs.Add("properties", nvc);
            ac.RegisterSingleton("configurer", typeof (PropertyPlaceholderConfigurer), pvs);
            ac.Refresh();

            TestObject to = (TestObject) ac["to"];
            Assert.AreEqual("G5", to.Touchy, "Fallback mode is not respecting previously set values.");
        }
开发者ID:tobi-tobsen,项目名称:spring-net,代码行数:17,代码来源:PropertyPlaceholderConfigurerTests.cs

示例9: CreateObjectWithMixOfIndexedAndTwoNamedSameTypeCtorArguments

        public void CreateObjectWithMixOfIndexedAndTwoNamedSameTypeCtorArguments()
        {
            // this object will be passed in as a named constructor argument
            string expectedCompany = "Griffin's Foosball Arcade";
            MutablePropertyValues autoProps = new MutablePropertyValues();
            autoProps.Add(new PropertyValue("Company", expectedCompany));
            RootObjectDefinition autowired = new RootObjectDefinition(typeof(NestedTestObject), autoProps);

            // this object will be passed in as a named constructor argument
            string expectedLawyersCompany = "Pollack, Pounce, & Pulverise";
            MutablePropertyValues lawyerProps = new MutablePropertyValues();
            lawyerProps.Add(new PropertyValue("Company", expectedLawyersCompany));
            RootObjectDefinition lawyer = new RootObjectDefinition(typeof(NestedTestObject), lawyerProps);

            // this simple string object will be passed in as an indexed constructor argument
            string expectedName = "Bingo";

            // this simple integer object will be passed in as a named constructor argument
            int expectedAge = 1023;

            ConstructorArgumentValues values = new ConstructorArgumentValues();

            // lets mix the order up a little...
            values.AddNamedArgumentValue("age", expectedAge);
            values.AddIndexedArgumentValue(0, expectedName);
            values.AddNamedArgumentValue("doctor", new RuntimeObjectReference("a_doctor"));
            values.AddNamedArgumentValue("lawyer", new RuntimeObjectReference("a_lawyer"));

            RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), values, new MutablePropertyValues());

            DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
            // the object we're attempting to resolve...
            fac.RegisterObjectDefinition("foo", def);
            // the object that will be looked up and passed as a named parameter to a ctor call...
            fac.RegisterObjectDefinition("a_doctor", autowired);
            // another object that will be looked up and passed as a named parameter to a ctor call...
            fac.RegisterObjectDefinition("a_lawyer", lawyer);

            ITestObject foo = fac["foo"] as ITestObject;
            Assert.IsNotNull(foo, "Couldn't pull manually registered instance out of the factory.");
            Assert.AreEqual(expectedName, foo.Name, "Dependency 'name' was not resolved an indexed ctor arg.");
            Assert.AreEqual(expectedAge, foo.Age, "Dependency 'age' was not resolved using a named ctor arg.");
            Assert.AreEqual(expectedCompany, foo.Doctor.Company, "Dependency 'doctor.Company' was not resolved using autowiring.");
            Assert.AreEqual(expectedLawyersCompany, foo.Lawyer.Company, "Dependency 'lawyer.Company' was not resolved using another named ctor arg.");
        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:45,代码来源:DefaultListableObjectFactoryTests.cs

示例10: RegisterExistingSingletonWithAutowire

 public void RegisterExistingSingletonWithAutowire()
 {
     DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
     MutablePropertyValues pvs = new MutablePropertyValues();
     pvs.Add("name", "Tony");
     pvs.Add("age", "48");
     RootObjectDefinition rod = new RootObjectDefinition(typeof(DependenciesObject), pvs, true);
     rod.DependencyCheck = DependencyCheckingMode.Objects;
     rod.AutowireMode = AutoWiringMode.ByType;
     lof.RegisterObjectDefinition("test", rod);
     object singletonObject = new TestObject();
     lof.RegisterSingleton("singletonObject", singletonObject);
     Assert.IsTrue(lof.ContainsObject("singletonObject"));
     Assert.IsTrue(lof.IsSingleton("singletonObject"));
     Assert.AreEqual(0, lof.GetAliases("singletonObject").Count);
     DependenciesObject test = (DependenciesObject)lof.GetObject("test");
     Assert.AreEqual(singletonObject, lof.GetObject("singletonObject"));
     Assert.AreEqual(singletonObject, test.Spouse);
 }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:19,代码来源:DefaultListableObjectFactoryTests.cs

示例11: WithExpressionProperty

        public void WithExpressionProperty()
        {
            StaticApplicationContext ac = new StaticApplicationContext();
            MutablePropertyValues pvs = new MutablePropertyValues();
            pvs.Add("age", new ExpressionHolder("${age}"));
            ac.RegisterSingleton("to1", typeof(TestObject), pvs);

            pvs = new MutablePropertyValues();
            NameValueCollection nvc = new NameValueCollection();
            nvc.Add("age", "'0x7FFFFFFF'");
            pvs.Add("properties", nvc);
            ac.RegisterSingleton("configurer", typeof(PropertyPlaceholderConfigurer), pvs);
            ac.Refresh();

            TestObject to1 = (TestObject)ac.GetObject("to1");;
            Assert.AreEqual(2147483647, to1.Age);
        }
开发者ID:tobi-tobsen,项目名称:spring-net,代码行数:17,代码来源:PropertyPlaceholderConfigurerTests.cs

示例12: OverridePropertyReference

        public void OverridePropertyReference()
        {
            StaticApplicationContext ac = new StaticApplicationContext();

            MutablePropertyValues pvs = new MutablePropertyValues();
            pvs.Add("Spouse", new RuntimeObjectReference("spouse1"));
            ac.RegisterSingleton("tb1", typeof(TestObject), pvs);

            ac.RegisterSingleton("spouse1", typeof(TestObject), new MutablePropertyValues());
            ac.RegisterSingleton("spouse2", typeof(TestObject), new MutablePropertyValues());

            pvs = new MutablePropertyValues();
            pvs.Add("Properties", "<spring-config><add key=\"tb1.Spouse\" value=\"spouse2\"/></spring-config>");
            ac.RegisterSingleton("configurer", typeof(PropertyOverrideConfigurer), pvs);

            ac.Refresh();
            TestObject tb1 = (TestObject)ac.GetObject("tb1");
            TestObject spouse2 = (TestObject)ac.GetObject("spouse2");
            Assert.AreEqual(spouse2, tb1.Spouse);
        }
开发者ID:adamlepkowski,项目名称:spring-net,代码行数:20,代码来源:PropertyOverrideConfigurerTests.cs

示例13: AutowireWithUnsatisfiedConstructorDependency

 public void AutowireWithUnsatisfiedConstructorDependency()
 {
     DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
     MutablePropertyValues pvs = new MutablePropertyValues();
     pvs.Add(new PropertyValue("name", "Rod"));
     RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject), pvs);
     lof.RegisterObjectDefinition("rod", rod);
     Assert.AreEqual(1, lof.ObjectDefinitionCount);
     lof.Autowire(typeof(UnsatisfiedConstructorDependency), AutoWiringMode.AutoDetect, true);
     Assert.Fail("Should have unsatisfied constructor dependency on SideEffectObject");
 }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:11,代码来源:DefaultListableObjectFactoryTests.cs

示例14: WithUnresolvablePlaceholder

 public void WithUnresolvablePlaceholder()
 {
     StaticApplicationContext ac = new StaticApplicationContext();
     MutablePropertyValues pvs = new MutablePropertyValues();
     pvs.Add("name", "${ref}");
     ac.RegisterSingleton("tb", typeof (TestObject), pvs);
     ac.RegisterSingleton("configurer", typeof (PropertyPlaceholderConfigurer), null);
     try
     {
         ac.Refresh();
         Assert.Fail("Should have thrown ObjectDefinitionStoreException");
     }
     catch (ObjectDefinitionStoreException ex)
     {
         // expected
         Assert.IsTrue(ex.Message.IndexOf("ref") != -1);
     }
 }
开发者ID:tobi-tobsen,项目名称:spring-net,代码行数:18,代码来源:PropertyPlaceholderConfigurerTests.cs

示例15: OverridePropertyExpression

        public void OverridePropertyExpression()
        {
            StaticApplicationContext ac = new StaticApplicationContext();

            MutablePropertyValues pvs = new MutablePropertyValues();
            pvs.Add("Age", new ExpressionHolder("26+1"));
            ac.RegisterSingleton("tb1", typeof(TestObject), pvs);

            pvs = new MutablePropertyValues();
            pvs.Add("Properties", "<spring-config><add key=\"tb1.Age\" value=\"26-1\"/></spring-config>");
            ac.RegisterSingleton("configurer", typeof(PropertyOverrideConfigurer), pvs);

            ac.Refresh();
            TestObject tb1 = (TestObject)ac.GetObject("tb1");
            Assert.AreEqual(25, tb1.Age);
        }
开发者ID:adamlepkowski,项目名称:spring-net,代码行数:16,代码来源:PropertyOverrideConfigurerTests.cs


注:本文中的MutablePropertyValues.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。