Ejemplo n.º 1
0
    public void AddRange(RazorDiagnosticCollection items)
    {
        if (items == null)
        {
            throw new ArgumentNullException(nameof(items));
        }

        _inner.AddRange(items);
    }
Ejemplo n.º 2
0
        public Enumerator(RazorDiagnosticCollection collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }

            _items = collection._inner;
            _index = -1;
        }
        public DefaultCodeRenderingContext(
            CodeWriter codeWriter,
            IntermediateNodeWriter nodeWriter,
            RazorCodeDocument codeDocument,
            DocumentIntermediateNode documentNode,
            RazorCodeGenerationOptions options)
        {
            if (codeWriter == null)
            {
                throw new ArgumentNullException(nameof(codeWriter));
            }

            if (nodeWriter == null)
            {
                throw new ArgumentNullException(nameof(nodeWriter));
            }

            if (codeDocument == null)
            {
                throw new ArgumentNullException(nameof(codeDocument));
            }

            if (documentNode == null)
            {
                throw new ArgumentNullException(nameof(documentNode));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            CodeWriter    = codeWriter;
            _codeDocument = codeDocument;
            _documentNode = documentNode;
            Options       = options;

            _ancestors     = new Stack <IntermediateNode>();
            Diagnostics    = new RazorDiagnosticCollection();
            Items          = new ItemCollection();
            SourceMappings = new List <SourceMapping>();

            var diagnostics = _documentNode.GetAllDiagnostics();

            for (var i = 0; i < diagnostics.Count; i++)
            {
                Diagnostics.Add(diagnostics[i]);
            }


            _scopes = new List <ScopeInternal>();
            _scopes.Add(new ScopeInternal(nodeWriter));
        }
        private static void ReadDiagnostic(JsonReader reader, RazorDiagnosticCollection diagnostics)
        {
            if (!reader.Read())
            {
                return;
            }

            if (reader.TokenType != JsonToken.StartObject)
            {
                return;
            }

            string     id         = default;
            int        severity   = default;
            string     message    = default;
            SourceSpan sourceSpan = default;

            reader.ReadProperties(propertyName =>
            {
                switch (propertyName)
                {
                case nameof(RazorDiagnostic.Id):
                    if (reader.Read())
                    {
                        id = (string)reader.Value;
                    }
                    break;

                case nameof(RazorDiagnostic.Severity):
                    severity = reader.ReadAsInt32().Value;
                    break;

                case "Message":
                    if (reader.Read())
                    {
                        message = (string)reader.Value;
                    }
                    break;

                case nameof(RazorDiagnostic.Span):
                    sourceSpan = ReadSourceSpan(reader);
                    break;
                }
            });

            var descriptor = new RazorDiagnosticDescriptor(id, () => message, (RazorDiagnosticSeverity)severity);

            var diagnostic = RazorDiagnostic.Create(descriptor, sourceSpan);

            diagnostics.Add(diagnostic);
        }
        private static void ReadDiagnostics(JsonReader reader, RazorDiagnosticCollection diagnostics)
        {
            if (!reader.Read())
            {
                return;
            }

            if (reader.TokenType != JsonToken.StartArray)
            {
                return;
            }

            do
            {
                ReadDiagnostic(reader, diagnostics);
            } while (reader.TokenType != JsonToken.EndArray);
        }
        public DefaultCodeRenderingContext(
            CodeWriter codeWriter,
            IntermediateNodeWriter nodeWriter,
            RazorCodeDocument codeDocument,
            DocumentIntermediateNode documentNode,
            RazorCodeGenerationOptions options)
        {
            if (codeWriter == null)
            {
                throw new ArgumentNullException(nameof(codeWriter));
            }

            if (nodeWriter == null)
            {
                throw new ArgumentNullException(nameof(nodeWriter));
            }

            if (codeDocument == null)
            {
                throw new ArgumentNullException(nameof(codeDocument));
            }

            if (documentNode == null)
            {
                throw new ArgumentNullException(nameof(documentNode));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            CodeWriter    = codeWriter;
            _codeDocument = codeDocument;
            _documentNode = documentNode;
            Options       = options;

            _ancestors     = new Stack <IntermediateNode>();
            Diagnostics    = new RazorDiagnosticCollection();
            Items          = new ItemCollection();
            SourceMappings = new List <SourceMapping>();

            var diagnostics = _documentNode.GetAllDiagnostics();

            for (var i = 0; i < diagnostics.Count; i++)
            {
                Diagnostics.Add(diagnostics[i]);
            }

            var newLineString = codeDocument.Items[NewLineString];

            if (newLineString != null)
            {
                // Set new line character to a specific string regardless of platform, for testing purposes.
                codeWriter.NewLine = (string)newLineString;
            }

            Items[NewLineString]     = codeDocument.Items[NewLineString];
            Items[SuppressUniqueIds] = codeDocument.Items[SuppressUniqueIds];

            _scopes = new List <ScopeInternal>();
            _scopes.Add(new ScopeInternal(nodeWriter));
        }