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


C# XmlObjectFactory.GetObjectDefinition方法代码示例

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


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

示例1: CanApplyConstructorArgsToAbstractType

        public void CanApplyConstructorArgsToAbstractType()
        {
            IResource resource = new ReadOnlyXmlTestResource("ctor-args.xml", GetType());
            XmlObjectFactory xof = new XmlObjectFactory(resource);
            TestObject rod = (TestObject)xof.GetObject("rod");
            Assert.AreEqual(1, rod.Age);

            RootObjectDefinition def = (RootObjectDefinition) xof.GetObjectDefinition("rod");
            ConstructorResolver resolver = new ConstructorResolver(xof, xof, new SimpleInstantiationStrategy(), 
                                                    new ObjectDefinitionValueResolver(xof));
            
            ConstructorInstantiationInfo ci = resolver.GetConstructorInstantiationInfo("rod", def, null, null);

            AbstractObjectDefinition objDef = (AbstractObjectDefinition)xof.GetObjectDefinition("foo");
            objDef.IsAbstract = false;

            TestObject foo = (TestObject) xof.GetObject("foo");


            Assert.AreEqual(2, foo.Age);
        }
开发者ID:fgq841103,项目名称:spring-net,代码行数:21,代码来源:XmlObjectCollectionTests.cs

示例2: ReadsMongoAttributesCorrectly

        public void ReadsMongoAttributesCorrectly()
        {
            string xml = @"<?xml version='1.0' encoding='UTF-8' ?>
                           <objects xmlns='http://www.springframework.net' xmlns:mongo='http://www.springframework.net/mongo'>
                                <mongo:mongo url='mongodb://localhost' write-concern='WMajority' />
                           </objects>";
            var factory = new XmlObjectFactory(new StringResource(xml, Encoding.UTF8));

            Assert.That(factory.GetObjectDefinitionNames(), Contains.Item("Mongo"));

            IObjectDefinition definition = factory.GetObjectDefinition("Mongo");

            Assert.That(definition, Is.Not.Null);

            IList<PropertyValue> values = definition.PropertyValues.PropertyValues;

            Assert.That(values, Contains.Item(new PropertyValue("WriteConcern", "WMajority")));
            Assert.That(values, Contains.Item(new PropertyValue("Url", "mongodb://localhost")));
        }
开发者ID:thomast74,项目名称:spring-net-data-mongodb,代码行数:19,代码来源:MongoFactoryParserTests.cs

示例3: _TypedStringValueIsPickedUp

        private void _TypedStringValueIsPickedUp(out Stream stream)
        {
            const string xml =
                @"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
	xsi:schemaLocation='http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd'>
	<object id='golyadkin' type='Spring.Objects.TestObject, Spring.Core.Tests'>
		<property name='Hats'><value type='string[]'>trilby,fedora</value></property>
	</object>
</objects>";
            stream = new MemoryStream(Encoding.UTF8.GetBytes(xml));
            XmlObjectFactory fac = new XmlObjectFactory(new InputStreamResource(stream, string.Empty));
            IObjectDefinition def = fac.GetObjectDefinition("golyadkin");
            PropertyValue value = def.PropertyValues.GetPropertyValue("Hats");
            Assert.AreEqual(typeof(TypedStringValue), value.Value.GetType());
            TestObject obj = (TestObject) fac.GetObject("golyadkin");
            Assert.IsTrue(ArrayUtils.AreEqual(new string[] {"trilby", "fedora"}, obj.Hats));
        }
开发者ID:fgq841103,项目名称:spring-net,代码行数:18,代码来源:XmlObjectFactoryTests.cs

示例4: ParsesNamedCtorArgsCorrectly

 public void ParsesNamedCtorArgsCorrectly()
 {
     XmlObjectFactory fac = new XmlObjectFactory(
         new ReadOnlyXmlTestResource("constructor-arg.xml", GetType()));
     IObjectDefinition obj = fac.GetObjectDefinition("ctorArgsAllNamed");
     Assert.AreEqual(2, obj.ConstructorArgumentValues.NamedArgumentValues.Count,
                     "Should have parsed 2 named ctor args.");
     ConstructorArgumentValues.ValueHolder nameArg = obj.ConstructorArgumentValues.GetNamedArgumentValue("name");
     Assert.IsNotNull(nameArg, "Should have parsed the 'name' ctor arg.");
     Assert.AreEqual("Isaac Newton", nameArg.Value);
     ConstructorArgumentValues.ValueHolder ageArg = obj.ConstructorArgumentValues.GetNamedArgumentValue("age");
     Assert.IsNotNull(ageArg, "Should have parsed the 'age' ctor arg.");
     Assert.AreEqual("87", ageArg.Value);
 }
开发者ID:fgq841103,项目名称:spring-net,代码行数:14,代码来源:XmlObjectFactoryTests.cs

示例5: SetsUpMongoDbFactoryUsingAMongoConnectStringWithoutCredentials

        public void SetsUpMongoDbFactoryUsingAMongoConnectStringWithoutCredentials()
        {
            string xml = @"<?xml version='1.0' encoding='UTF-8' ?>
                           <objects xmlns='http://www.springframework.net' xmlns:mongo='http://www.springframework.net/mongo'>
                             <mongo:db-factory url='mongodb://localhost/database' />
                           </objects>";
            var factory = new XmlObjectFactory(new StringResource(xml, Encoding.UTF8));

            IObjectDefinition definition = factory.GetObjectDefinition("MongoDatabaseFactory");
            ConstructorArgumentValues constructorArguments = definition.ConstructorArgumentValues;

            Assert.That(constructorArguments.ArgumentCount, Is.EqualTo(1));

            var argument = constructorArguments.GetArgumentValue(0, typeof(MongoUrl));

            Assert.That(argument, Is.Not.Null);

            var dbFactory = factory.GetObject<IMongoDatabaseFactory>("MongoDatabaseFactory");
            var db = dbFactory.GetDatabase();

            Assert.That(db.Name, Is.EqualTo("database"));
        }
开发者ID:thomast74,项目名称:spring-net-data-mongodb,代码行数:22,代码来源:MongoDatabaseFactoryParserTests.cs


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