本文整理汇总了C#中Order.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# Order.Serialize方法的具体用法?C# Order.Serialize怎么用?C# Order.Serialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Order
的用法示例。
在下文中一共展示了Order.Serialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serialise
public void Serialise()
{
var order = new Order
{
OrderId = "1",
TableNumber = 5,
ServerName = "Dave",
TimeStamp = "12:00",
TimeToCook = "00:00",
Subtotal = 5.55M,
Total = 6.66M,
Tax = 1.11M,
Ingredients = new[] {"Pasta", "Fish"},
Paid = true,
Items = new[]
{
new OrderItem {ItemName = "5", Qty = 2, Price = 5.00M},
new OrderItem {ItemName = "6", Qty = 3, Price = 6.00M},
}
};
var json = order.Serialize();
Assert.That(json.GetValue("OrderId").ToString(), Is.EqualTo("1"));
Assert.That(json.GetValue("TableNumber").ToObject<int>(), Is.EqualTo(5));
Assert.That(json.GetValue("ServerName").ToString(), Is.EqualTo("Dave"));
Assert.That(json.GetValue("TimeStamp").ToString(), Is.EqualTo("12:00"));
Assert.That(json.GetValue("TimeToCook").ToString(), Is.EqualTo("00:00"));
Assert.That(json.GetValue("Subtotal").ToObject<decimal>(), Is.EqualTo(5.55M));
Assert.That(json.GetValue("Total").ToObject<decimal>(), Is.EqualTo(6.66M));
Assert.That(json.GetValue("Tax").ToObject<decimal>(), Is.EqualTo(1.11M));
Assert.That(json.GetValue("Paid").ToObject<bool>(), Is.EqualTo(true));
var ingredients = json.GetValue("Ingredients");
Assert.That(ingredients[0].ToString(), Is.EqualTo("Pasta"));
Assert.That(ingredients[1].ToString(), Is.EqualTo("Fish"));
var items = json.GetValue("Items");
var item1 = items[0];
Assert.That(item1["ItemName"].ToObject<string>(), Is.EqualTo("5"));
Assert.That(item1["Qty"].ToObject<int>(), Is.EqualTo(2));
Assert.That(item1["Price"].ToObject<decimal>(), Is.EqualTo(5.00M));
var item2 = items[1];
Assert.That(item2["ItemName"].ToObject<string>(), Is.EqualTo("6"));
Assert.That(item2["Qty"].ToObject<int>(), Is.EqualTo(3));
Assert.That(item2["Price"].ToObject<decimal>(), Is.EqualTo(6.00M));
}