Services/XmlDataService.cs
(完整代码) 1KBusing System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Linq;
namespace MyApp.Services
{
public class XmlDataService : IDataService
{
List<Dish> IDataService.FindAllDishes()
{
List<Dish> list = new List<Dish>();
string dataDir = @"Data";
string dataFile = @"Data.xml";
string xmlFilePath = dataDir + @"\" + dataFile;
string xmlFileFullPath = Path.Combine(Environment.CurrentDirectory, xmlFilePath);
XDocument xDoc = XDocument.Load(xmlFileFullPath);
IEnumerable<XElement> dishes = xDoc.Descendants("Dish");
foreach (XElement d in dishes)
{
Dish dish = new Dish
{
Name = d.Element("Name").Value,
Category = d.Element("Category").Value,
Price = d.Element("Price").Value,
Description = d.Element("Description").Value,
Score = d.Element("Score").Value
};
list.Add(dish);
}
return list;
}
}
}
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
