When refactoring the code today, I want to embed the following XML file into the assembly and read it at runtime:
<? 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>
After reading the embedded resources of the. txt and. resx types, I tried the following methods:
Private Static convertordata getconvertordata ()
{
Assembly = typeof (convertorprovider). assembly;
System. Io. Stream stream = assembly. getmanifestresourcestream ("textconvertor. convertor. xml ");
Convertordata DATA = new convertordata ();
Data. readxml (Stream );
Return data;
}
Probably it is to get the Assembly object first and then get the stream object, and then it will be easy to do, or read the xmldocument, or the data set generated based on the XML file.