本文整理汇总了C#中Spring.Objects.Factory.Xml.XmlObjectFactory.GetAliases方法的典型用法代码示例。如果您正苦于以下问题:C# XmlObjectFactory.GetAliases方法的具体用法?C# XmlObjectFactory.GetAliases怎么用?C# XmlObjectFactory.GetAliases使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Spring.Objects.Factory.Xml.XmlObjectFactory
的用法示例。
在下文中一共展示了XmlObjectFactory.GetAliases方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AutoAliasing
public void AutoAliasing()
{
IResource resource = new ReadOnlyXmlTestResource("collections.xml", GetType());
XmlObjectFactory xof = new XmlObjectFactory(resource);
IList<string> objectNames = xof.GetObjectDefinitionNames();
TestObject tb1 = (TestObject) xof.GetObject("aliased");
TestObject alias1 = (TestObject) xof.GetObject("myalias");
Assert.IsTrue(tb1 == alias1);
IList<string> tb1Aliases = xof.GetAliases("aliased");
Assert.AreEqual(1, tb1Aliases.Count);
Assert.IsTrue(tb1Aliases.Contains("myalias"));
Assert.IsTrue(objectNames.Contains("aliased"));
Assert.IsFalse(objectNames.Contains("myalias"));
TestObject tb2 = (TestObject) xof.GetObject("multiAliased");
TestObject alias2 = (TestObject) xof.GetObject("alias1");
TestObject alias3 = (TestObject) xof.GetObject("alias2");
Assert.IsTrue(tb2 == alias2);
Assert.IsTrue(tb2 == alias3);
IList<string> tb2Aliases = xof.GetAliases("multiAliased");
Assert.AreEqual(2, tb2Aliases.Count);
Assert.IsTrue(tb2Aliases.Contains("alias1"));
Assert.IsTrue(tb2Aliases.Contains("alias2"));
Assert.IsTrue(objectNames.Contains("multiAliased"));
Assert.IsFalse(objectNames.Contains("alias1"));
Assert.IsFalse(objectNames.Contains("alias2"));
TestObject tb3 = (TestObject) xof.GetObject("aliasWithoutId1");
TestObject alias4 = (TestObject) xof.GetObject("aliasWithoutId2");
TestObject alias5 = (TestObject) xof.GetObject("aliasWithoutId3");
Assert.IsTrue(tb3 == alias4);
Assert.IsTrue(tb3 == alias5);
IList<string> tb3Aliases = xof.GetAliases("aliasWithoutId1");
Assert.AreEqual(2, tb2Aliases.Count);
Assert.IsTrue(tb3Aliases.Contains("aliasWithoutId2"));
Assert.IsTrue(tb3Aliases.Contains("aliasWithoutId3"));
Assert.IsTrue(objectNames.Contains("aliasWithoutId1"));
Assert.IsFalse(objectNames.Contains("aliasWithoutId2"));
Assert.IsFalse(objectNames.Contains("aliasWithoutId3"));
string className = typeof(TestObject).FullName;
string targetName = className + ObjectDefinitionReaderUtils.GENERATED_OBJECT_NAME_SEPARATOR + "0";
TestObject tb4 = (TestObject)xof.GetObject(targetName);
Assert.AreEqual(null, tb4.Name);
}