惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
The Exploit Database - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
Simon Willison's Weblog
Simon Willison's Weblog
T
Tor Project blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
D
DataBreaches.Net
The Hacker News
The Hacker News
有赞技术团队
有赞技术团队
Latest news
Latest news
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Threat Research - Cisco Blogs
G
GRAHAM CLULEY
G
Google Developers Blog
W
WeLiveSecurity
Project Zero
Project Zero
WordPress大学
WordPress大学
人人都是产品经理
人人都是产品经理
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
MyScale Blog
MyScale Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
F
Full Disclosure
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
Attack and Defense Labs
Attack and Defense Labs
N
News and Events Feed by Topic
博客园 - 【当耐特】
Google DeepMind News
Google DeepMind News
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
F
Fortinet All Blogs
PCI Perspectives
PCI Perspectives
小众软件
小众软件
N
News | PayPal Newsroom
罗磊的独立博客
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
AI
AI
T
Tenable Blog
S
Schneier on Security
O
OpenAI News
The Register - Security
The Register - Security
Google DeepMind News
Google DeepMind News
Engineering at Meta
Engineering at Meta
T
Threatpost
Hacker News: Ask HN
Hacker News: Ask HN

博客园 - karoc

《重构-改善既有代码的设计》读书笔记 扩展GridView,增加单选按钮列 任务开始时间和完成时间 最大长度验证控件:MaxLengthValidator 又是关于AjaxControlToolkit的ModalPopup的问题 有个总结 使用svn的小插曲 开发小经验总结(不断更新) 今天发现一个VS2008中文版和英文版的差别 解决DocType引起AjaxTookit的ModulPopup显示异常问题的方法 Reporting Services 2005 常见问题解决方法(不断更新) 用VSTO开发Project插件心得 自定义MemberShipProvider和PersonalizationProvider使用WebParts实现个性化页面 在线修改KeyValue配置节 瞎搞八搞,另类PageBase 改造Duwamish中的Configuration 直接用Response输出可以加批注的Excel C#控制Windows Messenger和Windows Live Messenger窗口发送消息 用C#+WMI实现获取w3wp进程对应的应用程序池
一个读取扩展名为xml的资源文件的方法
karoc · 2006-11-27 · via 博客园 - karoc

今天重构代码时,想把如下xml文件嵌入程序集中,在运行时读取:

<?xml version="1.0" encoding="utf-8"?>
<Convertors xmlns="http://tempuri.org/~vs24E.xsd">
    
<Convertor>
        
<Name>1</Name>
        
<Category>1</Category>
        
<Description>1</Description>
    
</Convertor>
    
<Convertor>
        
<Name>2</Name>
        
<Category>2</Category>
        
<Description>2</Description>
    
</Convertor>
    
<Convertor>
        
<Name>3</Name>
        
<Category>3</Category>
        
<Description>3</Description>
    
</Convertor>
</Convertors>

到处找了一番,都是关于读取.txt和.resx类型的嵌入资源的,后来灵光一现,试出以下方法:

private static ConvertorData GetConvertorData()
        
{
            Assembly assembly 
= typeof(ConvertorProvider).Assembly ;
            System.IO.Stream stream 
= assembly.GetManifestResourceStream("TextConvertor.Convertor.xml") ;

            ConvertorData data 
= new ConvertorData() ;
            data.ReadXml(stream) ;
            
return data ;
        }

大概是先得到Assembly对象,然后得到流对象,以后就好办了,要不读到XmlDocument,要不读到根据xml文件生成的数据集中。