本文整理匯總了C#中System.Data.DataTable.GetStringRepresentation方法的典型用法代碼示例。如果您正苦於以下問題:C# DataTable.GetStringRepresentation方法的具體用法?C# DataTable.GetStringRepresentation怎麽用?C# DataTable.GetStringRepresentation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Data.DataTable
的用法示例。
在下文中一共展示了DataTable.GetStringRepresentation方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetStringRepresentation_WhenDbNull_PrintsNull
public void GetStringRepresentation_WhenDbNull_PrintsNull()
{
var table = new DataTable();
table.Columns.Add("id", typeof(int));
table.Columns.Add("name", typeof(string));
table.Columns.Add("very long column name", typeof(string));
table.Rows.Add(1, "f", "a");
table.Rows.Add(2, "the longest", DBNull.Value);
table.Rows.Add(3, "g", "c");
var rep = table.GetStringRepresentation();
rep.Should().Be(
"+----+-------------+-----------------------+" + Environment.NewLine +
"| id | name | very long column name |" + Environment.NewLine +
"+----+-------------+-----------------------+" + Environment.NewLine +
"| 1 | f | a |" + Environment.NewLine +
"| 2 | the longest | NULL |" + Environment.NewLine +
"| 3 | g | c |" + Environment.NewLine +
"+----+-------------+-----------------------+" + Environment.NewLine);
}
示例2: GetStringRepresentation_WhenCustomFormat_Success
public void GetStringRepresentation_WhenCustomFormat_Success()
{
var table = new DataTable();
table.Columns.Add("id", typeof(int));
table.Columns.Add("name", typeof(string));
table.Columns.Add("very long column name", typeof(double));
table.Rows.Add(1, "f", 1.0);
table.Rows.Add(2, "the longest", 2.3456);
table.Rows.Add(3, "g", -98765);
var rep = table.GetStringRepresentation(
new RightAlign("id"),
new CustomFormat("very long column name", "#.00"));
rep.Should().Be(
"+----+-------------+-----------------------+" + Environment.NewLine +
"| id | name | very long column name |" + Environment.NewLine +
"+----+-------------+-----------------------+" + Environment.NewLine +
"| 1 | f | 1.00 |" + Environment.NewLine +
"| 2 | the longest | 2.35 |" + Environment.NewLine +
"| 3 | g | -98765.00 |" + Environment.NewLine +
"+----+-------------+-----------------------+" + Environment.NewLine);
}
示例3: GetStringRepresentation_WhenTableWithoutRows_Success
public void GetStringRepresentation_WhenTableWithoutRows_Success()
{
var table = new DataTable();
table.Columns.Add("id", typeof(int));
table.Columns.Add("name", typeof(string));
table.Columns.Add("very long column name", typeof(string));
var rep = table.GetStringRepresentation();
rep.Should().Be(
"+----+------+-----------------------+" + Environment.NewLine +
"| id | name | very long column name |" + Environment.NewLine +
"+----+------+-----------------------+" + Environment.NewLine +
"+----+------+-----------------------+" + Environment.NewLine);
}
示例4: GetStringRepresentation_WhenTableWithoutColumns_Success
public void GetStringRepresentation_WhenTableWithoutColumns_Success()
{
var table = new DataTable();
var rep = table.GetStringRepresentation();
rep.Should().Be(
"+--+" + Environment.NewLine +
"| |" + Environment.NewLine +
"+--+" + Environment.NewLine +
"+--+" + Environment.NewLine);
}