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


C# ConstructorArgumentValues.AddNamedArgumentValue方法代码示例

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


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

示例1: ChokesOnCircularReferenceToPlaceHolder

        public void ChokesOnCircularReferenceToPlaceHolder()
        {
            RootObjectDefinition def = new RootObjectDefinition();
            def.ObjectType = typeof (TestObject);
            ConstructorArgumentValues args = new ConstructorArgumentValues();
            args.AddNamedArgumentValue("name", "${foo}");
            def.ConstructorArgumentValues = args;

            NameValueCollection properties = new NameValueCollection();
            const string expectedName = "ba${foo}r";
            properties.Add("foo", expectedName);

            IConfigurableListableObjectFactory mock = (IConfigurableListableObjectFactory) mocks.CreateMock(typeof (IConfigurableListableObjectFactory));
            Expect.Call(mock.GetObjectDefinitionNames()).Return(new string[] {"foo"});
            Expect.Call(mock.GetObjectDefinition(null)).IgnoreArguments().Return(def);
            mocks.ReplayAll();

            PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
            cfg.Properties = properties;
            try
            {
                cfg.PostProcessObjectFactory(mock);
                Assert.Fail("Should have raised an ObjectDefinitionStoreException by this point.");
            }
            catch (ObjectDefinitionStoreException)
            {
            }
            mocks.VerifyAll();
        }
开发者ID:tobi-tobsen,项目名称:spring-net,代码行数:29,代码来源:PropertyPlaceholderConfigurerTests.cs

示例2: CreateObjectWithMixOfNamedAndIndexedCtorArguments

        public void CreateObjectWithMixOfNamedAndIndexedCtorArguments()
        {
            string expectedName = "Bingo";
            int expectedAge = 1023;
            ConstructorArgumentValues values = new ConstructorArgumentValues();
            values.AddNamedArgumentValue("age", expectedAge);
            values.AddIndexedArgumentValue(0, expectedName);
            RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), values, new MutablePropertyValues());
            DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
            fac.RegisterObjectDefinition("foo", def);

            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.");
        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:16,代码来源:DefaultListableObjectFactoryTests.cs

示例3: CreateObjectWithCtorArgsOverrided

        public void CreateObjectWithCtorArgsOverrided()
        {
            using (DefaultListableObjectFactory lof = new DefaultListableObjectFactory())
            {
                ConstructorArgumentValues arguments = new ConstructorArgumentValues();
                arguments.AddNamedArgumentValue("age", 27);
                arguments.AddNamedArgumentValue("name", "Bruno");
                RootObjectDefinition singleton = new RootObjectDefinition(typeof(TestObject), arguments, new MutablePropertyValues());
                singleton.IsSingleton = true;
                lof.RegisterObjectDefinition("singleton", singleton);

                TestObject to = lof.CreateObject("singleton", typeof(TestObject), new object[] { "Mark", 35 }) as TestObject;
                Assert.IsNotNull(to);
                Assert.AreEqual(35, to.Age);
                Assert.AreEqual("Mark", to.Name);

                TestObject to2 = lof.CreateObject("singleton", null, null) as TestObject;
                Assert.IsNotNull(to2);
                Assert.AreEqual(27, to2.Age);
                Assert.AreEqual("Bruno", to2.Name);
            }
        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:22,代码来源:DefaultListableObjectFactoryTests.cs

示例4: ProxyTransparentProxy

        public void ProxyTransparentProxy()
        {
            DefaultListableObjectFactory of = new DefaultListableObjectFactory();

            ConstructorArgumentValues ctorArgs = new ConstructorArgumentValues();
            ctorArgs.AddNamedArgumentValue("objectType", typeof(ITestObject));
            of.RegisterObjectDefinition("bar", new RootObjectDefinition(typeof(TransparentProxyFactory), ctorArgs, null));

            TestAutoProxyCreator apc = new TestAutoProxyCreator(of);
            of.AddObjectPostProcessor(apc);

            ITestObject o = of.GetObject("bar") as ITestObject;
            Assert.IsTrue(AopUtils.IsAopProxy(o));

            // ensure interceptors get called
            o.Foo();
            Assert.AreEqual(1, apc.NopInterceptor.Count);
            IAdvised advised = (IAdvised) o;

            // ensure target was called
            object target = advised.TargetSource.GetTarget();
            Assert.AreEqual(1, TransparentProxyFactory.GetRealProxy(target).Count);
        }
开发者ID:smnbss,项目名称:spring-net,代码行数:23,代码来源:AbstractAutoProxyCreatorTests.cs

示例5: UsingCustomMarkers

        public void UsingCustomMarkers()
        {
            RootObjectDefinition def = new RootObjectDefinition();
            def.ObjectType = typeof (TestObject);
            ConstructorArgumentValues args = new ConstructorArgumentValues();
            args.AddNamedArgumentValue("name", "#hope.floats#");
            def.ConstructorArgumentValues = args;

            NameValueCollection properties = new NameValueCollection();
            const string expectedName = "Rick";
            properties.Add("hope.floats", expectedName);

            IConfigurableListableObjectFactory mock = (IConfigurableListableObjectFactory) mocks.CreateMock(typeof (IConfigurableListableObjectFactory));
            Expect.Call(mock.GetObjectDefinitionNames()).Return(new string[] {"foo"});
            Expect.Call(mock.GetObjectDefinition(null)).IgnoreArguments().Return(def);
            mocks.ReplayAll();

            PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
            cfg.PlaceholderPrefix = cfg.PlaceholderSuffix = "#";
            cfg.Properties = properties;
            cfg.PostProcessObjectFactory(mock);

            mocks.VerifyAll();

            Assert.AreEqual(expectedName,
                def.ConstructorArgumentValues.GetNamedArgumentValue("name").Value,
                "Named argument placeholder value was not replaced.");
        }
开发者ID:tobi-tobsen,项目名称:spring-net,代码行数:28,代码来源:PropertyPlaceholderConfigurerTests.cs

示例6: ParseConstructorArgElement

        /// <summary>
        /// Parse a constructor-arg element.
        /// </summary>
        /// <param name="name">
        /// The name of the object (definition) associated with the ctor arg.
        /// </param>
        /// <param name="arguments">
        /// The list of constructor args associated with the object (definition).
        /// </param>
        /// <param name="element">
        /// The name of the element containing the ctor arg definition.
        /// </param>
        /// <param name="parserContext">
        /// The namespace-aware parser.
        /// </param>
        protected virtual void ParseConstructorArgElement(
            string name, ConstructorArgumentValues arguments, XmlElement element, ParserContext parserContext)
        {
            object val = ParsePropertyValue(element, name, parserContext);
            string indexAttr = GetAttributeValue(element, ObjectDefinitionConstants.IndexAttribute);
            string typeAttr = GetAttributeValue(element, ObjectDefinitionConstants.TypeAttribute);
            string nameAttr = GetAttributeValue(element, ObjectDefinitionConstants.ArgumentNameAttribute);

            // only one of the 'index' or 'name' attributes can be present
            if (StringUtils.HasText(indexAttr)
                && StringUtils.HasText(nameAttr))
            {
                throw new ObjectDefinitionStoreException(
                    parserContext.ReaderContext.Resource, name,
                    "Only one of the 'index' or 'name' attributes can be present per constructor argument.");
            }
            if (StringUtils.HasText(indexAttr))
            {
                try
                {
                    int index = int.Parse(indexAttr, CultureInfo.CurrentCulture);
                    if (index < 0)
                    {
                        throw new ObjectDefinitionStoreException(
                            parserContext.ReaderContext.Resource, name,
                            "'index' cannot be lower than 0");
                    }
                    if (StringUtils.HasText(typeAttr))
                    {
                        arguments.AddIndexedArgumentValue(index, val, typeAttr);
                    }
                    else
                    {
                        arguments.AddIndexedArgumentValue(index, val);
                    }
                }
                catch (FormatException)
                {
                    throw new ObjectDefinitionStoreException(
                        parserContext.ReaderContext.Resource, name,
                        "Attribute 'index' of tag 'constructor-arg' must be an integer value.");
                }
            }
            else if (StringUtils.HasText(nameAttr))
            {
                if (StringUtils.HasText(typeAttr))
                {
                    if (log.IsWarnEnabled)
                    {
                        log.Warn("The 'type' attribute is redundant when the 'name' attribute has been used on a constructor argument element.");
                    }
                }
                arguments.AddNamedArgumentValue(nameAttr, val);
            }
            else
            {
                if (StringUtils.HasText(typeAttr))
                {
                    arguments.AddGenericArgumentValue(val, typeAttr);
                }
                else
                {
                    arguments.AddGenericArgumentValue(val);
                }
            }
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:81,代码来源:ObjectsNamespaceParser.cs

示例7: AddNamedArgumentWithEmptyStringName

		public void AddNamedArgumentWithEmptyStringName()
		{
			ConstructorArgumentValues values = new ConstructorArgumentValues();
			values.AddNamedArgumentValue(string.Empty, 1);
		}
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:5,代码来源:ConstructorArgumentValuesTests.cs

示例8: GetArgumentValue

		public void GetArgumentValue()
		{
			ConstructorArgumentValues values = new ConstructorArgumentValues();
			Assert.IsNull(values.GetArgumentValue(0, typeof (object)), "Mmm... managed to get a non null instance back from an empty instance.");
			values.AddGenericArgumentValue(DBNull.Value, typeof (DBNull).FullName);
			values.AddNamedArgumentValue("foo", DBNull.Value);
			values.AddIndexedArgumentValue(16, DBNull.Value, typeof (DBNull).FullName);
			Assert.IsNull(values.GetArgumentValue(100, typeof (string)), "Mmm... managed to get a non null instance back from an instance that should have now't with the specified Type.");
			ConstructorArgumentValues.ValueHolder value =
				values.GetArgumentValue(-3, typeof (DBNull));
			Assert.IsNotNull(value, "Stored a value of a specified Type at a specified index, but got null when retrieving it using the wrong index but the correct Type.");
			Assert.AreSame(DBNull.Value, value.Value, "The retrieved value was not the exact same instance as was added.");
			
			value = values.GetArgumentValue("foo", typeof (DBNull));
			Assert.IsNotNull(value, "Stored a value of a specified Type under a name, but got null when retrieving it using the wrong name but the correct Type.");
			Assert.AreSame(DBNull.Value, value.Value, "The retrieved value was not the exact same instance as was added.");
		}
开发者ID:spring-projects,项目名称:spring-net,代码行数:17,代码来源:ConstructorArgumentValuesTests.cs

示例9: NamedArgumentsAreCaseInsensitive

		public void NamedArgumentsAreCaseInsensitive()
		{
			ConstructorArgumentValues values = new ConstructorArgumentValues();
			values.AddNamedArgumentValue("foo", "sball");
			Assert.AreEqual(1, values.NamedArgumentValues.Count, "Added one named argument but it doesn't seem to have been added to the named arguments collection.");
			Assert.AreEqual(1, values.ArgumentCount, "Added one named argument but it doesn't seem to be reflected in the overall argument count.");
			Assert.IsTrue(values.ContainsNamedArgument("FOo"), "Mmm, the ContainsNamedArgument() method eveidently IS case sensitive (which is wrong).");
			ConstructorArgumentValues.ValueHolder arg = values.GetNamedArgumentValue("fOo");
			Assert.IsNotNull(arg, "The named argument previously added could not be pulled from the ctor arg collection.");
			Assert.AreEqual("sball", arg.Value, "The value of the named argument passed in is not the same as the one that was pulled out.");
		}
开发者ID:spring-projects,项目名称:spring-net,代码行数:11,代码来源:ConstructorArgumentValuesTests.cs

示例10: AddNamedArgumentWithEmptyStringName

		public void AddNamedArgumentWithEmptyStringName()
		{
			ConstructorArgumentValues values = new ConstructorArgumentValues();
            Assert.Throws<ArgumentNullException>(() => values.AddNamedArgumentValue(string.Empty, 1));
		}
开发者ID:spring-projects,项目名称:spring-net,代码行数:5,代码来源:ConstructorArgumentValuesTests.cs

示例11: AddNamedArgumentWithWhitespaceStringName

		public void AddNamedArgumentWithWhitespaceStringName()
		{
			ConstructorArgumentValues values = new ConstructorArgumentValues();
            Assert.Throws<ArgumentNullException>(() => values.AddNamedArgumentValue(Environment.NewLine + "  ", 1));
		}
开发者ID:spring-projects,项目名称:spring-net,代码行数:5,代码来源:ConstructorArgumentValuesTests.cs

示例12: AddNamedArgumentWithNullName

		public void AddNamedArgumentWithNullName()
		{
			ConstructorArgumentValues values = new ConstructorArgumentValues();
            Assert.Throws<ArgumentNullException>(() => values.AddNamedArgumentValue(null, 1));
		}
开发者ID:spring-projects,项目名称:spring-net,代码行数:5,代码来源:ConstructorArgumentValuesTests.cs

示例13: ReplacesNamedCtorArgument

		public void ReplacesNamedCtorArgument()
		{
			RootObjectDefinition def = new RootObjectDefinition();
			def.ObjectType = typeof (TestObject);
			ConstructorArgumentValues args = new ConstructorArgumentValues();
			args.AddNamedArgumentValue("name", "${hope.floats}");
			def.ConstructorArgumentValues = args;

			NameValueCollection properties = new NameValueCollection();
			const string expectedName = "Rick";
			properties.Add("hope.floats", expectedName);

			IConfigurableListableObjectFactory mock = mocks.StrictMock<IConfigurableListableObjectFactory>();
			Expect.Call(mock.GetObjectDefinitionNames(false)).Return(new string[] {"foo"});
			Expect.Call(mock.GetObjectDefinition(null, false)).IgnoreArguments().Return(def);
            Expect.Call(delegate { mock.AddEmbeddedValueResolver(null); }).IgnoreArguments();
			mocks.ReplayAll();
            
            PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();
			cfg.Properties = properties;
			cfg.PostProcessObjectFactory(mock);

			mocks.VerifyAll();

			Assert.AreEqual(expectedName,
				def.ConstructorArgumentValues.GetNamedArgumentValue("name").Value,
				"Named argument placeholder value was not replaced.");
		}
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:28,代码来源:PropertyPlaceholderConfigurerTests.cs

示例14: AddNamedArgumentWithWhitespaceStringName

		public void AddNamedArgumentWithWhitespaceStringName()
		{
			ConstructorArgumentValues values = new ConstructorArgumentValues();
			values.AddNamedArgumentValue(Environment.NewLine + "  ", 1);
		}
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:5,代码来源:ConstructorArgumentValuesTests.cs

示例15: CreateObjectWithMixOfNamedAndIndexedAndAutowiredCtorArguments

        public void CreateObjectWithMixOfNamedAndIndexedAndAutowiredCtorArguments()
        {
            string expectedCompany = "Griffin's Foosball Arcade";
            MutablePropertyValues autoProps = new MutablePropertyValues();
            autoProps.Add(new PropertyValue("Company", expectedCompany));
            RootObjectDefinition autowired = new RootObjectDefinition(typeof(NestedTestObject), autoProps);

            string expectedName = "Bingo";
            int expectedAge = 1023;
            ConstructorArgumentValues values = new ConstructorArgumentValues();
            values.AddNamedArgumentValue("age", expectedAge);
            values.AddIndexedArgumentValue(0, expectedName);
            RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), values, new MutablePropertyValues());
            def.AutowireMode = AutoWiringMode.Constructor;
            DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
            fac.RegisterObjectDefinition("foo", def);
            fac.RegisterObjectDefinition("doctor", autowired);

            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.");
        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:24,代码来源:DefaultListableObjectFactoryTests.cs


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