本文整理汇总了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"));
}
}