From 8dfba25d5900a8fc4d0f73d56cbc110fcce5c3db Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Tue, 4 Jul 2017 18:48:28 -0700 Subject: [PATCH] Streamline collections Makes our collections sealed instead of abstract. Only the IntermediateNodeCollection needs to have a read only variant. --- .../InjectIntermediateNode.cs | 2 +- .../DefaultCodeRenderingContext.cs | 4 +- ...DefaultAllowedChildTagDescriptorBuilder.cs | 4 +- .../DefaultBoundAttributeDescriptorBuilder.cs | 4 +- .../DefaultItemCollection.cs | 116 ----------- .../DefaultRazorCodeDocument.cs | 2 +- .../DefaultRazorDiagnosticCollection.cs | 128 ------------ ...faultRequiredAttributeDescriptorBuilder.cs | 4 +- .../DefaultTagHelperDescriptorBuilder.cs | 4 +- ...DefaultTagMatchingRuleDescriptorBuilder.cs | 4 +- .../DefaultTagHelperBodyIntermediateNode.cs | 2 +- .../DefaultTagHelperCreateIntermediateNode.cs | 2 +- ...DefaultTagHelperExecuteIntermediateNode.cs | 2 +- ...tTagHelperHtmlAttributeIntermediateNode.cs | 2 +- ...efaultTagHelperPropertyIntermediateNode.cs | 2 +- ...DefaultTagHelperRuntimeIntermediateNode.cs | 2 +- .../DesignTimeDirectiveIntermediateNode.cs | 2 +- ...dTagHelperHtmlAttributeIntermediateNode.cs | 2 +- ...elperHtmlAttributeValueIntermediateNode.cs | 2 +- ...ocatedTagHelperPropertyIntermediateNode.cs | 2 +- ...dTagHelperPropertyValueIntermediateNode.cs | 2 +- .../Extensions/SectionIntermediateNode.cs | 2 +- .../Extensions/TemplateIntermediateNode.cs | 2 +- ...SharpCodeAttributeValueIntermediateNode.cs | 2 +- .../CSharpCodeIntermediateNode.cs | 2 +- ...xpressionAttributeValueIntermediateNode.cs | 2 +- .../CSharpExpressionIntermediateNode.cs | 2 +- .../ClassDeclarationIntermediateNode.cs | 2 +- .../DefaultIntermediateNodeCollection.cs | 128 ------------ .../Intermediate/DirectiveIntermediateNode.cs | 2 +- .../DirectiveTokenIntermediateNode.cs | 2 +- .../Intermediate/DocumentIntermediateNode.cs | 2 +- .../FieldDeclarationIntermediateNode.cs | 2 +- .../HtmlAttributeIntermediateNode.cs | 2 +- .../HtmlAttributeValueIntermediateNode.cs | 2 +- .../HtmlContentIntermediateNode.cs | 2 +- .../Intermediate/IntermediateNode.cs | 4 +- .../IntermediateNodeCollection.cs | 184 ++++++++++++++++-- .../Intermediate/IntermediateToken.cs | 2 +- .../MalformedDirectiveIntermediateNode.cs | 2 +- .../MethodDeclarationIntermediateNode.cs | 2 +- .../NamespaceDeclarationIntermediateNode.cs | 2 +- .../PropertyDeclarationIntermediateNode.cs | 2 +- .../ReadOnlyIntermediateNodeCollection.cs | 133 ------------- .../TagHelperBodyIntermediateNode.cs | 2 +- .../TagHelperHtmlAttributeIntermediateNode.cs | 2 +- .../Intermediate/TagHelperIntermediateNode.cs | 2 +- .../TagHelperPropertyIntermediateNode.cs | 2 +- .../UsingDirectiveIntermediateNode.cs | 2 +- .../ItemCollection.cs | 110 +++++++++-- .../RazorDiagnosticCollection.cs | 177 +++++++++++++++-- .../ReadOnlyDiagnosticCollection.cs | 133 ------------- .../ReadOnlyItemCollection.cs | 93 --------- .../TagHelperDescriptorProviderContext.cs | 2 +- .../DesignTimeNodeWriterTest.cs | 2 +- .../CodeGeneration/RuntimeNodeWriterTest.cs | 2 +- .../DefaultItemCollectionTest.cs | 8 +- ...DefaultRazorIntermediateNodeBuilderTest.cs | 2 +- .../ExtensionIntermediateNodeTest.cs | 2 +- .../IntermediateNodeReferenceTest.cs | 14 +- .../IntermediateNodeWalkerTest.cs | 2 +- 61 files changed, 502 insertions(+), 836 deletions(-) delete mode 100644 src/Microsoft.AspNetCore.Razor.Language/DefaultItemCollection.cs delete mode 100644 src/Microsoft.AspNetCore.Razor.Language/DefaultRazorDiagnosticCollection.cs delete mode 100644 src/Microsoft.AspNetCore.Razor.Language/Intermediate/DefaultIntermediateNodeCollection.cs delete mode 100644 src/Microsoft.AspNetCore.Razor.Language/Intermediate/ReadOnlyIntermediateNodeCollection.cs delete mode 100644 src/Microsoft.AspNetCore.Razor.Language/ReadOnlyDiagnosticCollection.cs delete mode 100644 src/Microsoft.AspNetCore.Razor.Language/ReadOnlyItemCollection.cs diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/InjectIntermediateNode.cs b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/InjectIntermediateNode.cs index fb6fc261f3..e1dfe9cf15 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/InjectIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/InjectIntermediateNode.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions public string MemberName { get; set; } - public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; + public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; public override void Accept(IntermediateNodeVisitor visitor) { diff --git a/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DefaultCodeRenderingContext.cs b/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DefaultCodeRenderingContext.cs index 97b4a23d96..ae0691e7f2 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DefaultCodeRenderingContext.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DefaultCodeRenderingContext.cs @@ -52,8 +52,8 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration _documentNode = documentNode; Options = options; - Diagnostics = new DefaultRazorDiagnosticCollection(); - Items = new DefaultItemCollection(); + Diagnostics = new RazorDiagnosticCollection(); + Items = new ItemCollection(); LineMappings = new List(); TagHelperRenderingContext = new TagHelperRenderingContext(); diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultAllowedChildTagDescriptorBuilder.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultAllowedChildTagDescriptorBuilder.cs index 75897d93fc..b420992e80 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultAllowedChildTagDescriptorBuilder.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultAllowedChildTagDescriptorBuilder.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Razor.Language internal class DefaultAllowedChildTagDescriptorBuilder : AllowedChildTagDescriptorBuilder { private readonly DefaultTagHelperDescriptorBuilder _parent; - private DefaultRazorDiagnosticCollection _diagnostics; + private RazorDiagnosticCollection _diagnostics; public DefaultAllowedChildTagDescriptorBuilder(DefaultTagHelperDescriptorBuilder parent) { @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Razor.Language { if (_diagnostics == null) { - _diagnostics = new DefaultRazorDiagnosticCollection(); + _diagnostics = new RazorDiagnosticCollection(); } return _diagnostics; diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultBoundAttributeDescriptorBuilder.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultBoundAttributeDescriptorBuilder.cs index 0db2e0d826..0652686dd2 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultBoundAttributeDescriptorBuilder.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultBoundAttributeDescriptorBuilder.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Razor.Language private readonly string _kind; private readonly Dictionary _metadata; - private DefaultRazorDiagnosticCollection _diagnostics; + private RazorDiagnosticCollection _diagnostics; public DefaultBoundAttributeDescriptorBuilder(DefaultTagHelperDescriptorBuilder parent, string kind) { @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Razor.Language { if (_diagnostics == null) { - _diagnostics = new DefaultRazorDiagnosticCollection(); + _diagnostics = new RazorDiagnosticCollection(); } return _diagnostics; diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultItemCollection.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultItemCollection.cs deleted file mode 100644 index 4ae88bf8b6..0000000000 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultItemCollection.cs +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; - -namespace Microsoft.AspNetCore.Razor.Language -{ - internal class DefaultItemCollection : ItemCollection - { - private readonly Dictionary _items; - - public DefaultItemCollection() - { - _items = new Dictionary(); - } - - public override object this[object key] - { - get - { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - - object value; - _items.TryGetValue(key, out value); - return value; - } - - set - { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - - _items[key] = value; - } - } - - public override int Count => _items.Count; - - public override bool IsReadOnly => false; - - public override void Add(object key, object value) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - - _items.Add(key, value); - } - - public override void Add(KeyValuePair item) - { - if (item.Key == null) - { - throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item)); - } - - ((ICollection>)_items).Add(item); - } - - public override void Clear() - { - _items.Clear(); - } - - public override bool Contains(KeyValuePair item) - { - if (item.Key == null) - { - throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item)); - } - - return ((ICollection>)_items).Contains(item); - } - - public override void CopyTo(KeyValuePair[] array, int arrayIndex) - { - if (array == null) - { - throw new ArgumentNullException(nameof(array)); - } - - if (arrayIndex < 0 || arrayIndex > array.Length) - { - throw new ArgumentOutOfRangeException(nameof(arrayIndex)); - } - else if (array.Length - arrayIndex < Count) - { - throw new ArgumentOutOfRangeException(nameof(arrayIndex)); - } - - ((ICollection>)_items).CopyTo(array, arrayIndex); - } - - public override IEnumerator> GetEnumerator() - { - return _items.GetEnumerator(); - } - - public override bool Remove(KeyValuePair item) - { - if (item.Key == null) - { - throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item)); - } - - return ((ICollection>)_items).Remove(item); - } - } -} diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorCodeDocument.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorCodeDocument.cs index d603da59cf..bceb14cbda 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorCodeDocument.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorCodeDocument.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Razor.Language Source = source; Imports = imports?.ToArray() ?? RazorSourceDocument.EmptyArray; - Items = new DefaultItemCollection(); + Items = new ItemCollection(); } public override IReadOnlyList Imports { get; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorDiagnosticCollection.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorDiagnosticCollection.cs deleted file mode 100644 index 92d59bb480..0000000000 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorDiagnosticCollection.cs +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; - -namespace Microsoft.AspNetCore.Razor.Language -{ - public sealed class DefaultRazorDiagnosticCollection : RazorDiagnosticCollection - { - private readonly List _inner = new List(); - - public override RazorDiagnostic this[int index] - { - get - { - if (index < 0 || index >= Count) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - return _inner[index]; - } - set - { - if (index < 0 || index >= Count) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - _inner[index] = value; - } - } - - public override int Count => _inner.Count; - - public override bool IsReadOnly => false; - - public override void Add(RazorDiagnostic item) - { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - _inner.Add(item); - } - - public override void Clear() - { - _inner.Clear(); - } - - public override bool Contains(RazorDiagnostic item) - { - return _inner.Contains(item); - } - - public override void CopyTo(RazorDiagnostic[] array, int arrayIndex) - { - if (array == null) - { - throw new ArgumentNullException(nameof(array)); - } - - if (arrayIndex < 0 || arrayIndex > array.Length) - { - throw new ArgumentOutOfRangeException(nameof(arrayIndex)); - } - else if (array.Length - arrayIndex < Count) - { - throw new ArgumentOutOfRangeException(nameof(arrayIndex)); - } - - _inner.CopyTo(array, arrayIndex); - } - - public override IEnumerator GetEnumerator() - { - return _inner.GetEnumerator(); - } - - public override int IndexOf(RazorDiagnostic item) - { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - return _inner.IndexOf(item); - } - - public override void Insert(int index, RazorDiagnostic item) - { - if (index < 0 || index > Count) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - _inner.Insert(index, item); - } - - public override bool Remove(RazorDiagnostic item) - { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - return _inner.Remove(item); - } - - public override void RemoveAt(int index) - { - if (index < 0 || index >= Count) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - _inner.RemoveAt(index); - } - } -} diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultRequiredAttributeDescriptorBuilder.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultRequiredAttributeDescriptorBuilder.cs index d46f40323d..5b611b7b20 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultRequiredAttributeDescriptorBuilder.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultRequiredAttributeDescriptorBuilder.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language { internal class DefaultRequiredAttributeDescriptorBuilder : RequiredAttributeDescriptorBuilder { - private DefaultRazorDiagnosticCollection _diagnostics; + private RazorDiagnosticCollection _diagnostics; public override string Name { get; set; } @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Razor.Language { if (_diagnostics == null) { - _diagnostics = new DefaultRazorDiagnosticCollection(); + _diagnostics = new RazorDiagnosticCollection(); } return _diagnostics; diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultTagHelperDescriptorBuilder.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultTagHelperDescriptorBuilder.cs index 703bd65c02..3dcd280a11 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultTagHelperDescriptorBuilder.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultTagHelperDescriptorBuilder.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Razor.Language private List _allowedChildTags; private List _attributeBuilders; private List _tagMatchingRuleBuilders; - private DefaultRazorDiagnosticCollection _diagnostics; + private RazorDiagnosticCollection _diagnostics; public DefaultTagHelperDescriptorBuilder(string kind, string name, string assemblyName) { @@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Razor.Language { if (_diagnostics == null) { - _diagnostics = new DefaultRazorDiagnosticCollection(); + _diagnostics = new RazorDiagnosticCollection(); } return _diagnostics; diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultTagMatchingRuleDescriptorBuilder.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultTagMatchingRuleDescriptorBuilder.cs index dd690c971e..7cfb80eebc 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultTagMatchingRuleDescriptorBuilder.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultTagMatchingRuleDescriptorBuilder.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Razor.Language internal class DefaultTagMatchingRuleDescriptorBuilder : TagMatchingRuleDescriptorBuilder { private List _requiredAttributeBuilders; - private DefaultRazorDiagnosticCollection _diagnostics; + private RazorDiagnosticCollection _diagnostics; internal DefaultTagMatchingRuleDescriptorBuilder() { @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Razor.Language { if (_diagnostics == null) { - _diagnostics = new DefaultRazorDiagnosticCollection(); + _diagnostics = new RazorDiagnosticCollection(); } return _diagnostics; diff --git a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperBodyIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperBodyIntermediateNode.cs index ab035c5aad..461df52991 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperBodyIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperBodyIntermediateNode.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions } } - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public TagMode TagMode { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperCreateIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperCreateIntermediateNode.cs index 8742f07418..85094bb52f 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperCreateIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperCreateIntermediateNode.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions { public sealed class DefaultTagHelperCreateIntermediateNode : ExtensionIntermediateNode { - public override IntermediateNodeCollection Children { get; } = ReadOnlyIntermediateNodeCollection.Instance; + public override IntermediateNodeCollection Children { get; } = IntermediateNodeCollection.ReadOnly; public string Field { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperExecuteIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperExecuteIntermediateNode.cs index bde4e4a634..35d4fa195c 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperExecuteIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperExecuteIntermediateNode.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions { public sealed class DefaultTagHelperExecuteIntermediateNode : ExtensionIntermediateNode { - public override IntermediateNodeCollection Children { get; } = ReadOnlyIntermediateNodeCollection.Instance; + public override IntermediateNodeCollection Children { get; } = IntermediateNodeCollection.ReadOnly; public override void Accept(IntermediateNodeVisitor visitor) { diff --git a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperHtmlAttributeIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperHtmlAttributeIntermediateNode.cs index dd44dac55d..4122f66ef2 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperHtmlAttributeIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperHtmlAttributeIntermediateNode.cs @@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions public AttributeStructure AttributeStructure { get; set; } - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public override void Accept(IntermediateNodeVisitor visitor) { diff --git a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperPropertyIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperPropertyIntermediateNode.cs index fa2f5af21b..578d53392f 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperPropertyIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperPropertyIntermediateNode.cs @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions } } - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public string AttributeName { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperRuntimeIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperRuntimeIntermediateNode.cs index 5d37a5debe..74f33baddd 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperRuntimeIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DefaultTagHelperRuntimeIntermediateNode.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions { public sealed class DefaultTagHelperRuntimeIntermediateNode : ExtensionIntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public override void Accept(IntermediateNodeVisitor visitor) { diff --git a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DesignTimeDirectiveIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DesignTimeDirectiveIntermediateNode.cs index 1898b8fb00..ef1e971584 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Extensions/DesignTimeDirectiveIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Extensions/DesignTimeDirectiveIntermediateNode.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions { internal sealed class DesignTimeDirectiveIntermediateNode : ExtensionIntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public override void Accept(IntermediateNodeVisitor visitor) { diff --git a/src/Microsoft.AspNetCore.Razor.Language/Extensions/PreallocatedTagHelperHtmlAttributeIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Extensions/PreallocatedTagHelperHtmlAttributeIntermediateNode.cs index d786e8eb26..11501c1a26 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Extensions/PreallocatedTagHelperHtmlAttributeIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Extensions/PreallocatedTagHelperHtmlAttributeIntermediateNode.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions { internal sealed class PreallocatedTagHelperHtmlAttributeIntermediateNode : ExtensionIntermediateNode { - public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; + public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; public string VariableName { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Extensions/PreallocatedTagHelperHtmlAttributeValueIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Extensions/PreallocatedTagHelperHtmlAttributeValueIntermediateNode.cs index 80eb93b27f..03bb175094 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Extensions/PreallocatedTagHelperHtmlAttributeValueIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Extensions/PreallocatedTagHelperHtmlAttributeValueIntermediateNode.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions } } - public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; + public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; public string VariableName { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Extensions/PreallocatedTagHelperPropertyIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Extensions/PreallocatedTagHelperPropertyIntermediateNode.cs index 2fff1cc874..01da47b567 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Extensions/PreallocatedTagHelperPropertyIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Extensions/PreallocatedTagHelperPropertyIntermediateNode.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions TagHelper = propertyNode.TagHelper; } - public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; + public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; public string AttributeName { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Extensions/PreallocatedTagHelperPropertyValueIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Extensions/PreallocatedTagHelperPropertyValueIntermediateNode.cs index 067f13fda1..d769905ff4 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Extensions/PreallocatedTagHelperPropertyValueIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Extensions/PreallocatedTagHelperPropertyValueIntermediateNode.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions { internal sealed class PreallocatedTagHelperPropertyValueIntermediateNode : ExtensionIntermediateNode { - public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; + public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; public string VariableName { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Extensions/SectionIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Extensions/SectionIntermediateNode.cs index bd4039460c..0666d49c12 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Extensions/SectionIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Extensions/SectionIntermediateNode.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions { public sealed class SectionIntermediateNode : ExtensionIntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public string Name { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Extensions/TemplateIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Extensions/TemplateIntermediateNode.cs index 18ccda7fe3..76c81a94a3 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Extensions/TemplateIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Extensions/TemplateIntermediateNode.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions { public sealed class TemplateIntermediateNode : ExtensionIntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public override void Accept(IntermediateNodeVisitor visitor) { diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/CSharpCodeAttributeValueIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/CSharpCodeAttributeValueIntermediateNode.cs index cb2fe554c2..23eff1efda 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/CSharpCodeAttributeValueIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/CSharpCodeAttributeValueIntermediateNode.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class CSharpCodeAttributeValueIntermediateNode : IntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public string Prefix { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/CSharpCodeIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/CSharpCodeIntermediateNode.cs index 74577572aa..f15ce8b067 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/CSharpCodeIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/CSharpCodeIntermediateNode.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class CSharpCodeIntermediateNode : IntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public override void Accept(IntermediateNodeVisitor visitor) { diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/CSharpExpressionAttributeValueIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/CSharpExpressionAttributeValueIntermediateNode.cs index 413ab8ed25..6cc7a837e4 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/CSharpExpressionAttributeValueIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/CSharpExpressionAttributeValueIntermediateNode.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class CSharpExpressionAttributeValueIntermediateNode : IntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public string Prefix { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/CSharpExpressionIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/CSharpExpressionIntermediateNode.cs index 889bc6f134..42b25a8df3 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/CSharpExpressionIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/CSharpExpressionIntermediateNode.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class CSharpExpressionIntermediateNode : IntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public override void Accept(IntermediateNodeVisitor visitor) { diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/ClassDeclarationIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/ClassDeclarationIntermediateNode.cs index 14be3bf113..85dc1aeb7c 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/ClassDeclarationIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/ClassDeclarationIntermediateNode.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class ClassDeclarationIntermediateNode : MemberDeclarationIntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public IList Modifiers { get; } = new List(); diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/DefaultIntermediateNodeCollection.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/DefaultIntermediateNodeCollection.cs deleted file mode 100644 index 699a759dfb..0000000000 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/DefaultIntermediateNodeCollection.cs +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; - -namespace Microsoft.AspNetCore.Razor.Language.Intermediate -{ - public sealed class DefaultIntermediateNodeCollection : IntermediateNodeCollection - { - private readonly List _inner = new List(); - - public override IntermediateNode this[int index] - { - get - { - if (index < 0 || index >= Count) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - return _inner[index]; - } - set - { - if (index < 0 || index >= Count) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - _inner[index] = value; - } - } - - public override int Count => _inner.Count; - - public override bool IsReadOnly => false; - - public override void Add(IntermediateNode item) - { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - _inner.Add(item); - } - - public override void Clear() - { - _inner.Clear(); - } - - public override bool Contains(IntermediateNode item) - { - return _inner.Contains(item); - } - - public override void CopyTo(IntermediateNode[] array, int arrayIndex) - { - if (array == null) - { - throw new ArgumentNullException(nameof(array)); - } - - if (arrayIndex < 0 || arrayIndex > array.Length) - { - throw new ArgumentOutOfRangeException(nameof(arrayIndex)); - } - else if (array.Length - arrayIndex < Count) - { - throw new ArgumentOutOfRangeException(nameof(arrayIndex)); - } - - _inner.CopyTo(array, arrayIndex); - } - - public override IEnumerator GetEnumerator() - { - return _inner.GetEnumerator(); - } - - public override int IndexOf(IntermediateNode item) - { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - return _inner.IndexOf(item); - } - - public override void Insert(int index, IntermediateNode item) - { - if (index < 0 || index > Count) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - _inner.Insert(index, item); - } - - public override bool Remove(IntermediateNode item) - { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - return _inner.Remove(item); - } - - public override void RemoveAt(int index) - { - if (index < 0 || index >= Count) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - _inner.RemoveAt(index); - } - } -} diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/DirectiveIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/DirectiveIntermediateNode.cs index de92bcba27..6c1b4c114e 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/DirectiveIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/DirectiveIntermediateNode.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class DirectiveIntermediateNode : IntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public string Name { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/DirectiveTokenIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/DirectiveTokenIntermediateNode.cs index 1187a4fb75..dba8688c78 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/DirectiveTokenIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/DirectiveTokenIntermediateNode.cs @@ -5,7 +5,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class DirectiveTokenIntermediateNode : IntermediateNode { - public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; + public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; public string Content { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/DocumentIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/DocumentIntermediateNode.cs index 7564cbb03c..af071a7488 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/DocumentIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/DocumentIntermediateNode.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class DocumentIntermediateNode : IntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public string DocumentKind { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/FieldDeclarationIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/FieldDeclarationIntermediateNode.cs index d93e4ef06e..b0227bd5f4 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/FieldDeclarationIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/FieldDeclarationIntermediateNode.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class FieldDeclarationIntermediateNode : MemberDeclarationIntermediateNode { - public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; + public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; public IList Modifiers { get; } = new List(); diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/HtmlAttributeIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/HtmlAttributeIntermediateNode.cs index e8861673b5..46f772fce9 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/HtmlAttributeIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/HtmlAttributeIntermediateNode.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class HtmlAttributeIntermediateNode : IntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public string AttributeName { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/HtmlAttributeValueIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/HtmlAttributeValueIntermediateNode.cs index dc85dea404..d22eaa78aa 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/HtmlAttributeValueIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/HtmlAttributeValueIntermediateNode.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class HtmlAttributeValueIntermediateNode : IntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public string Prefix { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/HtmlContentIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/HtmlContentIntermediateNode.cs index acf0f6d064..d41b8a6a47 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/HtmlContentIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/HtmlContentIntermediateNode.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class HtmlContentIntermediateNode : IntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public override void Accept(IntermediateNodeVisitor visitor) { diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/IntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/IntermediateNode.cs index 96f55a3de1..f8970d23f6 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/IntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/IntermediateNode.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { if (_annotations == null) { - _annotations = new DefaultItemCollection(); + _annotations = new ItemCollection(); } return _annotations; @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { if (_diagnostics == null) { - _diagnostics = new DefaultRazorDiagnosticCollection(); + _diagnostics = new RazorDiagnosticCollection(); } return _diagnostics; diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/IntermediateNodeCollection.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/IntermediateNodeCollection.cs index 7a200cc244..4c50fa1240 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/IntermediateNodeCollection.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/IntermediateNodeCollection.cs @@ -1,40 +1,198 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections; using System.Collections.Generic; namespace Microsoft.AspNetCore.Razor.Language.Intermediate { - public abstract class IntermediateNodeCollection : IList + public sealed class IntermediateNodeCollection : IList { - public abstract IntermediateNode this[int index] { get; set; } + public static readonly IntermediateNodeCollection ReadOnly = new IntermediateNodeCollection(new List().AsReadOnly()); - public abstract int Count { get; } + private readonly IList _inner; - public abstract bool IsReadOnly { get; } + public IntermediateNodeCollection() + : this(new List()) + { + } - public abstract void Add(IntermediateNode item); + private IntermediateNodeCollection(IList inner) + { + _inner = inner; + } - public abstract void Clear(); + public IntermediateNode this[int index] + { + get + { + if (index < 0 || index >= Count) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } - public abstract bool Contains(IntermediateNode item); + return _inner[index]; + } + set + { + if (index < 0 || index >= Count) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } - public abstract void CopyTo(IntermediateNode[] array, int arrayIndex); + _inner[index] = value; + } + } - public abstract IEnumerator GetEnumerator(); + public int Count => _inner.Count; - public abstract int IndexOf(IntermediateNode item); + public bool IsReadOnly => _inner.IsReadOnly; - public abstract void Insert(int index, IntermediateNode item); + public void Add(IntermediateNode item) + { + if (item == null) + { + throw new ArgumentNullException(nameof(item)); + } - public abstract bool Remove(IntermediateNode item); + _inner.Add(item); + } - public abstract void RemoveAt(int index); + public void Clear() + { + _inner.Clear(); + } + + public bool Contains(IntermediateNode item) + { + return _inner.Contains(item); + } + + public void CopyTo(IntermediateNode[] array, int arrayIndex) + { + if (array == null) + { + throw new ArgumentNullException(nameof(array)); + } + + if (arrayIndex < 0 || arrayIndex > array.Length) + { + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); + } + else if (array.Length - arrayIndex < Count) + { + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); + } + + _inner.CopyTo(array, arrayIndex); + } + + public Enumerator GetEnumerator() + { + return new Enumerator(this); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } + + public int IndexOf(IntermediateNode item) + { + if (item == null) + { + throw new ArgumentNullException(nameof(item)); + } + + return _inner.IndexOf(item); + } + + public void Insert(int index, IntermediateNode item) + { + if (index < 0 || index > Count) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + + if (item == null) + { + throw new ArgumentNullException(nameof(item)); + } + + _inner.Insert(index, item); + } + + public bool Remove(IntermediateNode item) + { + if (item == null) + { + throw new ArgumentNullException(nameof(item)); + } + + return _inner.Remove(item); + } + + public void RemoveAt(int index) + { + if (index < 0 || index >= Count) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + + _inner.RemoveAt(index); + } + + public struct Enumerator : IEnumerator + { + private readonly IList _items; + private int _index; + + public Enumerator(IntermediateNodeCollection collection) + { + if (collection == null) + { + throw new ArgumentNullException(nameof(collection)); + } + + _items = collection._inner; + _index = -1; + } + + public IntermediateNode Current + { + get + { + if (_index < 0 || _index >= _items.Count) + { + return null; + } + + return _items[_index]; + } + } + + object IEnumerator.Current => Current; + + public void Dispose() + { + } + + public bool MoveNext() + { + _index++; + return _index < _items.Count; + } + + public void Reset() + { + _index = -1; + } + } } } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/IntermediateToken.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/IntermediateToken.cs index 440f2d8747..fd2498602a 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/IntermediateToken.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/IntermediateToken.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class IntermediateToken : IntermediateNode { - public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; + public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; public string Content { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/MalformedDirectiveIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/MalformedDirectiveIntermediateNode.cs index 5d87ec48da..1ccfec030a 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/MalformedDirectiveIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/MalformedDirectiveIntermediateNode.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class MalformedDirectiveIntermediateNode : IntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public string Name { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/MethodDeclarationIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/MethodDeclarationIntermediateNode.cs index 04e77d2d78..877e30f325 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/MethodDeclarationIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/MethodDeclarationIntermediateNode.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class MethodDeclarationIntermediateNode : MemberDeclarationIntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public IList Modifiers { get; } = new List(); diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/NamespaceDeclarationIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/NamespaceDeclarationIntermediateNode.cs index 55585a78f0..d4626c7ba3 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/NamespaceDeclarationIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/NamespaceDeclarationIntermediateNode.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class NamespaceDeclarationIntermediateNode : IntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public string Content { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/PropertyDeclarationIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/PropertyDeclarationIntermediateNode.cs index 175fdfab47..a7ebaeb759 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/PropertyDeclarationIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/PropertyDeclarationIntermediateNode.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class PropertyDeclarationIntermediateNode : MemberDeclarationIntermediateNode { - public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; + public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; public IList Modifiers { get; } = new List(); diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/ReadOnlyIntermediateNodeCollection.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/ReadOnlyIntermediateNodeCollection.cs deleted file mode 100644 index b46a0eaae7..0000000000 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/ReadOnlyIntermediateNodeCollection.cs +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Microsoft.AspNetCore.Razor.Language.Intermediate -{ - public sealed class ReadOnlyIntermediateNodeCollection : IntermediateNodeCollection - { - public static readonly ReadOnlyIntermediateNodeCollection Instance = new ReadOnlyIntermediateNodeCollection(); - - private ReadOnlyIntermediateNodeCollection() - { - } - - public override IntermediateNode this[int index] - { - get - { - if (index < 0 || index >= Count) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - throw null; // Unreachable - } - set - { - if (index < 0 || index >= Count) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - throw null; // Unreachable - } - } - - public override int Count => 0; - - public override bool IsReadOnly => true; - - public override void Add(IntermediateNode item) - { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - throw new NotSupportedException(); - } - - public override void Clear() - { - throw new NotSupportedException(); - } - - public override bool Contains(IntermediateNode item) - { - return false; - } - - public override void CopyTo(IntermediateNode[] array, int arrayIndex) - { - if (array == null) - { - throw new ArgumentNullException(nameof(array)); - } - - if (arrayIndex < 0 || arrayIndex > array.Length) - { - throw new ArgumentOutOfRangeException(nameof(arrayIndex)); - } - else if (array.Length - arrayIndex < Count) - { - throw new ArgumentOutOfRangeException(nameof(arrayIndex)); - } - - throw new NotSupportedException(); - } - - public override IEnumerator GetEnumerator() - { - return Enumerable.Empty().GetEnumerator(); - } - - public override int IndexOf(IntermediateNode item) - { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - return -1; - } - - public override void Insert(int index, IntermediateNode item) - { - if (index < 0 || index > Count) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - throw new NotSupportedException(); - } - - public override bool Remove(IntermediateNode item) - { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - return false; - } - - public override void RemoveAt(int index) - { - if (index < 0 || index >= Count) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - throw new NotSupportedException(); - } - } -} diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/TagHelperBodyIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/TagHelperBodyIntermediateNode.cs index 376098a757..ebf5b0eac0 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/TagHelperBodyIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/TagHelperBodyIntermediateNode.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class TagHelperBodyIntermediateNode : IntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public override void Accept(IntermediateNodeVisitor visitor) { diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/TagHelperHtmlAttributeIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/TagHelperHtmlAttributeIntermediateNode.cs index 27c283e854..4b7cee465b 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/TagHelperHtmlAttributeIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/TagHelperHtmlAttributeIntermediateNode.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class TagHelperHtmlAttributeIntermediateNode : IntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public string AttributeName { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/TagHelperIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/TagHelperIntermediateNode.cs index e547e921b4..2003882a19 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/TagHelperIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/TagHelperIntermediateNode.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class TagHelperIntermediateNode : IntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public TagMode TagMode { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/TagHelperPropertyIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/TagHelperPropertyIntermediateNode.cs index 99b9df22ab..073571b185 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/TagHelperPropertyIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/TagHelperPropertyIntermediateNode.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class TagHelperPropertyIntermediateNode : IntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public string AttributeName { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/UsingDirectiveIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/UsingDirectiveIntermediateNode.cs index 9da19e4560..4199c95e97 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/UsingDirectiveIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/UsingDirectiveIntermediateNode.cs @@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate { public sealed class UsingDirectiveIntermediateNode : IntermediateNode { - public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; + public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; public string Content { get; set; } diff --git a/src/Microsoft.AspNetCore.Razor.Language/ItemCollection.cs b/src/Microsoft.AspNetCore.Razor.Language/ItemCollection.cs index ef5144a2a3..dc6ab9723f 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/ItemCollection.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/ItemCollection.cs @@ -1,36 +1,124 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections; using System.Collections.Generic; namespace Microsoft.AspNetCore.Razor.Language { - public abstract class ItemCollection : ICollection> + public sealed class ItemCollection : ICollection> { - public abstract object this[object key] { get; set; } + private readonly Dictionary _inner; - public abstract int Count { get; } + public ItemCollection() + { + _inner = new Dictionary(); + } - public abstract bool IsReadOnly { get; } + public object this[object key] + { + get + { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + + _inner.TryGetValue(key, out var value); + return value; + } + set + { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } - public abstract void Add(object key, object value); + _inner[key] = value; + } + } - public abstract void Add(KeyValuePair item); + public int Count => _inner.Count; - public abstract void Clear(); + public bool IsReadOnly => _inner != null; - public abstract bool Contains(KeyValuePair item); + int ICollection>.Count => throw new NotImplementedException(); - public abstract void CopyTo(KeyValuePair[] array, int arrayIndex); + bool ICollection>.IsReadOnly => throw new NotImplementedException(); - public abstract IEnumerator> GetEnumerator(); + public void Add(KeyValuePair item) + { + if (item.Key == null) + { + throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item)); + } - public abstract bool Remove(KeyValuePair item); + ((ICollection>)_inner).Add(item); + } + + public void Add(object key, object value) + { + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + + _inner.Add(key, value); + } + + public void Clear() + { + _inner.Clear(); + } + + public bool Contains(KeyValuePair item) + { + if (item.Key == null) + { + throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item)); + } + + return ((ICollection>)_inner).Contains(item); + } + + public void CopyTo(KeyValuePair[] array, int arrayIndex) + { + if (array == null) + { + throw new ArgumentNullException(nameof(array)); + } + + if (arrayIndex < 0 || arrayIndex > array.Length) + { + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); + } + else if (array.Length - arrayIndex < Count) + { + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); + } + + ((ICollection>)_inner).CopyTo(array, arrayIndex); + } + + public IEnumerator> GetEnumerator() + { + return _inner.GetEnumerator(); + } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } + + public bool Remove(KeyValuePair item) + { + if (item.Key == null) + { + throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item)); + } + + return ((ICollection>)_inner).Remove(item); + } } } diff --git a/src/Microsoft.AspNetCore.Razor.Language/RazorDiagnosticCollection.cs b/src/Microsoft.AspNetCore.Razor.Language/RazorDiagnosticCollection.cs index 24e7d8b1db..46f35ac3e0 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/RazorDiagnosticCollection.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/RazorDiagnosticCollection.cs @@ -1,40 +1,191 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections; using System.Collections.Generic; namespace Microsoft.AspNetCore.Razor.Language { - public abstract class RazorDiagnosticCollection : IList + public sealed class RazorDiagnosticCollection : IList { - public abstract RazorDiagnostic this[int index] { get; set; } + private readonly List _inner; - public abstract int Count { get; } + public RazorDiagnosticCollection() + { + _inner = new List(); + } - public abstract bool IsReadOnly { get; } + public RazorDiagnostic this[int index] + { + get + { + if (index < 0 || index >= Count) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } - public abstract void Add(RazorDiagnostic item); + return _inner[index]; + } + set + { + if (index < 0 || index >= Count) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } - public abstract void Clear(); + _inner[index] = value; + } + } - public abstract bool Contains(RazorDiagnostic item); + public int Count => _inner.Count; - public abstract void CopyTo(RazorDiagnostic[] array, int arrayIndex); + public bool IsReadOnly => _inner != null; - public abstract IEnumerator GetEnumerator(); + public void Add(RazorDiagnostic item) + { + if (item == null) + { + throw new ArgumentNullException(nameof(item)); + } - public abstract int IndexOf(RazorDiagnostic item); + _inner.Add(item); + } - public abstract void Insert(int index, RazorDiagnostic item); + public void Clear() + { + _inner.Clear(); + } - public abstract bool Remove(RazorDiagnostic item); + public bool Contains(RazorDiagnostic item) + { + return _inner.Contains(item); + } - public abstract void RemoveAt(int index); + public void CopyTo(RazorDiagnostic[] array, int arrayIndex) + { + if (array == null) + { + throw new ArgumentNullException(nameof(array)); + } + + if (arrayIndex < 0 || arrayIndex > array.Length) + { + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); + } + else if (array.Length - arrayIndex < Count) + { + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); + } + + _inner.CopyTo(array, arrayIndex); + } + + public Enumerator GetEnumerator() + { + return new Enumerator(this); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } + + public int IndexOf(RazorDiagnostic item) + { + if (item == null) + { + throw new ArgumentNullException(nameof(item)); + } + + return _inner.IndexOf(item); + } + + public void Insert(int index, RazorDiagnostic item) + { + if (index < 0 || index > Count) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + + if (item == null) + { + throw new ArgumentNullException(nameof(item)); + } + + _inner.Insert(index, item); + } + + public bool Remove(RazorDiagnostic item) + { + if (item == null) + { + throw new ArgumentNullException(nameof(item)); + } + + return _inner.Remove(item); + } + + public void RemoveAt(int index) + { + if (index < 0 || index >= Count) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + + _inner.RemoveAt(index); + } + + public struct Enumerator : IEnumerator + { + private readonly IList _items; + private int _index; + + public Enumerator(RazorDiagnosticCollection collection) + { + if (collection == null) + { + throw new ArgumentNullException(nameof(collection)); + } + + _items = collection._inner; + _index = -1; + } + + public RazorDiagnostic Current + { + get + { + if (_index < 0 || _index >= _items.Count) + { + return null; + } + + return _items[_index]; + } + } + + object IEnumerator.Current => Current; + + public void Dispose() + { + } + + public bool MoveNext() + { + _index++; + return _index < _items.Count; + } + + public void Reset() + { + _index = -1; + } + } } } diff --git a/src/Microsoft.AspNetCore.Razor.Language/ReadOnlyDiagnosticCollection.cs b/src/Microsoft.AspNetCore.Razor.Language/ReadOnlyDiagnosticCollection.cs deleted file mode 100644 index 775ef49a90..0000000000 --- a/src/Microsoft.AspNetCore.Razor.Language/ReadOnlyDiagnosticCollection.cs +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Microsoft.AspNetCore.Razor.Language -{ - public sealed class ReadOnlyDiagnosticCollection : RazorDiagnosticCollection - { - public static readonly ReadOnlyDiagnosticCollection Instance = new ReadOnlyDiagnosticCollection(); - - private ReadOnlyDiagnosticCollection() - { - } - - public override RazorDiagnostic this[int index] - { - get - { - if (index < 0 || index >= Count) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - throw null; // Unreachable - } - set - { - if (index < 0 || index >= Count) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - throw null; // Unreachable - } - } - - public override int Count => 0; - - public override bool IsReadOnly => true; - - public override void Add(RazorDiagnostic item) - { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - throw new NotSupportedException(); - } - - public override void Clear() - { - throw new NotSupportedException(); - } - - public override bool Contains(RazorDiagnostic item) - { - return false; - } - - public override void CopyTo(RazorDiagnostic[] array, int arrayIndex) - { - if (array == null) - { - throw new ArgumentNullException(nameof(array)); - } - - if (arrayIndex < 0 || arrayIndex > array.Length) - { - throw new ArgumentOutOfRangeException(nameof(arrayIndex)); - } - else if (array.Length - arrayIndex < Count) - { - throw new ArgumentOutOfRangeException(nameof(arrayIndex)); - } - - throw new NotSupportedException(); - } - - public override IEnumerator GetEnumerator() - { - return Enumerable.Empty().GetEnumerator(); - } - - public override int IndexOf(RazorDiagnostic item) - { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - return -1; - } - - public override void Insert(int index, RazorDiagnostic item) - { - if (index < 0 || index > Count) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - throw new NotSupportedException(); - } - - public override bool Remove(RazorDiagnostic item) - { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - return false; - } - - public override void RemoveAt(int index) - { - if (index < 0 || index >= Count) - { - throw new ArgumentOutOfRangeException(nameof(index)); - } - - throw new NotSupportedException(); - } - } -} diff --git a/src/Microsoft.AspNetCore.Razor.Language/ReadOnlyItemCollection.cs b/src/Microsoft.AspNetCore.Razor.Language/ReadOnlyItemCollection.cs deleted file mode 100644 index beb9200d2a..0000000000 --- a/src/Microsoft.AspNetCore.Razor.Language/ReadOnlyItemCollection.cs +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Microsoft.AspNetCore.Razor.Language -{ - internal class ReadOnlyItemCollection : ItemCollection - { - public static readonly ItemCollection Empty = new ReadOnlyItemCollection(); - - public override object this[object key] - { - get => null; - set => throw new NotSupportedException(); - } - - public override int Count => 0; - - public override bool IsReadOnly => true; - - public override void Add(object key, object value) - { - if (key == null) - { - throw new ArgumentNullException(nameof(key)); - } - - throw new NotSupportedException(); - } - - public override void Add(KeyValuePair item) - { - if (item.Key == null) - { - throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item)); - } - - throw new NotSupportedException(); - } - - public override void Clear() - { - throw new NotSupportedException(); - } - - public override bool Contains(KeyValuePair item) - { - if (item.Key == null) - { - throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item)); - } - - return false; - } - - public override void CopyTo(KeyValuePair[] array, int arrayIndex) - { - if (array == null) - { - throw new ArgumentNullException(nameof(array)); - } - - if (arrayIndex < 0 || arrayIndex > array.Length) - { - throw new ArgumentOutOfRangeException(nameof(arrayIndex)); - } - else if (array.Length - arrayIndex < Count) - { - throw new ArgumentOutOfRangeException(nameof(arrayIndex)); - } - - // Do nothing. - } - - public override IEnumerator> GetEnumerator() - { - return Enumerable.Empty>().GetEnumerator(); - } - - public override bool Remove(KeyValuePair item) - { - if (item.Key == null) - { - throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item)); - } - - throw new NotSupportedException(); - } - } -} diff --git a/src/Microsoft.AspNetCore.Razor.Language/TagHelperDescriptorProviderContext.cs b/src/Microsoft.AspNetCore.Razor.Language/TagHelperDescriptorProviderContext.cs index ef228b9156..e8ad7b8219 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/TagHelperDescriptorProviderContext.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/TagHelperDescriptorProviderContext.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Razor.Language { Results = results; - Items = new DefaultItemCollection(); + Items = new ItemCollection(); } public override ItemCollection Items { get; } diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/CodeGeneration/DesignTimeNodeWriterTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/CodeGeneration/DesignTimeNodeWriterTest.cs index 1038e4d84e..eeb7ef37ac 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/CodeGeneration/DesignTimeNodeWriterTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/CodeGeneration/DesignTimeNodeWriterTest.cs @@ -472,7 +472,7 @@ Render Children private class MyExtensionIntermediateNode : ExtensionIntermediateNode { - public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; + public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; public override void Accept(IntermediateNodeVisitor visitor) { diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/CodeGeneration/RuntimeNodeWriterTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/CodeGeneration/RuntimeNodeWriterTest.cs index 85b2244501..ea24ff2c02 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/CodeGeneration/RuntimeNodeWriterTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/CodeGeneration/RuntimeNodeWriterTest.cs @@ -583,7 +583,7 @@ WriteAttributeValue("" "", 27, false, 28, 6, false); private class MyExtensionIntermediateNode : ExtensionIntermediateNode { - public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; + public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; public override void Accept(IntermediateNodeVisitor visitor) { diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/DefaultItemCollectionTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/DefaultItemCollectionTest.cs index 44a7b16b26..aee4d07fe0 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/DefaultItemCollectionTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/DefaultItemCollectionTest.cs @@ -5,13 +5,13 @@ using Xunit; namespace Microsoft.AspNetCore.Razor.Language { - public class DefaultItemCollectionTest + public class ItemCollectionTest { [Fact] public void Get_MissingValueReturnsNull() { // Arrange - var items = new DefaultItemCollection(); + var items = new ItemCollection(); // Act var value = items["foo"]; @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Razor.Language public void GetAndSet_ReturnsValue() { // Arrange - var items = new DefaultItemCollection(); + var items = new ItemCollection(); var expected = "bar"; items["foo"] = expected; @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Razor.Language public void Set_CanSetValueToNull() { // Arrange - var items = new DefaultItemCollection(); + var items = new ItemCollection(); items["foo"] = "bar"; diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Intermediate/DefaultRazorIntermediateNodeBuilderTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Intermediate/DefaultRazorIntermediateNodeBuilderTest.cs index affdfdeab0..f4813684e1 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/Intermediate/DefaultRazorIntermediateNodeBuilderTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Intermediate/DefaultRazorIntermediateNodeBuilderTest.cs @@ -206,7 +206,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate private class BasicIntermediateNode : IntermediateNode { - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public override void Accept(IntermediateNodeVisitor visitor) { diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Intermediate/ExtensionIntermediateNodeTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Intermediate/ExtensionIntermediateNodeTest.cs index ae604bf47e..a4bf7950ae 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/Intermediate/ExtensionIntermediateNodeTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Intermediate/ExtensionIntermediateNodeTest.cs @@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate private class TestExtensionIntermediateNode : ExtensionIntermediateNode { - public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; + public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; public override void Accept(IntermediateNodeVisitor visitor) { diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Intermediate/IntermediateNodeReferenceTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Intermediate/IntermediateNodeReferenceTest.cs index ea8f1286f4..2adbe06a4f 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/Intermediate/IntermediateNodeReferenceTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Intermediate/IntermediateNodeReferenceTest.cs @@ -305,7 +305,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate public void InsertAfter_SingleNode_ThrowsForReadOnlyCollection() { // Arrange - var parent = new BasicIntermediateNode("Parent", ReadOnlyIntermediateNodeCollection.Instance); + var parent = new BasicIntermediateNode("Parent", IntermediateNodeCollection.ReadOnly); var node1 = new BasicIntermediateNode("Node1"); @@ -320,7 +320,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate public void InsertAfter_MulipleNodes_ThrowsForReadOnlyCollection() { // Arrange - var parent = new BasicIntermediateNode("Parent", ReadOnlyIntermediateNodeCollection.Instance); + var parent = new BasicIntermediateNode("Parent", IntermediateNodeCollection.ReadOnly); var node1 = new BasicIntermediateNode("Node1"); @@ -335,7 +335,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate public void InsertBefore_SingleNode_ThrowsForReadOnlyCollection() { // Arrange - var parent = new BasicIntermediateNode("Parent", ReadOnlyIntermediateNodeCollection.Instance); + var parent = new BasicIntermediateNode("Parent", IntermediateNodeCollection.ReadOnly); var node1 = new BasicIntermediateNode("Node1"); @@ -350,7 +350,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate public void InsertBefore_MulipleNodes_ThrowsForReadOnlyCollection() { // Arrange - var parent = new BasicIntermediateNode("Parent", ReadOnlyIntermediateNodeCollection.Instance); + var parent = new BasicIntermediateNode("Parent", IntermediateNodeCollection.ReadOnly); var node1 = new BasicIntermediateNode("Node1"); @@ -365,7 +365,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate public void Remove_ThrowsForReadOnlyCollection() { // Arrange - var parent = new BasicIntermediateNode("Parent", ReadOnlyIntermediateNodeCollection.Instance); + var parent = new BasicIntermediateNode("Parent", IntermediateNodeCollection.ReadOnly); var node1 = new BasicIntermediateNode("Node1"); @@ -380,7 +380,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate public void Replace_ThrowsForReadOnlyCollection() { // Arrange - var parent = new BasicIntermediateNode("Parent", ReadOnlyIntermediateNodeCollection.Instance); + var parent = new BasicIntermediateNode("Parent", IntermediateNodeCollection.ReadOnly); var node1 = new BasicIntermediateNode("Node1"); @@ -484,7 +484,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate private class BasicIntermediateNode : IntermediateNode { public BasicIntermediateNode(string name) - : this(name, new DefaultIntermediateNodeCollection()) + : this(name, new IntermediateNodeCollection()) { Name = name; } diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Intermediate/IntermediateNodeWalkerTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Intermediate/IntermediateNodeWalkerTest.cs index 70207317f3..50f0894df6 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/Intermediate/IntermediateNodeWalkerTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Intermediate/IntermediateNodeWalkerTest.cs @@ -124,7 +124,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate public string Name { get; } - public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); public override void Accept(IntermediateNodeVisitor visitor) {