当前位置: 首页>>代码示例>>C#>>正文


C# Resources.ResXResourceReader类代码示例

本文整理汇总了C#中System.Resources.ResXResourceReader的典型用法代码示例。如果您正苦于以下问题:C# ResXResourceReader类的具体用法?C# ResXResourceReader怎么用?C# ResXResourceReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ResXResourceReader类属于System.Resources命名空间,在下文中一共展示了ResXResourceReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InitResource

        public static void InitResource()
        {
            string path = HttpContext.Current.Server.MapPath("/") + "Resource\\";

            foreach (string lang in LangList)
            {
                ResXResourceReader reader = new ResXResourceReader(path + lang + ".resx");

                try
                {
                    foreach (DictionaryEntry d in reader)
                    {
                        dataCollection.Add(new KeyValuePair<string, string>(AssmbleKey(d.Key.ToString(), lang), d.Value.ToString()));
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    reader.Close();
                }
            }
        }
开发者ID:Benguan,项目名称:Code,代码行数:25,代码来源:LocalizationHelpers.cs

示例2: Test

		public void Test ()
		{
			Thread.CurrentThread.CurrentCulture =
					Thread.CurrentThread.CurrentUICulture = new CultureInfo ("de-DE");

			ResXResourceWriter w = new ResXResourceWriter (fileName);
			w.AddResource ("point", new Point (42, 43));
			w.Generate ();
			w.Close ();

			int count = 0;
			ResXResourceReader r = new ResXResourceReader (fileName);
			IDictionaryEnumerator e = r.GetEnumerator ();
			while (e.MoveNext ()) {
				if ((string) e.Key == "point") {
					Assert.AreEqual (typeof (Point), e.Value.GetType (), "#1");
					Point p = (Point) e.Value;
					Assert.AreEqual (42, p.X, "#2");
					Assert.AreEqual (43, p.Y, "#3");
					count++;
				}
			}
			r.Close ();
			Assert.AreEqual (1, count, "#100");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:25,代码来源:CultureTest.cs

示例3: ResXViewForm

        public ResXViewForm(string fileName)
        {
            const int BASEWIDTH = 1000;
            const int BASEHEIGHT = 250;
            ClientSize = new Size((BASEWIDTH + 20), BASEHEIGHT + 100);

            resxFile = new FileInfo(fileName);

            using (var resxSet = new ResXResourceSet(resxFile.FullName))
            {
                Text = resxSet.GetString("FormTitle");
                Icon = (Icon)resxSet.GetObject("ShieldIcon");
            }

            const int margin = 10;
            var resList = new ListView
            {
                Bounds = new Rectangle(new Point(margin, margin), new Size(BASEWIDTH, BASEHEIGHT)),
                View = View.Details,
                GridLines = true,
            };

            var columnWidth = (resList.ClientSize.Width / 3);
            resList.Columns.Add("Resource Name", columnWidth);
            resList.Columns.Add("Type", columnWidth);
            resList.Columns.Add("Value", columnWidth);

            using (var resxReader = new ResXResourceReader(resxFile.FullName))
            {
                foreach (DictionaryEntry entry in resxReader)
                {
                    var resItem = new ListViewItem((string)entry.Key);
                    resItem.SubItems.Add(entry.Value.GetType().FullName);
                    resItem.SubItems.Add(entry.Value.ToString());
                    resList.Items.Add(resItem);
                }
            }

            var resxButton = new Button
            {
                Text = "Show ResX",
                Location = new Point(resList.Bounds.Left, resList.Bounds.Bottom + margin)
            };
            resxButton.Click += (sender, args) => Process.Start("Notepad.exe", resxFile.FullName);

            var exitButton = new Button { Text = "Exit" };
            exitButton.Location = new Point(resList.Bounds.Right - exitButton.Width, resList.Bounds.Bottom + margin);
            exitButton.Click += (sender, args) => Application.Exit();

            FormBorderStyle = FormBorderStyle.Sizable;
            MaximizeBox = true;
            MinimizeBox = false;
            StartPosition = FormStartPosition.CenterScreen;

            Controls.Add(resList);
            Controls.Add(resxButton);
            Controls.Add(exitButton);

            InitializeComponent();
        }
开发者ID:CubicleJockey,项目名称:ResourceWriter,代码行数:60,代码来源:ResXViewForm.cs

示例4: GetResourceReader

 protected override IResourceReader GetResourceReader(Stream inputStream)
 {
     ResXResourceReader reader = new ResXResourceReader(inputStream);
     string path = HostingEnvironment.MapPath(base.VirtualPath);
     reader.BasePath = Path.GetDirectoryName(path);
     return reader;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:ResXBuildProvider.cs

示例5: GetCustomerCredentials

        /// <summary>
        /// To Get the user credentials from Customer Resource file
        /// </summary>
        /// Authour: Pradeep
        /// <param name="custType">Type of the customer</param>
        /// <returns>returns an array with UserName and Password</returns>
        /// Created Date: 22-Dec-2011
        /// Modified Date: 22-Dec-2011
        /// Modification Comments
        public static string[] GetCustomerCredentials(string custType)
        {
            try
            {
                Stream stream = new System.IO.FileStream(ResFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
                var resFileData = new ResXResourceReader(stream);
                IDictionaryEnumerator resFileDataDict = resFileData.GetEnumerator();
                var customerCreds = new string[2];
                while (resFileDataDict.MoveNext())
                {
                    if (custType.ToString(CultureInfo.InvariantCulture) == resFileDataDict.Key.ToString())
                    {
                        string temp = resFileDataDict.Value.ToString();
                        customerCreds = temp.Split(';');
                        break;
                    }
                }

                resFileData.Close();
                stream.Dispose();
                return customerCreds;

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                return null;

            }
        }
开发者ID:hemap,项目名称:PhoenixAutomationRepo,代码行数:40,代码来源:Common.cs

示例6: UpdateResourceFile

        public static void UpdateResourceFile(Hashtable data, string path, TranslatorForm form)
        {
            form.TextOutput = "Writing " + path + "...";

            Hashtable resourceEntries = new Hashtable();
            bool check = false;

            //Get existing resources
            ResXResourceReader reader = new ResXResourceReader(path);
            if (reader != null)
            {
                IDictionaryEnumerator id = reader.GetEnumerator();
                foreach (DictionaryEntry d in reader)
                {
                    if (d.Value == null)
                        resourceEntries.Add(d.Key.ToString(), "");
                    else
                        resourceEntries.Add(d.Key.ToString(), d.Value.ToString());
                }
                reader.Close();
            }

            //Modify resources here...
            foreach (String key in data.Keys)
            {
                if (!resourceEntries.ContainsKey(key))
                {

                    String value = data[key].ToString();
                    if (value == null) value = "";

                    resourceEntries.Add(key, value);
                }
            }

            //Write the combined resource file
            ResXResourceWriter resourceWriter = new ResXResourceWriter(path);

            foreach (String key in resourceEntries.Keys)
            {
                resourceWriter.AddResource(key, resourceEntries[key]);
            }
            resourceWriter.Generate();
            resourceWriter.Close();

            //Check if entered correctly
            reader = new ResXResourceReader(path);
            if (reader != null)
            {
                foreach (DictionaryEntry d in reader)
                    foreach (String key in resourceEntries.Keys)
                    {
                        if ((string) d.Key == key && (string) d.Value == (string) resourceEntries[key]) check = true;
                    }
                reader.Close();
            }

            if (check) form.TextOutput = path + " written successfully";
            else form.TextOutput = path + " not written !!";
        }
开发者ID:nathanpower,项目名称:resource-translator,代码行数:60,代码来源:Helper.cs

示例7: LoadResources

 void LoadResources(ResXResourceReader resxReader)
 {
     IDictionaryEnumerator enumerator = resxReader.GetEnumerator ();
     while (enumerator.MoveNext ()) {
         Resources.Add (enumerator.Value as ResXDataNode);
     }
 }
开发者ID:CalebMorris,项目名称:Xamarin-ResxEditor,代码行数:7,代码来源:ResourceHandler.cs

示例8: LocalizationMessageProvider

        public LocalizationMessageProvider(string pluginName)
        {
            string path = "";
            //NOTE: Modified by [email protected] original is at revision 1668
            try
            {
                path = HttpContext.Current.Server.MapPath("/").Replace("IUDICO.LMS", "IUDICO." + pluginName);
            }
            catch(Exception exception)
            {
                path = Assembly.GetExecutingAssembly().CodeBase;
                path = Path.GetDirectoryName(path);
                path = Path.GetDirectoryName(path);
                path = Path.GetDirectoryName(path);
                path = Path.GetDirectoryName(path);
                path = Path.Combine(path, "IUDICO.LMS");
                path=path.Replace("IUDICO.LMS", "IUDICO." + pluginName);
                path = path.Remove(0, 6);
                path += @"\";
            }   
            //NOTE: End of modifiation from revision 1668
            foreach (var culture in cultures)
            {
                var rsxr = new ResXResourceReader(path + "Resource." + culture + ".resx");

                Dictionary<string, string> temp = new Dictionary<string, string>();
                foreach (DictionaryEntry d in rsxr)
                {
                    temp.Add(d.Key.ToString(), d.Value.ToString());
                }

                resource.Add(culture, temp);
            }
        }
开发者ID:supermuk,项目名称:iudico,代码行数:34,代码来源:Localization.cs

示例9: ResourceHandler

 public ResourceHandler(string fileName)
 {
     Resources = new List<ResXDataNode> ();
     using (var reader = new ResXResourceReader (fileName) { UseResXDataNodes = true }) {
         LoadResources (reader);
     }
 }
开发者ID:CalebMorris,项目名称:Xamarin-ResxEditor,代码行数:7,代码来源:ResourceHandler.cs

示例10: Init_ResourceCache

        public static void Init_ResourceCache()
        {
            string resourceFolder = HttpContext.Current.Server.MapPath("~/App_GlobalResources");
            var dir = new DirectoryInfo(resourceFolder);
            var files = dir.GetFiles();

            for (int i = 0; i < files.Length; i++)
            {
                var file = files[i];
                string extension = Path.GetExtension(file.FullName).ToLower();

                if (extension == C_ResourceFileExtension)
                {
                    string dicKey = file.Name.ToLower();
                    Dictionary<string,string> resourceItems =new Dictionary<string, string>();
                    using (var reader = new ResXResourceReader(file.FullName))
                    {
                        foreach (DictionaryEntry item in reader)
                        {
                            var val = item.Value == null ? string.Empty : item.Value.ToString();
                            resourceItems.Add(item.Key.ToString(), val);
                        }
                    }
                    cacheLangResources.Add(dicKey, resourceItems);
                }
            }
        }
开发者ID:koolay,项目名称:MVCAppStart,代码行数:27,代码来源:GlobalizationHelper.cs

示例11: ResxToResourceStringDictionary

        public List<ResxStringResource> ResxToResourceStringDictionary(TextReader resxFileContent)
        {
            try
            {
                var result = new List<ResxStringResource>();

                // Reading comments: http://msdn.microsoft.com/en-us/library/system.resources.resxdatanode.aspx
                using (var reader = new ResXResourceReader(resxFileContent))
                {
                    reader.UseResXDataNodes = true;
                    var dict = reader.GetEnumerator();

                    while (dict.MoveNext())
                    {
                        var node = (ResXDataNode)dict.Value;

                        result.Add(new ResxStringResource()
                        {
                            Name = node.Name,
                            Value = (string)node.GetValue((ITypeResolutionService)null),
                            Comment = node.Comment
                        });
                    }
                }

                return result;
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
            }

            return null;
        }
开发者ID:transformersprimeabcxyz,项目名称:ResourceFirstTranslations,代码行数:34,代码来源:ResxStringResourceReader.cs

示例12: getBMPFiles

        public static void getBMPFiles(string resxFile)
        {
            // Create a Resource Reader
            ResXResourceReader rsxr = new ResXResourceReader(resxFile);

            // Create a enumerator
            IDictionaryEnumerator id = rsxr.GetEnumerator();

            int i = 0;
            foreach (DictionaryEntry d in rsxr)
            {

                Bitmap b = d.Value as Bitmap;

                if (b != null)
                {
                    b.Save(resxFile + "__" + i.ToString() + ".bmp");
                    i++;
                }

            }

            //Close the reader.
            rsxr.Close();
        }
开发者ID:Tab3r,项目名称:Tab3r.Utils,代码行数:25,代码来源:myResxFileBMPExtractor.cs

示例13: LoadResource

        protected void LoadResource(string pluginName)
        {
            string path;

            try
            {
                path = HttpContext.Current.Server.MapPath("/").Replace("IUDICO.LMS", pluginName);
            }
            catch (Exception)
            {
                path = Path.Combine(Assembly.GetExecutingAssembly().CodeBase.Remove(0, 8) + @"\..\..\..\..\", pluginName) + @"\";
            }

            this.resource.Add(pluginName, new Dictionary<string, Dictionary<string, string>>());

            foreach (var culture in Cultures)
            {
                try
                {
                    var resourceReader = new ResXResourceReader(path + "Resource." + culture + ".resx");
                    var resourceEntries = resourceReader.Cast<DictionaryEntry>().ToDictionary(d => d.Key.ToString(), d => d.Value.ToString());

                    this.resource[pluginName].Add(culture, resourceEntries);
                }
                catch (Exception)
                {
                    
                }
            }
        }
开发者ID:supermuk,项目名称:iudico,代码行数:30,代码来源:Localization.cs

示例14: Parse

        public override IEnumerable<ILocalizationUnit> Parse ()
        {
            foreach (var path in resx_paths) {
                var reader = new ResXResourceReader(path) { UseResXDataNodes = true };

                foreach (DictionaryEntry item in reader) {
                    var name = (string)item.Key;
                    var node = (ResXDataNode)item.Value;
                    var localized_string = new LocalizedString {
                        Name = name,
                        DeveloperComments = node.Comment,
                        UntranslatedSingularValue = name,
                        TranslatedValues = new string [] {(string)node.GetValue(null as ITypeResolutionService) }
                    };

                    for (int i = 0; i < localized_string.TranslatedValues.Length; i++)
                    {
                        var s = localized_string.TranslatedValues [i];
                        s = s.Replace ("\r", "");
                        localized_string.TranslatedValues[i] = s;
                    }

                    yield return localized_string;
                }
            }

            yield break;
        }
开发者ID:lothrop,项目名称:vernacular,代码行数:28,代码来源:ResxParser.cs

示例15: LoadConfig

 /// <summary>
 /// 加载配置数据.如果加载失败,将抛异常
 /// </summary>
 public void LoadConfig()
 {
     SecurityOpr secOpr = new SecurityOpr(GlobalVar.Instanse.SecurityKey);
     string Datas = secOpr.ReadFromFile(m_StrPath);
     StringReader reader = new StringReader(Datas);
     using (m_Reader = new ResXResourceReader(reader))
     {
         try
         {
             foreach (DictionaryEntry item in m_Reader)
                 m_cfgDatas[item.Key.ToString()] = item.Value;
         }
         catch (FileNotFoundException)
         { }
         catch (Exception ex)
         {
             throw ex;
         }
     }
     //finally
     //{
     //    if (m_Reader != null)
     //        m_Reader.Close();
     //}
 }
开发者ID:kener1985,项目名称:MyGitHubProj,代码行数:28,代码来源:ConfigAccessor.cs


注:本文中的System.Resources.ResXResourceReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。