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


C# ResourceReader.ReadLine方法代码示例

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


在下文中一共展示了ResourceReader.ReadLine方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Load

        public void Load(string fileName)
        {
            this.New();

            this.FileName = fileName;
            string fileExtension = Path.GetExtension(fileName).ToLower();

            try
            {

            switch (fileExtension)
            {
                case ".xml":
                case ".resx":
                    using (ResXResourceReader reader = new ResXResourceReader(fileName))
                    {
                        this.BeginUpdate();

                        Hashtable resources = new Hashtable();
                        IDictionaryEnumerator enumerator = reader.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            string name = (string) enumerator.Key;
                            object value = enumerator.Value;
                            if (!resources.Contains(name))
                            {
                                this.AddResource(name, value);
                                resources.Add(name, value);
                            }
                        }

                        this.EndUpdate();
                    }
                    break;

                case ".resources":
                    using (FileStream stream = File.OpenRead(fileName))
                    {
                        this.BeginUpdate();

                        using (ResourceReader reader = new ResourceReader(stream))
                        {
                            Hashtable resources = new Hashtable();
                            IDictionaryEnumerator enumerator = reader.GetEnumerator();

                            while (enumerator.MoveNext())
                            {
                                string name = (string)enumerator.Key;
                                object value = enumerator.Value;

                                if (!resources.Contains(name))
                                {
                                    this.AddResource(name, value);
                                    resources.Add(name, value);
                                }
                            }
                        }

                        this.EndUpdate();
                    }
                    break;

                case ".txt":
                    using (StreamReader reader = File.OpenText(fileName))
                    {
                        this.BeginUpdate();

                        Hashtable resources = new Hashtable();
                        while (reader.Peek() != -1)
                        {
                            string line = reader.ReadLine();
                            line = line.TrimStart();
                            if (!line.StartsWith(";"))
                            {
                                int index = line.IndexOf("=");
                                if (index != -1)
                                {
                                    string name = line.Substring(0, index);
                                    string value = line.Substring(index + 1);
                                    name = name.Trim();
                                    if (!resources.Contains(name))
                                    {
                                        this.AddResource(name, value);
                                        resources.Add(name, value);
                                    }
                                }
                            }
                        }

                        this.EndUpdate();
                    }
                    break;

                default:
                    MessageBox.Show(this, "Unknown resource file format.", StringTable.GetString("ApplicationName"));
                    break;
            }

            }
            catch (Exception exception)
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:Resourcer,代码行数:101,代码来源:ResourceBrowser.cs


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