The original: vs under the operation of the RESX resource file
Read
<textarea cols= "rows=" "Name=" "Code" class= "C-sharp" >using system.io;using system.resources;using System.collections;using System.reflection;namespace resxedit{class Resxdemo {void Readresx (string StrResxP Ath, Boolean isresourcepath) {assemblyname[] referencedassemblies = assembly.getexecutingassembly (). Getreferencedassemblies (); ResXResourceReader Rsxresource = new ResXResourceReader (Strresxpath); Rsxresource.useresxdatanodes = true; IDictionaryEnumerator enumerator = Rsxresource.getenumerator (); while (enumerator. MoveNext ()) {DictionaryEntry current = (DictionaryEntry) Enumerator. Current; Resxdatanode node = (resxdatanode) Current. Value; String strkey = node. Name; Resource entry name String strvalue = node. GetValue (referencedassemblies); Value string strcomment = Node.comment; Comment}}} </textarea>
Write
using system.io;using system.resources;using system.collections;using system.reflection;namespace ResxEdit{ Class Resxdemo {void Writeresx (string strsavepath) {ResXResourceWriter resourceWriter = new ResXResourceWriter (Strsavepath); String strkey= "Key"; Resource entry name string strvalue= "Value"; Value string strcomment= "Comment"; Note Resxdatanode node = new Resxdatanode (strkey, strvalue); Node.comment = strcomment; Resourcewriter.addresource (node); Resourcewriter.generate (); Resourcewriter.close (); } }}
These are the resources that are used to store string types
For other resource types such as picture music, etc.
using system.resources;using system.collections;namespace resxdemo{class Resxdemo {void Writeresx () {ResourceWriter RW = new ResourceWriter ("./res.resx"); Bitmap map = new Bitmap ("./123.jpg"); rw. AddResource ("pp", map); rw. Generate (); rw. Close (); } void Readresx () {ResourceReader rr = new ResourceReader ("./res.resx"); foreach (DictionaryEntry dic in RR) {if (dic. key.tostring () = = "pp") {Bitmap map = new Bitmap ((Bitmap) dic. Value); pictureBox1.Image = map; } } } }}
Of course, it can be handled with ResourceManager.
Using system;using system.resources;using system.reflection;using system.threading;using System.Globalization;/* Perform The following steps to use this code Example:main assembly:1) in a Main directory, create a file named "Rmc.txt" T Hat contains the following resource strings:day=fridayyear=2006holiday= "Cinco de Mayo" 2) Use the Resgen.exe tool to genera Te the "rmc.resources" resource file from the "rmc.txt" input file.> resgen rmc.txtsatellite assembly:3) Create a Subdi Rectory of the main directory and name the subdirectory "Es-es", which is the culture name of the satellite assembly.4) Cr Eate a file named "Rmc.es-es.txt" that contains the following resource strings:day=viernesyear=2006holiday= "Cinco de Mayo" 5) Use the Resgen.exe tool to generate the "rmc.es-es.resources" resource file from the "Rmc.es-es.txt" input file.> re SGen rmc.es-es.txt6) Use the Al.exe tool to create a satellite assembly. If the base name of the application is "RMC", the satellite assembly name must are "Rmc.resources.dll ". Also, specify the culture, which is es-es.> Al/embed:rmc.es-es.resources/c:es-es/out:rmc.resources.dll 7) Assume the FileName for this code example is "Rmc.cs". Compile Rmc.cs and embed the main assembly resource file, Rmc.resources, in the executable assembly, Rmc.exe:>csc/res: Rmc.resources rmc.cs8) Execute Rmc.exe, which obtains and displays the embedded resource Strings.*/class Sample {publi c static void Main () {string Day; String year; String holiday; String celebrate = "{0} would occur on {1} in {2}./n";//Create a resource manager. The getexecutingassembly () method//gets Rmc.exe as an Assembly object. ResourceManager rm = new ResourceManager ("RMC", assembly.getexecutingassembly ());//Obtain RE Sources using the current UI culture. Console.WriteLine ("Obtain resources using the current UI culture."); /Get The resource strings for the day, year, and holiday//using the current UI culture. Use ThosE strings to//display a message. Day = rm. GetString ("Day"); Year = RM. GetString ("year"); Holiday = rm. GetString ("Holiday"); Console.WriteLine (Celebrate, Holiday, day, year);//Obtain the Es-es culture. CultureInfo ci = new CultureInfo ("Es-es");//Get The resource strings for the day, year, and holiday/using the Specifie D culture. Use those strings to//display a message. Obtain resources using the Es-es culture. Console.WriteLine ("Obtain resources using the Es-es culture."); Day = rm. GetString ("Day", CI); Year = RM. GetString ("Year", CI); Holiday = rm. GetString ("Holiday", CI);//---------------------------------------------------------------//Alternatively, Comment The preceding 3 code statements and//uncomment the following 4 code statements://------------------------------ ----------------------------------//Set The current UI culture to "es-es" (spanish-spain).//Thread.CurrentThread.Curr Entuiculture = ci;//Get The resource strings for thE Day, year, and holiday//using the current UI culture. Use those strings to//display a message. Day = rm. GetString ("Day");//year = RM. GetString ("Year");//holiday = RM. GetString ("Holiday");//---------------------------------------------------------------//Regardless of the Alternative that choose, display a message//using the retrieved resource strings. Console.WriteLine (Celebrate, Holiday, day, year); }}/*this code example produces the following Results:>rmcobtain resources using the current UI culture. " 5th of the "would occur on Friday in 2006.Obtain resources using the Es-es culture." Cinco de Mayo "would occur on Viernes in 2006.*/
vs. the operation of the RESX resource file