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


C# ResourceWriter.Generate方法代码示例

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


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

示例1: WriteResourceFile

        private static void WriteResourceFile(string resxFilePath)
        {
            using (var fs = File.OpenRead(resxFilePath))
            {
                var document = XDocument.Load(fs);

                var binDirPath = Path.Combine(Path.GetDirectoryName(resxFilePath), "bin");
                if (!Directory.Exists(binDirPath))
                {
                    Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(resxFilePath), "bin"));
                }

                // Put in "bin" sub-folder of resx file
                var targetPath = Path.Combine(binDirPath, Path.ChangeExtension(Path.GetFileName(resxFilePath), ".resources"));

                using (var targetStream = File.Create(targetPath))
                {
                    var rw = new ResourceWriter(targetStream);

                    foreach (var e in document.Root.Elements("data"))
                    {
                        var name = e.Attribute("name").Value;
                        var value = e.Element("value").Value;

                        rw.AddResource(name, value);
                    }

                    rw.Generate();
                }
            }
        }
开发者ID:morarsebastian,项目名称:i18nStarterWeb,代码行数:31,代码来源:ResxFileCompilation.cs

示例2: SystemResourceTests_Should_WriteUpdateValueToResx

        public void SystemResourceTests_Should_WriteUpdateValueToResx()
        {
            var filename = Path.Combine(TestContext.TestRunDirectory, Guid.NewGuid().ToString() + ".resx");

            var inputData = "TheInputData";

            using (ResourceWriter w = new ResourceWriter(filename))
            {

                w.AddResource("InvariantName", inputData);
                w.Generate();
            }

            inputData = "TheUpdatedInputData";

            using (ResourceWriter w = new ResourceWriter(filename))
            {

                w.AddResource("InvariantName", inputData);
                w.Generate();
            }

            var data = string.Empty;

            using( var r = new ResourceReader(filename))
            {
                var rr = r.GetEnumerator();
                rr.MoveNext();

                data = rr.Value as string;

            }

            Assert.IsTrue(inputData == data);
        }
开发者ID:zachbonham,项目名称:Lingua,代码行数:35,代码来源:System.Resource.Tests.cs

示例3: Run

        public void Run()
        {
            Catalog catalog = new Catalog();
            foreach(string fileName in Options.InputFiles)
            {
                Catalog temp = new Catalog();
                temp.Load(fileName);
                catalog.Append(temp);
            }

            using (ResourceWriter writer = new ResourceWriter(Options.OutFile))
            {
                foreach (CatalogEntry entry in catalog)
                {
                    try
                    {
                        writer.AddResource(entry.Key, entry.IsTranslated ? entry.GetTranslation(0) : entry.String);
                    }
                    catch (Exception e)
                    {
                        string message = String.Format("Error adding item {0}", entry.String);
                        if (!String.IsNullOrEmpty(entry.Context))
                            message = String.Format("Error adding item {0} in context '{1}'",
                                                    entry.String, entry.Context);
                        throw new Exception(message, e);
                    }
                }
                writer.Generate();
            }
        }
开发者ID:rzaitov,项目名称:GetTextNet,代码行数:30,代码来源:ResourcesGen.cs

示例4: MakeResourceStream

 private static Stream MakeResourceStream()
 {
     var stream = new MemoryStream();
     var resourceWriter = new ResourceWriter(stream);            
     resourceWriter.AddResource("TestName", "value");
     resourceWriter.Generate();
     stream.Position = 0;
     return stream;
 }
开发者ID:qiudesong,项目名称:Localization,代码行数:9,代码来源:ResourceManagerStringLocalizerTest.cs

示例5: Main

        static void Main(string[] args)
        {
            var getopt = new Getopt(Assembly.GetExecutingAssembly().GetName().Name, args, "i:o:") { Opterr = false };

            string input = null;
            string output = null;

            int option;
            while (-1 != (option = getopt.getopt()))
            {
                switch (option)
                {
                    case 'i': input = getopt.Optarg; break;
                    case 'o': output = getopt.Optarg; break;

                    default: PrintUsage(); return;
                }
            }

            if (input == null || output == null)
            {
                PrintUsage();
                return;
            }

            try
            {
                if (!File.Exists(input))
                {
                    Console.WriteLine("File {0} not found", input);
                    return;
                }

                Dictionary<string, string> entries;
                var parser = new PoParser();
                using (var reader = new StreamReader(input))
                {
                    entries = parser.ParseIntoDictionary(reader);
                }

                using (var writer = new ResourceWriter(output))
                {
                    foreach (var kv in entries)
                    {
                        try { writer.AddResource(kv.Key, kv.Value); }
                        catch (Exception e) { Console.WriteLine("Error adding item {0}: {1}", kv.Key, e.Message); }
                    }
                    writer.Generate();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error during execution: {0}", ex.Message);
                return;
            }
        }
开发者ID:LvlAndFarm,项目名称:gettext-cs-utils,代码行数:56,代码来源:Program.cs

示例6: AddItem

        public void AddItem(string entity, string key, string value, string culture)
        {
            var filename = GetResourceFilename(entity, culture);

            using (var writer = new ResourceWriter(filename))
            {
                writer.AddResource(key, value);
                writer.Generate();
            }
        }
开发者ID:zachbonham,项目名称:Lingua,代码行数:10,代码来源:FileRepository.cs

示例7: EnsureRepositoryFileExists

 internal void EnsureRepositoryFileExists()
 {
     if (!File.Exists(this.RepositoryFilename))
     {
         using (IResourceWriter writer = new ResourceWriter(this.RepositoryFilename))
         {
             writer.Generate();
         }
     }
 }
开发者ID:dangilkerson,项目名称:ApprovalTestsVS2010,代码行数:10,代码来源:ImageAdornmentRepositoryService.cs

示例8: SystemResourceTests_Should_CreateResxFile

        public void SystemResourceTests_Should_CreateResxFile()
        {
            var filename = Path.Combine(TestContext.TestRunDirectory, Guid.NewGuid().ToString() + ".resx");

            using (ResourceWriter w = new ResourceWriter(filename))
            {
                w.Generate();
            }

            Assert.IsTrue(File.Exists(filename));
        }
开发者ID:zachbonham,项目名称:Lingua,代码行数:11,代码来源:System.Resource.Tests.cs

示例9: ReadAllInput

 // Read all msgid/msgstr pairs, register them in the ResourceWriter,
 // and write the binary contents to the output stream.
 private void ReadAllInput (ResourceWriter rw) {
   for (;;) {
     String msgid = ReadString();
     if (msgid == null)
       break;
     String msgstr = ReadString();
     if (msgstr == null)
       break;
     rw.AddResource(msgid, msgstr);
   }
   rw.Generate();
 }
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:14,代码来源:msgfmt.cs

示例10: CreateResource

        private static void CreateResource()
        {
            FileStream stream = File.OpenWrite(ResourceFile);

            using (var writer = new ResourceWriter(stream))
            {
                writer.AddResource("Title", "Professional C#");
                writer.AddResource("Author", "Christian Nagel");
                writer.AddResource("Publisher", "Wrox Press");

                writer.Generate();
            }
        }
开发者ID:ProfessionalCSharp,项目名称:ProfessionalCSharp6,代码行数:13,代码来源:Program.cs

示例11: GenerateResourceStream

        public static ResourceWriter GenerateResourceStream(Dictionary<string, string> inp_dict, MemoryStream ms)
        {

            ResourceWriter rw = new ResourceWriter(ms);
            foreach (KeyValuePair<string, string> e in inp_dict)
            {
                string name = e.Key;
                string values = e.Value;
                rw.AddResource(name, values);
            }
            rw.Generate();
            ms.Seek(0L, SeekOrigin.Begin);
            return rw;
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:14,代码来源:ResourceReaderUnitTest.cs

示例12: WriteResourcesFile

        private static void WriteResourcesFile(Stream outfs, IEnumerable<XElement> data)
        {
            var rw = new ResourceWriter(outfs);

            foreach (var e in data)
            {
                var name = e.Attribute("name").Value;
                var value = e.Element("value").Value;

                rw.AddResource(name, value);
            }

            rw.Generate();
        }
开发者ID:niemyjski,项目名称:cli,代码行数:14,代码来源:Program.cs

示例13: New

        /// <summary>
        /// TODO - Refactor into just creating the resource 'MyResource'.  AddItem will handle the key/value pairs.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="key"></param>
        /// <param name="data"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public string New(string entity, string culture)
        {
            var filename = GetResourceFilename(entity, culture);

            if (File.Exists(filename))
            {
                // TODO - Replace this with an EntityAlreadyExistsException or something similar - IOException is too generic
                //
                throw new IOException("File already exists: " + filename);
            }

            using (var writer = new ResourceWriter(filename))
            {
                writer.Generate();
            }
            return filename;
        }
开发者ID:zachbonham,项目名称:Lingua,代码行数:25,代码来源:FileRepository.cs

示例14: WriteResourcesFile

        private static void WriteResourcesFile(string resxFilePath, string outputFile)
        {
            using (var fs = File.OpenRead(resxFilePath))
            using (var outfs = File.Create(outputFile))
            {
                var document = XDocument.Load(fs);

                var rw = new ResourceWriter(outfs);

                foreach (var e in document.Root.Elements("data"))
                {
                    string name = e.Attribute("name").Value;
                    string value = e.Element("value").Value;

                    rw.AddResource(name, value);
                }

                rw.Generate();
            }
        }
开发者ID:krwq,项目名称:cli-1,代码行数:20,代码来源:Program.cs

示例15: Generate

        public static void Generate(ResourceFile sourceFile, Stream outputStream)
        {
            if (outputStream == null) throw new ArgumentNullException(nameof(outputStream));
            using (var input = sourceFile.File.OpenRead())
            {
                var document = XDocument.Load(input);
                var data = document.Root.Elements("data");
                if (data.Any())
                {
                    var rw = new ResourceWriter(outputStream);

                    foreach (var e in data)
                    {
                        var name = e.Attribute("name").Value;
                        var value = e.Element("value").Value;
                        rw.AddResource(name, value);
                    }

                    rw.Generate();
                }
            }
        }
开发者ID:yonglehou,项目名称:cli-1,代码行数:22,代码来源:ResourcesFileGenerator.cs


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