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


C# ResXResourceReader.Cast方法代码示例

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


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

示例1: 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

示例2: AddDoubleKey

        public void AddDoubleKey()
        {
            PanelViewModel panelViewModel = new PanelViewModel(_model.RootPanel) { RuDescription = "Комент", FieldInDb = "Key1" };
            _model.RootPanel.Children.Add(panelViewModel);
            //Добавляем ключь, должны добавится в оба словаря
            _model.WriteResourses();
            //Проверяем
            ResXResourceReader reader = new ResXResourceReader(_model.ResourceFilePath);
            var dictionary = reader.Cast<DictionaryEntry>();
            Assert.AreEqual(1, dictionary.Count());
            reader.Close();

            reader = new ResXResourceReader(_model.ResourceFilePath.Replace(".resx", ".ru-RU.resx"));
            dictionary = reader.Cast<DictionaryEntry>();
            Assert.AreEqual(1, dictionary.Count());
            reader.Close();
        }
开发者ID:pitchcontrol,项目名称:Atom,代码行数:17,代码来源:ResourceTests.cs

示例3: AddNewKeyTest

        public void AddNewKeyTest()
        {
            PanelViewModel panelViewModel = new PanelViewModel(_model.RootPanel) { RuDescription = "Комент", FieldInDb = "Id1" };
            _model.RootPanel.Children.Add(panelViewModel);
            //Добавляем ключь, должны добавится в оба словаря
            _model.WriteResourses();
            //Проверяем
            ResXResourceReader reader = new ResXResourceReader(_model.ResourceFilePath);
            var dictionary = reader.Cast<DictionaryEntry>();
            Assert.AreEqual(2, dictionary.Count());
            Assert.IsNotNull(dictionary.FirstOrDefault(i => (string) i.Key == "Id1"));
            reader.Close();

            reader = new ResXResourceReader(_model.ResourceFilePath.Replace(".resx", ".ru-RU.resx"));
            dictionary = reader.Cast<DictionaryEntry>();
            Assert.AreEqual(2, dictionary.Count());
            Assert.IsNotNull(dictionary.FirstOrDefault(i => (string) i.Key == "Id1"));
            reader.Close();
        }
开发者ID:pitchcontrol,项目名称:Atom,代码行数:19,代码来源:ResourceTests.cs

示例4: ReadAllResxEntries

 private static Dictionary<string, object> ReadAllResxEntries(Stream resxStream)
 {
     using (var reader = new ResXResourceReader(resxStream))
     {
         return reader
             .Cast<DictionaryEntry>()
             .ToDictionary(entry => (string)entry.Key, entry => entry.Value);
     }
 }
开发者ID:Saleslogix,项目名称:ProjectUpgrade,代码行数:9,代码来源:ResxDiffMerge.cs

示例5: AddRecursiveKey

        public void AddRecursiveKey()
        {
            PanelViewModel panel1 = new PanelViewModel(_model.RootPanel);
            panel1.FieldInDb = "fl1";
            _model.RootPanel.Children.Add(panel1);

            PanelViewModel panel2 = new PanelViewModel(panel1);
            panel2.FieldInDb = "fl2";
            panel1.Children.Add(panel2);

            PanelViewModel panel3 = new PanelViewModel(panel2);
            panel3.FieldInDb = "fl3";
            panel2.Children.Add(panel3);
            //Добавляем ключь, должны добавится в оба словаря
            _model.WriteResourses();
            //Проверяем
            ResXResourceReader reader = new ResXResourceReader(_model.ResourceFilePath);
            var dictionary = reader.Cast<DictionaryEntry>();
            Assert.IsNotNull(dictionary.FirstOrDefault(i => i.Key == "fl1"));
            Assert.IsNotNull(dictionary.FirstOrDefault(i => i.Key == "fl2"));
            Assert.IsNotNull(dictionary.FirstOrDefault(i => i.Key == "fl3"));
            Assert.AreEqual(4, dictionary.Count());
            reader.Close();

            reader = new ResXResourceReader(_model.ResourceFilePath.Replace(".resx", ".ru-RU.resx"));
            dictionary = reader.Cast<DictionaryEntry>();
            Assert.IsNotNull(dictionary.FirstOrDefault(i => i.Key == "fl1"));
            Assert.IsNotNull(dictionary.FirstOrDefault(i => i.Key == "fl2"));
            Assert.IsNotNull(dictionary.FirstOrDefault(i => i.Key == "fl3"));
            Assert.AreEqual(4, dictionary.Count());
            reader.Close();
        }
开发者ID:pitchcontrol,项目名称:Atom,代码行数:32,代码来源:ResourceTests.cs

示例6: TestWrite

        private void TestWrite(
            Func<System.Data.Entity.Migrations.Utilities.MigrationWriter, ScaffoldedMigration, string> action,
            bool skipUserCodeVerification = false)
        {
            var command = CreateCommand(_projectDir);
            var writer = new System.Data.Entity.Migrations.Utilities.MigrationWriter(command);
            var scaffoldedMigration = new ScaffoldedMigration
                                          {
                                              MigrationId = MigrationId,
                                              Language = Language,
                                              Directory = MigrationsDirectory,
                                              UserCode = "The user code.",
                                              DesignerCode = "The designer code.",
                                              Resources =
                                                  {
                                                      { ResourceName, "The resource." }
                                                  }
                                          };

            var relativeUserCodePath = action(writer, scaffoldedMigration);

            Assert.Equal(UserCodePath, relativeUserCodePath);

            if (!skipUserCodeVerification)
            {
                var userCodePath = Path.Combine(_projectDir, UserCodePath);
                Assert.Equal("The user code.", File.ReadAllText(userCodePath));
            }

            var designerCodePath = Path.Combine(_projectDir, DesignerCodePath);
            Assert.Equal("The designer code.", File.ReadAllText(designerCodePath));

            var resourcesPath = Path.Combine(_projectDir, ResourcesPath);

            using (var reader = new ResXResourceReader(resourcesPath))
            {
                var resources = reader.Cast<DictionaryEntry>();

                Assert.Equal(1, resources.Count());
                Assert.Contains(new DictionaryEntry(ResourceName, "The resource."), resources);
            }
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:42,代码来源:MigrationWriterTests.cs

示例7: AddOrUpdateResource

        public int AddOrUpdateResource(string key, string value, int forceupdate = 0)
        {
            int result = 0;

            var resx = new List<DictionaryEntry>();
            string resourceFilepath = "D:\\LC\\OCR\\Convertor\\Licence\\info.resx";
            using (var reader = new ResXResourceReader(resourceFilepath))
            {
                resx = reader.Cast<DictionaryEntry>().ToList();
                var existingResource = resx.Where(r => r.Key.ToString() == key).FirstOrDefault();
                if (existingResource.Key == null && existingResource.Value == null) // NEW!
                {
                    resx.Add(new DictionaryEntry() { Key = key, Value = value });
                    result = 1;
                }

                if (forceupdate == 0)
                {
                    if (existingResource.Key != null && (existingResource.Value == null || existingResource.Value == "")) // NEW!
                    {
                        var modifiedResx = new DictionaryEntry() { Key = existingResource.Key, Value = value };
                        resx.Remove(existingResource);  // REMOVING RESOURCE!
                        resx.Add(modifiedResx);  // AND THEN ADDING RESOURCE!
                        result = 1;
                    }
                }
                if (forceupdate == 1)
                {
                    if (existingResource.Key != null) // NEW!
                    {
                        var modifiedResx = new DictionaryEntry() { Key = existingResource.Key, Value = value };
                        resx.Remove(existingResource);  // REMOVING RESOURCE!
                        resx.Add(modifiedResx);  // AND THEN ADDING RESOURCE!
                        result = 1;
                    }

                }
            }
            if (result > 0)
            {
                using (var writer = new ResXResourceWriter(resourceFilepath))
                {
                    resx.ForEach(r =>
                    {
                        // Again Adding all resource to generate with final items
                        writer.AddResource(r.Key.ToString(), r.Value.ToString());
                    });
                    writer.Generate();
                }
            }
            return result;
        }
开发者ID:ashishjain76,项目名称:AutoConvertor,代码行数:52,代码来源:Form1.cs

示例8: Execute

        /// <summary>
        /// Executes the Task
        /// </summary>
        /// <returns>True if success</returns>
        public bool Execute()
        {
            if (!this.EmbeddedResourcesItems.Any())
            {
                this.BuildEngine.LogMessageEvent(
                    new BuildMessageEventArgs(
                        string.Format(
							"Skipping conversion of Resource files to Pseudo-Loc, as there are no resource files found in the project. If your resx file is not being picked up, check if the file is marked for build action = 'Embedded Resource'"),
                        string.Empty,
						"PseudoLocResx",
                        MessageImportance.Normal));
            }

            var args = new BuildMessageEventArgs(
                "Started converting Resx To Pseudo-Loc",
                string.Empty,
				"PseudoLocResx",
                MessageImportance.Normal);

            this.BuildEngine.LogMessageEvent(args);
            foreach (var embeddedResourcesItem in this.EmbeddedResourcesItems)
            {
	            var lang = this.GetCultureInfo(embeddedResourcesItem.ItemSpec);
	            if (lang == null)
	            {
		            this.BuildEngine.LogMessageEvent(
			            new BuildMessageEventArgs(
							string.Format("Started converting Resx {0} to Pseudo-Loc", embeddedResourcesItem.ItemSpec),
							string.Empty,
							"PseudoLocResx",
							MessageImportance.Normal));


		            var outputFileName = Path.Combine(
			            Path.GetDirectoryName(embeddedResourcesItem.ItemSpec),
						Path.GetFileNameWithoutExtension(embeddedResourcesItem.ItemSpec) + string.Format(".{0}.resx", locale));

		            var strings = new Dictionary<string, object>();
		            using (var rsxr = new ResXResourceReader(embeddedResourcesItem.ItemSpec))
		            {
			            rsxr.UseResXDataNodes = true;
			            strings = rsxr.Cast<DictionaryEntry>()
									.ToDictionary(x => x.Key.ToString(), x => ((ResXDataNode)x.Value).GetValue((ITypeResolutionService)null));
		            }

		            using (ResXResourceWriter resourceWriter = new ResXResourceWriter(outputFileName))
		            {
			            foreach (var entry in strings)
			            {
				            if (entry.Value is string)
				            {
					            var value = entry.Value as string;
					            CultureInfo ci = null;

					            if (value.TryParse(out ci))
						            resourceWriter.AddResource(entry.Key, locale);
					            else
						            resourceWriter.AddResource(entry.Key, value.ToPseudo());
				            }
				            else
				            {
					            resourceWriter.AddResource(entry.Key, entry.Value);
				            }
			            }

			            this.BuildEngine.LogMessageEvent(
				            new BuildMessageEventArgs(
								string.Format("Generated pseudo-loc file {0}", outputFileName),
								string.Empty,
								"PseudoLocResx",
								MessageImportance.Normal));
			            resourceWriter.Generate();
		            }
	            }
            }

            return true;
        }
开发者ID:manishkp,项目名称:PseudoLocResx.MSBuild,代码行数:82,代码来源:PseudoLocResxTask.cs

示例9: WriteResource

 private void WriteResource(string path, bool ru)
 {
     using (ResXResourceReader reader = new ResXResourceReader(path))
     {
         var dictionary = reader.Cast<DictionaryEntry>();
         using (ResXResourceWriter writer = new ResXResourceWriter(path))
         {
             foreach (DictionaryEntry dictionaryEntry in dictionary)
                 writer.AddResource(dictionaryEntry.Key.ToString(), dictionaryEntry.Value.ToString());
             foreach (WebPageBaseViewModel webPageBaseViewModel in RootPanel.Children.Flatten(i => i.Children))
             {
                 writer.AddResource(webPageBaseViewModel.FieldInDb, ru ? webPageBaseViewModel.RuDescription : webPageBaseViewModel.EnDescription);
             }
             writer.Generate();
         }
     }
 }
开发者ID:pitchcontrol,项目名称:Atom,代码行数:17,代码来源:ConstructorViewModel.cs


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