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


C# RelayTwo.AppendTables方法代码示例

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


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

示例1: LoadFromSeveralPartialDatabases

		public void LoadFromSeveralPartialDatabases()
        {
			{
				RelayTwo r1 = new RelayTwo();
				TableTwo t = r1.CreateTable("Table");
				
				t.AddField<string>("animal");
				t.AddField<int>("age");
				
				TableRow row0 = t.CreateRow();
				row0.Set("animal", "rabbit");
				row0.Set("age", 5);
				
				TableRow row1 = t.CreateRow();
				row1.Set("animal", "salmon");
				row1.Set("age", 10);
				
				TableRow row2 = t.CreateRow();
				row2.Set("animal", "spider");
				row2.Set("age", 1);
				
				r1.SaveAll("r1.json");
			}
			
			{
				RelayTwo r2 = new RelayTwo();
				TableTwo t = r2.CreateTable("Table");
				
				t.AddField<string>("animal");
				t.AddField<bool>("carnivore");
				
				TableRow row0 = t.CreateRow();
				row0.Set("animal", "mouse");
				row0.Set("carnivore", false);
				
				TableRow row1 = t.CreateRow();
				row1.Set("animal", "fox");
				row1.Set("carnivore", true);
				
				r2.SaveAll("r2.json");
			}
		
			{
				RelayTwo combined = new RelayTwo();
				combined.AppendTables("r1.json");
                combined.AppendTables("r2.json");
				
				Assert.AreEqual(1, combined.tables.Count);
				
				TableTwo t = combined.GetTable("Table");
				Assert.AreEqual(3, t.fieldNames.Length);
				
				Console.WriteLine("The merged table contains the following rows: ");
				foreach(int rowIndex in t.GetIndexesOfPopulatedRows())
				{
					TableRow row = t[rowIndex];
					Console.WriteLine("Values in row " + rowIndex);
					foreach(string s in row.valuesAsStrings) {
						Console.Write(s + ", ");
					}
                    Console.WriteLine("\n");
				}
				Assert.AreEqual(5, t.GetIndexesOfPopulatedRows().Length);
				
				TableRow rabbit = t[0];
				TableRow salmon = t[1];
				TableRow spider = t[2];
				TableRow mouse = t[3];
				TableRow fox = t[4];
				
				Assert.AreEqual("rabbit", rabbit.Get<string>("animal"));
				Assert.AreEqual("salmon", salmon.Get<string>("animal"));
				Assert.AreEqual("spider", spider.Get<string>("animal"));
				Assert.AreEqual("mouse", mouse.Get<string>("animal"));
				Assert.AreEqual("fox", fox.Get<string>("animal"));
				
				Assert.AreEqual(5, rabbit.Get<int>("age"));
				Assert.AreEqual(10, salmon.Get<int>("age"));
				Assert.AreEqual(1, spider.Get<int>("age"));
                Assert.Throws<RelayException>(() =>
                {
                    Assert.AreEqual(0, mouse.Get<int>("age"));
                });
                Assert.Throws<RelayException>(() =>
                {
                    Assert.AreEqual(0, fox.Get<int>("age"));
                });
				Assert.AreEqual(true, fox.Get<bool>("carnivore"));
			}
		}
开发者ID:substans,项目名称:Relay,代码行数:90,代码来源:RelayTwoTests.cs


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