当前位置:K88软件开发文章中心编程工具CodeSmith → 文章内容

CodeSmith 使用 XMLProperty

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-24 10:16:42

OrderDate: <%= MyPurchaseOrder.OrderDate %> Items: <% for (int i = 0; i < MyPurchaseOrder.Items.Count; i++) { %> <%= i %>: ItemName: <%= MyPurchaseOrder.Items[i].ItemName %> Description: <%= MyPurchaseOrder.Items[i].Description %> UnitPrice: <%= MyPurchaseOrder.Items[i].UnitPrice %> Quantity: <%= MyPurchaseOrder.Items[i].Quantity %> LineTotal: <%= MyPurchaseOrder.Items[i].LineTotal %> <% } %> SubTotal: <%= MyPurchaseOrder.SubTotal %> ShipCost: <%= MyPurchaseOrder.ShipCost %> TotalCost: <%= MyPurchaseOrder.TotalCost %>模板中定义的 XML 属性名为 MyPurchaseOrder 对应的 Schema 为 PurchaseOrder.xsd ,因此在代码模板可以通过 MyPurchaseOrder.ShipTo.Name 的格式来直接引用 XML Schema 中定义的元素,CoddSmith 也支持 IntelliSense。运行该模板,首先需要为 MyPurchaseOrder 选择合适的 XML 文件:如果选择的文件不符合指定的 XML Schema,CodeSmith 不允许选择该文件,本例使用预先定义的SamplePurchaseOrder.xml ,生成的文件如下:This file generated by CodeSmith on Saturday, 12 January 2013PurchaseOrder: Address: Name: Eric J. Smith Line1: 123 Test Dr. City: Dallas State: TX Zip: 75075 OrderDate: 05-01-2003 Items: 0: ItemName: Item #1 Description: Item #1 Description UnitPrice: 5.45 Quantity: 3 LineTotal: 16.35 1: ItemName: Item #2 Description: Item #2 Description UnitPrice: 12.75 Quantity: 8 LineTotal: 102.00 SubTotal: 45.23 ShipCost: 5.23 TotalCost: 50.46本例下载

上一页  [1] [2] 


CodeSmith 使用 XMLProperty