• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Resources.ResXResourceReader类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: TestReader

			public static void TestReader (string fileName)
			{
				ResXResourceReader r = new ResXResourceReader (fileName);
				Hashtable h = new Hashtable ();
				foreach (DictionaryEntry e in r) {
					h.Add (e.Key, e.Value);
				}
				r.Close ();

				Assert.AreEqual ("hola", (string) h ["String"], fileName + "#1");
				Assert.AreEqual ("hello", (string) h ["String2"], fileName + "#2");
				Assert.AreEqual (42, (int) h ["Int"], fileName + "#3");
				Assert.AreEqual (PlatformID.Win32NT, (PlatformID) h ["Enum"], fileName + "#4");
				Assert.AreEqual (43, ((Point) h ["Convertible"]).X, fileName + "#5");
				Assert.AreEqual (2, (byte) ((ArrayList) h ["Serializable"]) [1], fileName + "#6");
				Assert.AreEqual (13, ((byte []) h ["ByteArray"]) [1], fileName + "#7");
				Assert.AreEqual (16, ((byte []) h ["ByteArray2"]) [1], fileName + "#8");
				Assert.AreEqual (1013, ((int []) h ["IntArray"]) [1], fileName + "#9");
				Assert.AreEqual ("world", ((string []) h ["StringArray"]) [1], fileName + "#10");
#if NET_2_0
				Assert.IsNull (h ["InvalidMimeType"], "#11");
#else
				Assert.IsNotNull (h ["InvalidMimeType"], "#11a");
				Assert.AreEqual ("AAEAAAD/////AQAAAAAAAAARAQAAAAIAAAAGAgAAAAVoZWxsbwYDAAAABXdvcmxkCw==",
					h ["InvalidMimeType"], "#11b");
#endif
				Assert.IsNotNull (h ["Image"], fileName + "#12");
				Assert.AreEqual (typeof (Bitmap), h ["Image"].GetType (), fileName + "#13");
			}
开发者ID:nlhepler,项目名称:mono,代码行数:29,代码来源:CompatTest.cs


示例17: GetResourceData

        /// <summary>
        /// get all the values from the resource file 
        /// </summary>
        /// <param name="path"></param>
        /// <param name="moduleName"></param>
        /// <returns></returns>
        public static List<ResourceData> GetResourceData(string path, string moduleName)
        {
            List<ResourceData> resourceData = new List<ResourceData>();
            string defaultLanguagePath = GetResourceFilePath(moduleName, "en-IN");
            if (File.Exists(path))
            {

                ResXResourceReader reader = new ResXResourceReader(path);
                if (reader != null)
                {
                    IDictionaryEnumerator id = reader.GetEnumerator();
                    foreach (DictionaryEntry d in reader)
                    {

                        resourceData.Add(new ResourceData
                        {
                            Key = d.Key.ToString(),
                            Value = GetResourceDataByKey(defaultLanguagePath, d.Key.ToString()).Value,
                            NewValue = d.Value.ToString(),
                            ModuleName = moduleName
                        });
                    } reader.Close();
                }

            }
            return resourceData;
        }
开发者ID:n2463230,项目名称:MVC4Project,代码行数:33,代码来源:CustomLocalizationUtility.cs


示例18: Build

        /// <summary>
        /// Build .resx file to .resource
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        public static void Build(string input)
        {
            var resxs = Directory.GetFiles(input, "*.resx");
            foreach (var resxFile in resxs)
            {
                var binFile = Path.GetDirectoryName(resxFile) +"\\"+ Path.GetFileNameWithoutExtension(resxFile) + ".resources";
                if (File.Exists(binFile)) {
                    var resxFileInfo = new FileInfo(resxFile);
                    var binFileInfo = new FileInfo(binFile);
                    if (resxFileInfo.LastWriteTime > binFileInfo.LastWriteTime)
                        File.Delete(binFile); //Re-complied
                }

                if (!File.Exists(binFile))
                {
                    using (var reader = new ResXResourceReader(resxFile))
                    {
                        using (var writer = new ResourceWriter(binFile))
                        {
                            foreach (DictionaryEntry d in reader)
                            {
                                writer.AddResource(d.Key.ToString(), d.Value);
                            }
                        }
                    }
                }
            }
        }
开发者ID:howej,项目名称:dotnetage,代码行数:33,代码来源:ResBuilder.cs


示例19: SaveResxAsTypeScriptFile

        public void SaveResxAsTypeScriptFile(string[] resxFiles, string outputTSFilePAth)
        {
            var sb = new StringBuilder();
            sb.AppendLine("// This file is auto generated");
            sb.AppendLine("");
            sb.AppendLine("export class PortalResources");
            sb.AppendLine("{");

            foreach (var resxFile in resxFiles)
            {
                if (File.Exists(resxFile))
                {

                    ResXResourceReader rsxr = new ResXResourceReader(resxFile);
                    foreach (DictionaryEntry d in rsxr)
                    {
                        sb.AppendLine(string.Format("    public static {0}: string = \"{0}\";", d.Key.ToString()));
                    }

                    //Close the reader.
                    rsxr.Close();
                }
            }
            sb.AppendLine("}");

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(outputTSFilePAth))
            {
                file.WriteLine(sb.ToString());
            }
        }
开发者ID:projectkudu,项目名称:AzureFunctionsPortal,代码行数:30,代码来源:ResxConvertor.cs


示例20: TestWriter01

        public void TestWriter01()
        {
            List<ILocanRow> expectedValues = new List<ILocanRow> {
                new LocanRow(id:"Key01",translatedString:"Value01"),
                new LocanRow(id:"Key02",translatedString:"Value02"),
                new LocanRow(id:"Key03",translatedString:"Value03"),
            };

            string filepath = this.GetTempFilename(true, ".resx");
            using (ResxFileLocanWriter writer = new ResxFileLocanWriter(filepath)) {
                writer.WriteRows(expectedValues);
            }

            // now we need to read that file
            using (ResXResourceReader reader = new ResXResourceReader(filepath)) {
                int currentIndex = 0;
                foreach (DictionaryEntry de in reader) {
                    string expectedKey = expectedValues[currentIndex].Id;
                    string expectedValue = expectedValues[currentIndex].TranslatedString;

                    Assert.AreEqual(expectedKey, de.Key);
                    Assert.AreEqual(expectedValue, de.Value);

                    currentIndex++;
                }
            }
        }
开发者ID:sayedihashimi,项目名称:locan,代码行数:27,代码来源:TestResxFileLocanReader.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Resources.ResXResourceWriter类代码示例发布时间:2022-05-26
下一篇:
C# Resources.ResXDataNode类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap