C# 3.0 LINQ to XML
2024-08-24 07:33:54
高级转换:
static IEnumerable<XElement> ExpandPaths (IEnumerable<string> paths)
{
var brokenUp = from path in paths
let split = path.Split (new char[] { '\\' }, 2)
orderby split[0]
select new
{
name = split[0],
remainder = split.ElementAtOrDefault (1)
}; IEnumerable<XElement> files = from b in brokenUp
where b.remainder == null
select new XElement ("file", b.name); IEnumerable<XElement> folders = from b in brokenUp
where b.remainder != null
group b.remainder by b.name into grp
select new XElement ("folder",
new XAttribute ("name", grp.Key),
ExpandPaths (grp)
); return files.Concat (folders);
} static void RunQuery()
{
XElement project = XElement.Load ("myProjectFile.csproj");
XName ns = project.Name.Namespace; IEnumerable<string> paths =
from compileItem in
project.Elements (ns + "ItemGroup").Elements (ns + "Compile")
let include = compileItem.Attribute ("Include")
where include != null
select include.Value; XElement query = new XElement ("Project", ExpandPaths (paths));
}
最新文章
- 一个免费的、跨平台的、开源音频编辑器Audacity
- 宠物收养所(bzoj1208)
- iOS 正则表达式判断邮箱、身份证..是否正确
- Android_gridVIew
- 总结: Struts2 + Spring 的线程安全问题
- 左右推拽显示对比图 - jQyery封装 - 附源文件
- IHttpModule接口事件执行 获取Session 找了很多国内的都不对,从国外转过来一个测试可用的
- Sublime Text 3 无法使用package control安装插件解决办法
- 8.2.5: Spring3.0新增的@DependsOn和@Lazy
- touch修改文件的修改时间和访问时间,ls --full-time显示文件详细,stat命令
- .net 在数据访问层中写一个DBhelper优化类
- Java--Dom解析XML文件
- Linux替换动态库导致正在运行的程序崩溃
- 关于python的展望
- 主流CTR预估模型的演化及对比
- wzoj install
- Isomorphism 同构
- 超详细的PS抠图方法
- 华中农业大学第五届程序设计大赛网络同步赛-K
- jzoj100044
热门文章
- Petshop学习第一天
- Android开发--ListPreferance 运行报错:android.preference.ListPreference.findIndexOfValue(ListPreference.java:169)
- sqlite 修改表名,合并数据库(文件)
- Java List 用法代码分析 非常详细
- A Tour of Go Methods
- 第一个android程序所遇到问题
- [置顶] Objective-C ,ios,iphone开发基础:protocol 协议(委托,代理)的声明
- android应用程序fps meter[帧数显示]的分析 —— 浅谈root的风险 (3)
- linux mail命令用法
- cocos2d-x CCSpriteBatchNode