public void Dispose()
        {
            if (_addLineMapping)
            {
                // Verify that the generated length has not already been calculated
                if (_generatedContentLength == 0)
                {
                    _generatedContentLength = _writer.GenerateCode().Length - _generatedLocation.AbsoluteIndex;
                }

                var generatedLocation = new MappingLocation(_generatedLocation, _generatedContentLength);
                var documentMapping   = _documentMapping;
                if (documentMapping.ContentLength == -1)
                {
                    documentMapping = new MappingLocation(
                        location: new SourceLocation(
                            _documentMapping.FilePath,
                            _documentMapping.AbsoluteIndex,
                            _documentMapping.LineIndex,
                            _documentMapping.CharacterIndex),
                        contentLength: _generatedContentLength);
                }

                _writer.LineMappingManager.AddMapping(
                    documentLocation: documentMapping,
                    generatedLocation: generatedLocation);
            }

            if (_writePragmas)
            {
                // Need to add an additional line at the end IF there wasn't one already written.
                // This is needed to work with the C# editor's handling of #line ...
                var endsWithNewline = _writer.GenerateCode().EndsWith("\n");

                // Always write at least 1 empty line to potentially separate code from pragmas.
                _writer.WriteLine();

                // Check if the previous empty line wasn't enough to separate code from pragmas.
                if (!endsWithNewline)
                {
                    _writer.WriteLine();
                }

                _writer.WriteLineDefaultDirective()
                .WriteLineHiddenDirective();
            }

            // Reset indent back to when it was started
            _writer.SetIndent(_startIndent);
        }
Exemplo n.º 2
0
        public void Dispose()
        {
            if (_addLineMapping)
            {
                // Verify that the generated length has not already been calculated
                if (_generatedContentLength == 0)
                {
                    _generatedContentLength = _writer.GenerateCode().Length - _generatedLocation.AbsoluteIndex;
                }

                var generatedLocation = new MappingLocation(_generatedLocation, _generatedContentLength);
                var documentMapping = _documentMapping;
                if (documentMapping.ContentLength == -1)
                {
                    documentMapping = new MappingLocation(
                        location: new SourceLocation(
                            _documentMapping.AbsoluteIndex,
                            _documentMapping.LineIndex,
                            _documentMapping.CharacterIndex),
                        contentLength: _generatedContentLength);
                }

                _writer.LineMappingManager.AddMapping(
                    documentLocation: documentMapping,
                    generatedLocation: generatedLocation);
            }

            if (_writePragmas)
            {
                // Need to add an additional line at the end IF there wasn't one already written.
                // This is needed to work with the C# editor's handling of #line ...
                var endsWithNewline = _writer.GenerateCode().EndsWith("\n");

                // Always write at least 1 empty line to potentially separate code from pragmas.
                _writer.WriteLine();

                // Check if the previous empty line wasn't enough to separate code from pragmas.
                if (!endsWithNewline)
                {
                    _writer.WriteLine();
                }

                _writer.WriteLineDefaultDirective()
                    .WriteLineHiddenDirective();
            }

            // Reset indent back to when it was started
            _writer.SetIndent(_startIndent);
        }
Exemplo n.º 3
0
 public CSharpLineMappingWriter(CSharpCodeWriter writer, SourceLocation documentLocation, int contentLength)
     : this(writer, addLineMappings: true)
 {
     _documentMapping = new MappingLocation(documentLocation, contentLength);
     _generatedLocation = _writer.GetCurrentSourceLocation();
 }
Exemplo n.º 4
0
 public LineMapping(MappingLocation documentLocation, MappingLocation generatedLocation)
 {
     DocumentLocation = documentLocation;
     GeneratedLocation = generatedLocation;
 }
Exemplo n.º 5
0
 public void AddMapping(MappingLocation documentLocation, MappingLocation generatedLocation)
 {
     Mappings.Add(new LineMapping(documentLocation, generatedLocation));
 }
Exemplo n.º 6
0
 public LineMapping(MappingLocation documentLocation, MappingLocation generatedLocation)
 {
     DocumentLocation  = documentLocation;
     GeneratedLocation = generatedLocation;
 }
Exemplo n.º 7
0
 public void AddMapping(MappingLocation documentLocation, MappingLocation generatedLocation)
 {
     Mappings.Add(new LineMapping(documentLocation, generatedLocation));
 }
Exemplo n.º 8
0
 public CSharpLineMappingWriter(CSharpCodeWriter writer, SourceLocation documentLocation, int contentLength)
     : this(writer, addLineMappings : true)
 {
     _documentMapping   = new MappingLocation(documentLocation, contentLength);
     _generatedLocation = _writer.GetCurrentSourceLocation();
 }