public static void ReadRessourceFile() { //Requires Assembly System.Windows.Forms ' string filename = @"C:\Program Files\paint.net\resx\PaintDotNet.Strings.3.resx"; filename = "/root/github/EntityFrameworkCore/src/EFCore.Sqlite.Core/Properties/SqliteStrings.resx"; filename = "/root/github/ExpressProfiler/ExpressProfiler/MainForm.resx"; System.Resources.ResXResourceReader rsxr = new System.Resources.ResXResourceReader(filename); // Iterate through the resources and display the contents to the console. ' foreach (System.Collections.DictionaryEntry d in rsxr) { if (d.Key != null) { System.Console.Write(d.Key.ToString() + ":\t"); } if (d.Value != null) { System.Console.Write(d.Value.ToString()); } System.Console.WriteLine(); } //Close the reader. ' rsxr.Close(); }
private string GetResourceKey(string resourceFileName, string key) { System.Resources.ResXResourceReader rsxr = null; try { rsxr = new System.Resources.ResXResourceReader(resourceFileName); System.Collections.DictionaryEntry d = default(System.Collections.DictionaryEntry); foreach (DictionaryEntry d_loopVariable in rsxr) { if (d_loopVariable.Key.ToString().ToLower().Equals(key.ToLower())) { return(d_loopVariable.Key.ToString()); } } return(null); } catch (Exception e) { string logMessage = $"Unable to find key {key} in resource file: {resourceFileName}."; logger.Warn(logMessage); throw new Exception(logMessage, e); } finally { if (rsxr != null) { rsxr.Close(); } } }
private void MyDiary_Loaded(object sender, RoutedEventArgs e) { Colorit(); string date_string = DateTime.Now.ToString("yyyy-MM-dd"); string weekday_string = DateTime.Now.DayOfWeek.ToString(); this.Label_time.Content = date_string + " " + weekday_string; this.diaryBox.Text = original_text; WinChange(0); string help_msg = ""; help_msg += "MyDiary By BlackHand\n"; help_msg += "o : 打开日记\n"; help_msg += "c : 更换颜色\n"; help_msg += "×: 退出"; Label_helptext.Content = help_msg; System.Resources.ResXResourceReader rr = new System.Resources.ResXResourceReader(respath); var dict = rr.GetEnumerator(); while (dict.MoveNext()) { if (dict.Key.ToString() == "FILEPATH") { Filepath = dict.Value.ToString(); } if (dict.Key.ToString() == "PASSWORD") { pword = dict.Value.ToString(); } } rr.Close(); /* * try * { * ManageReg(); * } * catch * { * MessageBox.Show("请使用管理员权限打开本应用。"); * Application.Current.Shutdown(); * } */ string path = System.IO.Path.GetDirectoryName(Filepath); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); FileStream fs = new FileStream(Filepath, FileMode.Append); fs.Close(); } }
public static Dictionary <string, Font> LoadRess(string FsPath) { MonoBug(); System.Resources.ResXResourceReader test = new System.Resources.ResXResourceReader(FsPath); Dictionary <string, Font> ResXData = new Dictionary <string, Font>(); // Iterate through the resources and display the contents to the console. try { foreach (DictionaryEntry d in test) { ResXData.Add(d.Key.ToString(), (Font)d.Value); //if(!VarGlobal.LessVerbose)Console.WriteLine(d.Key.ToString() + ":\t" + d.Value.ToString()); } } catch (Exception Ex) { if (!VarGlobal.LessVerbose) { Console.WriteLine("{0}{1}{1}{2}", Ex.Message, Environment.NewLine, Ex.StackTrace); } MonoBug(); } try { if (null != test) { test.Close(); } } catch (Exception Ex) { if (!VarGlobal.LessVerbose) { Console.WriteLine("{0}{1}{1}{2}", Ex.Message, Environment.NewLine, Ex.StackTrace); } MonoBug(); } return(ResXData); }