System.IO.File.WriteAllText C# (CSharp) Méthode

WriteAllText() private méthode

private WriteAllText ( String path, String contents ) : void
path String
contents String
Résultat void
        public static void WriteAllText(String path, String contents)
        {
            if (path == null)
                throw new ArgumentNullException(nameof(path));
            if (path.Length == 0)
                throw new ArgumentException(SR.Argument_EmptyPath, nameof(path));
            Contract.EndContractBlock();

            using (StreamWriter sw = new StreamWriter(path))
            {
                sw.Write(contents);
            }
        }

Same methods

File::WriteAllText ( String path, String contents, Encoding encoding ) : void
File::WriteAllText ( string path, string contents ) : void
File::WriteAllText ( string path, string contents, System encoding ) : void

Usage Example

        public void Compile()
        {
            Console.WriteLine("start compile");
            var projectPath = Directory.GetCurrentDirectory();

            //load files
            var files = Directory.GetFiles(Path.Combine(projectPath, sourceFolder));

            var sourceFiles = files
                .Where(y => Path.GetExtension(y) == sourceFileExtension)
                .Select(x => new HDL.Parser.File()
                {
                    Name = Path.GetFileNameWithoutExtension(x),
                    Value = File.ReadAllText(x)
                })
                .ToList();

            Console.WriteLine($"Load {sourceFiles.Count} files");

            new ParserController(sourceFiles, x =>
            {
                Console.WriteLine($"{x.Count} tokens found");
                var compiler = new CompilerController(x, result =>
                {
                    new VHDLGeneratorController().GenerateCode(result, code =>
                    {
                        Console.WriteLine("Result");
                        Console.WriteLine("_______________________");
                        Console.WriteLine(code);
                        File.WriteAllText(Path.Combine(projectPath, outputFolder, outputFileName), code);
                    });
                });
            });
        }
All Usage Examples Of System.IO.File::WriteAllText