private string GetContent(RazorSourceDocument imports)
        {
            var contentChars = new char[imports.Length];

            imports.CopyTo(0, contentChars, 0, imports.Length);
            return(new string(contentChars));
        }
        public static string Serialize(RazorCSharpDocument csharpDocument, RazorSourceDocument sourceDocument)
        {
            var builder        = new StringBuilder();
            var sourceFilePath = sourceDocument.FilePath;
            var charBuffer     = new char[sourceDocument.Length];

            sourceDocument.CopyTo(0, charBuffer, 0, sourceDocument.Length);
            var sourceContent = new string(charBuffer);

            for (var i = 0; i < csharpDocument.SourceMappings.Count; i++)
            {
                var sourceMapping = csharpDocument.SourceMappings[i];
                if (!string.Equals(sourceMapping.OriginalSpan.FilePath, sourceFilePath, StringComparison.Ordinal))
                {
                    continue;
                }

                builder.Append("Source Location: ");
                AppendMappingLocation(builder, sourceMapping.OriginalSpan, sourceContent);

                builder.Append("Generated Location: ");
                AppendMappingLocation(builder, sourceMapping.GeneratedSpan, csharpDocument.GeneratedCode);

                builder.AppendLine();
            }

            return(builder.ToString());
        }
    private static string ReadContent(RazorSourceDocument razorSourceDocument)
    {
        var buffer = new char[razorSourceDocument.Length];

        razorSourceDocument.CopyTo(0, buffer, 0, buffer.Length);

        return(new string(buffer));
    }
Esempio n. 4
0
        protected override void OnCreatingCodeDocument(ref RazorSourceDocument source, IList <RazorSourceDocument> imports)
        {
            // It's important that we normalize the newlines in the default imports. The default imports will
            // be created with Environment.NewLine, but we need to normalize to `\r\n` so that the indices
            // are the same on xplat.
            var buffer = new char[DefaultImports.Length];

            DefaultImports.CopyTo(0, buffer, 0, DefaultImports.Length);

            var text = new string(buffer);

            text = Regex.Replace(text, "(?<!\r)\n", "\r\n");

            imports.Add(RazorSourceDocument.Create(text, DefaultImports.FilePath, DefaultImports.Encoding));
        }
Esempio n. 5
0
        public ParserContext(RazorSourceDocument source, RazorParserOptions options)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            SourceDocument = source;
            var chars = new char[source.Length];

            source.CopyTo(0, chars, 0, source.Length);

            Source                 = new SeekableTextReader(chars, source.FilePath);
            DesignTimeMode         = options.DesignTime;
            FeatureFlags           = options.FeatureFlags;
            ParseLeadingDirectives = options.ParseLeadingDirectives;
            ErrorSink              = new ErrorSink();
            SeenDirectives         = new HashSet <string>(StringComparer.Ordinal);
        }
Esempio n. 6
0
 public override void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)
 => _innerSourceDocument.CopyTo(sourceIndex, destination, destinationIndex, count);