System.IO.TextWriter.Close C# (CSharp) Méthode

Close() public méthode

public Close ( ) : void
Résultat void
        public virtual void Close()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

Usage Example

        public void Compile(string fileName)
        {
            var parent = Directory.GetParent(fileName);
            var dir = Directory.CreateDirectory($"output_{parent.Name}");

            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);

            var tacFilePath = $"{dir.FullName}/{fileNameWithoutExtension}.tac";
            var asmFilePath = $"{dir.FullName}/{fileNameWithoutExtension}.asm";
            try
            {
                FileIn = File.CreateText(tacFilePath);
                var streamReader = new StreamReader(fileName);
                var lexAnalyzer = new LexicalAnalyzerService(streamReader);
                var symbolTable = new SymbolTable
                {
                    Printer = (val) =>
                    {
                        Console.WriteLine(val);
                    }
                };

                var syntaxParser = new SyntaxParserService(lexAnalyzer, symbolTable);

                PrintSourceCode(File.ReadAllText(fileName));
                syntaxParser.Parse();
                FileIn.Close();

                Intelx86GeneratorService.Generate(
                    File.ReadAllLines(tacFilePath),
                    syntaxParser.GlobalStrings,
                    syntaxParser.MethodLocalSize,
                    syntaxParser.MethodParamSize,
                    (str) => {
                        if (File.Exists(asmFilePath))
                        {
                            File.Delete(asmFilePath);
                        }

                        File.AppendAllText(asmFilePath, str);
                        Console.WriteLine(str);
                    });

            }
            catch (Exception ex)
            {
                // Delete out file
                if (File.Exists(tacFilePath))
                {
                    FileIn.Close();
                    File.Delete(tacFilePath);
                }

                Print("Oops, there seems to be something wrong.\n\n", ErrorColor);
                Print(ex.Message, ErrorColor);
            }
        }
All Usage Examples Of System.IO.TextWriter::Close