Streamline collections

Makes our collections sealed instead of abstract.

Only the IntermediateNodeCollection needs to have a read only variant.
This commit is contained in:
Ryan Nowak 2017-07-04 18:48:28 -07:00
parent d36838ed88
commit 8dfba25d59
61 changed files with 502 additions and 836 deletions

View File

@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
public string MemberName { get; set; } public string MemberName { get; set; }
public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly;
public override void Accept(IntermediateNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {

View File

@ -52,8 +52,8 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
_documentNode = documentNode; _documentNode = documentNode;
Options = options; Options = options;
Diagnostics = new DefaultRazorDiagnosticCollection(); Diagnostics = new RazorDiagnosticCollection();
Items = new DefaultItemCollection(); Items = new ItemCollection();
LineMappings = new List<LineMapping>(); LineMappings = new List<LineMapping>();
TagHelperRenderingContext = new TagHelperRenderingContext(); TagHelperRenderingContext = new TagHelperRenderingContext();

View File

@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Razor.Language
internal class DefaultAllowedChildTagDescriptorBuilder : AllowedChildTagDescriptorBuilder internal class DefaultAllowedChildTagDescriptorBuilder : AllowedChildTagDescriptorBuilder
{ {
private readonly DefaultTagHelperDescriptorBuilder _parent; private readonly DefaultTagHelperDescriptorBuilder _parent;
private DefaultRazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
public DefaultAllowedChildTagDescriptorBuilder(DefaultTagHelperDescriptorBuilder parent) public DefaultAllowedChildTagDescriptorBuilder(DefaultTagHelperDescriptorBuilder parent)
{ {
@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultRazorDiagnosticCollection(); _diagnostics = new RazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;

View File

@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Razor.Language
private readonly string _kind; private readonly string _kind;
private readonly Dictionary<string, string> _metadata; private readonly Dictionary<string, string> _metadata;
private DefaultRazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
public DefaultBoundAttributeDescriptorBuilder(DefaultTagHelperDescriptorBuilder parent, string kind) public DefaultBoundAttributeDescriptorBuilder(DefaultTagHelperDescriptorBuilder parent, string kind)
{ {
@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultRazorDiagnosticCollection(); _diagnostics = new RazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;

View File

@ -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<object, object> _items;
public DefaultItemCollection()
{
_items = new Dictionary<object, object>();
}
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<object, object> item)
{
if (item.Key == null)
{
throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item));
}
((ICollection<KeyValuePair<object, object>>)_items).Add(item);
}
public override void Clear()
{
_items.Clear();
}
public override bool Contains(KeyValuePair<object, object> item)
{
if (item.Key == null)
{
throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item));
}
return ((ICollection<KeyValuePair<object, object>>)_items).Contains(item);
}
public override void CopyTo(KeyValuePair<object, object>[] 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<KeyValuePair<object, object>>)_items).CopyTo(array, arrayIndex);
}
public override IEnumerator<KeyValuePair<object, object>> GetEnumerator()
{
return _items.GetEnumerator();
}
public override bool Remove(KeyValuePair<object, object> item)
{
if (item.Key == null)
{
throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item));
}
return ((ICollection<KeyValuePair<object, object>>)_items).Remove(item);
}
}
}

View File

@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Razor.Language
Source = source; Source = source;
Imports = imports?.ToArray() ?? RazorSourceDocument.EmptyArray; Imports = imports?.ToArray() ?? RazorSourceDocument.EmptyArray;
Items = new DefaultItemCollection(); Items = new ItemCollection();
} }
public override IReadOnlyList<RazorSourceDocument> Imports { get; } public override IReadOnlyList<RazorSourceDocument> Imports { get; }

View File

@ -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<RazorDiagnostic> _inner = new List<RazorDiagnostic>();
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<RazorDiagnostic> 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);
}
}
}

View File

@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
internal class DefaultRequiredAttributeDescriptorBuilder : RequiredAttributeDescriptorBuilder internal class DefaultRequiredAttributeDescriptorBuilder : RequiredAttributeDescriptorBuilder
{ {
private DefaultRazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
public override string Name { get; set; } public override string Name { get; set; }
@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultRazorDiagnosticCollection(); _diagnostics = new RazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;

View File

@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Razor.Language
private List<DefaultAllowedChildTagDescriptorBuilder> _allowedChildTags; private List<DefaultAllowedChildTagDescriptorBuilder> _allowedChildTags;
private List<DefaultBoundAttributeDescriptorBuilder> _attributeBuilders; private List<DefaultBoundAttributeDescriptorBuilder> _attributeBuilders;
private List<DefaultTagMatchingRuleDescriptorBuilder> _tagMatchingRuleBuilders; private List<DefaultTagMatchingRuleDescriptorBuilder> _tagMatchingRuleBuilders;
private DefaultRazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
public DefaultTagHelperDescriptorBuilder(string kind, string name, string assemblyName) public DefaultTagHelperDescriptorBuilder(string kind, string name, string assemblyName)
{ {
@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultRazorDiagnosticCollection(); _diagnostics = new RazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;

View File

@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Razor.Language
internal class DefaultTagMatchingRuleDescriptorBuilder : TagMatchingRuleDescriptorBuilder internal class DefaultTagMatchingRuleDescriptorBuilder : TagMatchingRuleDescriptorBuilder
{ {
private List<DefaultRequiredAttributeDescriptorBuilder> _requiredAttributeBuilders; private List<DefaultRequiredAttributeDescriptorBuilder> _requiredAttributeBuilders;
private DefaultRazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
internal DefaultTagMatchingRuleDescriptorBuilder() internal DefaultTagMatchingRuleDescriptorBuilder()
{ {
@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultRazorDiagnosticCollection(); _diagnostics = new RazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;

View File

@ -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; } public TagMode TagMode { get; set; }

View File

@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
{ {
public sealed class DefaultTagHelperCreateIntermediateNode : ExtensionIntermediateNode public sealed class DefaultTagHelperCreateIntermediateNode : ExtensionIntermediateNode
{ {
public override IntermediateNodeCollection Children { get; } = ReadOnlyIntermediateNodeCollection.Instance; public override IntermediateNodeCollection Children { get; } = IntermediateNodeCollection.ReadOnly;
public string Field { get; set; } public string Field { get; set; }

View File

@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
{ {
public sealed class DefaultTagHelperExecuteIntermediateNode : ExtensionIntermediateNode 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) public override void Accept(IntermediateNodeVisitor visitor)
{ {

View File

@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
public AttributeStructure AttributeStructure { get; set; } 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) public override void Accept(IntermediateNodeVisitor visitor)
{ {

View File

@ -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; } public string AttributeName { get; set; }

View File

@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
{ {
public sealed class DefaultTagHelperRuntimeIntermediateNode : ExtensionIntermediateNode 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) public override void Accept(IntermediateNodeVisitor visitor)
{ {

View File

@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
{ {
internal sealed class DesignTimeDirectiveIntermediateNode : ExtensionIntermediateNode 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) public override void Accept(IntermediateNodeVisitor visitor)
{ {

View File

@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
{ {
internal sealed class PreallocatedTagHelperHtmlAttributeIntermediateNode : ExtensionIntermediateNode internal sealed class PreallocatedTagHelperHtmlAttributeIntermediateNode : ExtensionIntermediateNode
{ {
public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly;
public string VariableName { get; set; } public string VariableName { get; set; }

View File

@ -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; } public string VariableName { get; set; }

View File

@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
TagHelper = propertyNode.TagHelper; TagHelper = propertyNode.TagHelper;
} }
public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly;
public string AttributeName { get; set; } public string AttributeName { get; set; }

View File

@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
{ {
internal sealed class PreallocatedTagHelperPropertyValueIntermediateNode : ExtensionIntermediateNode internal sealed class PreallocatedTagHelperPropertyValueIntermediateNode : ExtensionIntermediateNode
{ {
public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly;
public string VariableName { get; set; } public string VariableName { get; set; }

View File

@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
{ {
public sealed class SectionIntermediateNode : ExtensionIntermediateNode public sealed class SectionIntermediateNode : ExtensionIntermediateNode
{ {
public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection();
public string Name { get; set; } public string Name { get; set; }

View File

@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
{ {
public sealed class TemplateIntermediateNode : ExtensionIntermediateNode 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) public override void Accept(IntermediateNodeVisitor visitor)
{ {

View File

@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class CSharpCodeAttributeValueIntermediateNode : IntermediateNode public sealed class CSharpCodeAttributeValueIntermediateNode : IntermediateNode
{ {
public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection();
public string Prefix { get; set; } public string Prefix { get; set; }

View File

@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class CSharpCodeIntermediateNode : IntermediateNode 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) public override void Accept(IntermediateNodeVisitor visitor)
{ {

View File

@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class CSharpExpressionAttributeValueIntermediateNode : IntermediateNode public sealed class CSharpExpressionAttributeValueIntermediateNode : IntermediateNode
{ {
public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection();
public string Prefix { get; set; } public string Prefix { get; set; }

View File

@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class CSharpExpressionIntermediateNode : IntermediateNode 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) public override void Accept(IntermediateNodeVisitor visitor)
{ {

View File

@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class ClassDeclarationIntermediateNode : MemberDeclarationIntermediateNode public sealed class ClassDeclarationIntermediateNode : MemberDeclarationIntermediateNode
{ {
public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection();
public IList<string> Modifiers { get; } = new List<string>(); public IList<string> Modifiers { get; } = new List<string>();

View File

@ -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<IntermediateNode> _inner = new List<IntermediateNode>();
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<IntermediateNode> 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);
}
}
}

View File

@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class DirectiveIntermediateNode : IntermediateNode public sealed class DirectiveIntermediateNode : IntermediateNode
{ {
public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection();
public string Name { get; set; } public string Name { get; set; }

View File

@ -5,7 +5,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class DirectiveTokenIntermediateNode : IntermediateNode public sealed class DirectiveTokenIntermediateNode : IntermediateNode
{ {
public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly;
public string Content { get; set; } public string Content { get; set; }

View File

@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class DocumentIntermediateNode : IntermediateNode public sealed class DocumentIntermediateNode : IntermediateNode
{ {
public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection();
public string DocumentKind { get; set; } public string DocumentKind { get; set; }

View File

@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class FieldDeclarationIntermediateNode : MemberDeclarationIntermediateNode public sealed class FieldDeclarationIntermediateNode : MemberDeclarationIntermediateNode
{ {
public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly;
public IList<string> Modifiers { get; } = new List<string>(); public IList<string> Modifiers { get; } = new List<string>();

View File

@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class HtmlAttributeIntermediateNode : IntermediateNode public sealed class HtmlAttributeIntermediateNode : IntermediateNode
{ {
public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection();
public string AttributeName { get; set; } public string AttributeName { get; set; }

View File

@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class HtmlAttributeValueIntermediateNode : IntermediateNode public sealed class HtmlAttributeValueIntermediateNode : IntermediateNode
{ {
public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection();
public string Prefix { get; set; } public string Prefix { get; set; }

View File

@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class HtmlContentIntermediateNode : IntermediateNode 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) public override void Accept(IntermediateNodeVisitor visitor)
{ {

View File

@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_annotations == null) if (_annotations == null)
{ {
_annotations = new DefaultItemCollection(); _annotations = new ItemCollection();
} }
return _annotations; return _annotations;
@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultRazorDiagnosticCollection(); _diagnostics = new RazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;

View File

@ -1,40 +1,198 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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;
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public abstract class IntermediateNodeCollection : IList<IntermediateNode> public sealed class IntermediateNodeCollection : IList<IntermediateNode>
{ {
public abstract IntermediateNode this[int index] { get; set; } public static readonly IntermediateNodeCollection ReadOnly = new IntermediateNodeCollection(new List<IntermediateNode>().AsReadOnly());
public abstract int Count { get; } private readonly IList<IntermediateNode> _inner;
public abstract bool IsReadOnly { get; } public IntermediateNodeCollection()
: this(new List<IntermediateNode>())
{
}
public abstract void Add(IntermediateNode item); private IntermediateNodeCollection(IList<IntermediateNode> 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<IntermediateNode> 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<IntermediateNode> IEnumerable<IntermediateNode>.GetEnumerator()
{
return GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()
{ {
return 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<IntermediateNode>
{
private readonly IList<IntermediateNode> _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;
}
}
} }
} }

View File

@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class IntermediateToken : IntermediateNode public sealed class IntermediateToken : IntermediateNode
{ {
public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly;
public string Content { get; set; } public string Content { get; set; }

View File

@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class MalformedDirectiveIntermediateNode : IntermediateNode public sealed class MalformedDirectiveIntermediateNode : IntermediateNode
{ {
public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection();
public string Name { get; set; } public string Name { get; set; }

View File

@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class MethodDeclarationIntermediateNode : MemberDeclarationIntermediateNode public sealed class MethodDeclarationIntermediateNode : MemberDeclarationIntermediateNode
{ {
public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection();
public IList<string> Modifiers { get; } = new List<string>(); public IList<string> Modifiers { get; } = new List<string>();

View File

@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class NamespaceDeclarationIntermediateNode : IntermediateNode public sealed class NamespaceDeclarationIntermediateNode : IntermediateNode
{ {
public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection();
public string Content { get; set; } public string Content { get; set; }

View File

@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class PropertyDeclarationIntermediateNode : MemberDeclarationIntermediateNode public sealed class PropertyDeclarationIntermediateNode : MemberDeclarationIntermediateNode
{ {
public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly;
public IList<string> Modifiers { get; } = new List<string>(); public IList<string> Modifiers { get; } = new List<string>();

View File

@ -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<IntermediateNode> GetEnumerator()
{
return Enumerable.Empty<IntermediateNode>().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();
}
}
}

View File

@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class TagHelperBodyIntermediateNode : IntermediateNode 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) public override void Accept(IntermediateNodeVisitor visitor)
{ {

View File

@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class TagHelperHtmlAttributeIntermediateNode : IntermediateNode public sealed class TagHelperHtmlAttributeIntermediateNode : IntermediateNode
{ {
public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection();
public string AttributeName { get; set; } public string AttributeName { get; set; }

View File

@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class TagHelperIntermediateNode : IntermediateNode public sealed class TagHelperIntermediateNode : IntermediateNode
{ {
public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection();
public TagMode TagMode { get; set; } public TagMode TagMode { get; set; }

View File

@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class TagHelperPropertyIntermediateNode : IntermediateNode public sealed class TagHelperPropertyIntermediateNode : IntermediateNode
{ {
public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection();
public string AttributeName { get; set; } public string AttributeName { get; set; }

View File

@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class UsingDirectiveIntermediateNode : IntermediateNode public sealed class UsingDirectiveIntermediateNode : IntermediateNode
{ {
public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly;
public string Content { get; set; } public string Content { get; set; }

View File

@ -1,36 +1,124 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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;
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language namespace Microsoft.AspNetCore.Razor.Language
{ {
public abstract class ItemCollection : ICollection<KeyValuePair<object, object>> public sealed class ItemCollection : ICollection<KeyValuePair<object, object>>
{ {
public abstract object this[object key] { get; set; } private readonly Dictionary<object, object> _inner;
public abstract int Count { get; } public ItemCollection()
{
_inner = new Dictionary<object, object>();
}
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<object, object> item); public int Count => _inner.Count;
public abstract void Clear(); public bool IsReadOnly => _inner != null;
public abstract bool Contains(KeyValuePair<object, object> item); int ICollection<KeyValuePair<object, object>>.Count => throw new NotImplementedException();
public abstract void CopyTo(KeyValuePair<object, object>[] array, int arrayIndex); bool ICollection<KeyValuePair<object, object>>.IsReadOnly => throw new NotImplementedException();
public abstract IEnumerator<KeyValuePair<object, object>> GetEnumerator(); public void Add(KeyValuePair<object, object> item)
{
if (item.Key == null)
{
throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item));
}
public abstract bool Remove(KeyValuePair<object, object> item); ((ICollection<KeyValuePair<object, object>>)_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<object, object> item)
{
if (item.Key == null)
{
throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item));
}
return ((ICollection<KeyValuePair<object, object>>)_inner).Contains(item);
}
public void CopyTo(KeyValuePair<object, object>[] 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<KeyValuePair<object, object>>)_inner).CopyTo(array, arrayIndex);
}
public IEnumerator<KeyValuePair<object, object>> GetEnumerator()
{
return _inner.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()
{ {
return GetEnumerator(); return GetEnumerator();
} }
public bool Remove(KeyValuePair<object, object> item)
{
if (item.Key == null)
{
throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item));
}
return ((ICollection<KeyValuePair<object, object>>)_inner).Remove(item);
}
} }
} }

View File

@ -1,40 +1,191 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // 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;
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language namespace Microsoft.AspNetCore.Razor.Language
{ {
public abstract class RazorDiagnosticCollection : IList<RazorDiagnostic> public sealed class RazorDiagnosticCollection : IList<RazorDiagnostic>
{ {
public abstract RazorDiagnostic this[int index] { get; set; } private readonly List<RazorDiagnostic> _inner;
public abstract int Count { get; } public RazorDiagnosticCollection()
{
_inner = new List<RazorDiagnostic>();
}
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<RazorDiagnostic> 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<RazorDiagnostic> IEnumerable<RazorDiagnostic>.GetEnumerator()
{
return GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()
{ {
return 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<RazorDiagnostic>
{
private readonly IList<RazorDiagnostic> _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;
}
}
} }
} }

View File

@ -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<RazorDiagnostic> GetEnumerator()
{
return Enumerable.Empty<RazorDiagnostic>().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();
}
}
}

View File

@ -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<object, object> 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<object, object> item)
{
if (item.Key == null)
{
throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item));
}
return false;
}
public override void CopyTo(KeyValuePair<object, object>[] 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<KeyValuePair<object, object>> GetEnumerator()
{
return Enumerable.Empty<KeyValuePair<object, object>>().GetEnumerator();
}
public override bool Remove(KeyValuePair<object, object> item)
{
if (item.Key == null)
{
throw new ArgumentException(Resources.KeyMustNotBeNull, nameof(item));
}
throw new NotSupportedException();
}
}
}

View File

@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
Results = results; Results = results;
Items = new DefaultItemCollection(); Items = new ItemCollection();
} }
public override ItemCollection Items { get; } public override ItemCollection Items { get; }

View File

@ -472,7 +472,7 @@ Render Children
private class MyExtensionIntermediateNode : ExtensionIntermediateNode private class MyExtensionIntermediateNode : ExtensionIntermediateNode
{ {
public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly;
public override void Accept(IntermediateNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {

View File

@ -583,7 +583,7 @@ WriteAttributeValue("" "", 27, false, 28, 6, false);
private class MyExtensionIntermediateNode : ExtensionIntermediateNode private class MyExtensionIntermediateNode : ExtensionIntermediateNode
{ {
public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly;
public override void Accept(IntermediateNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {

View File

@ -5,13 +5,13 @@ using Xunit;
namespace Microsoft.AspNetCore.Razor.Language namespace Microsoft.AspNetCore.Razor.Language
{ {
public class DefaultItemCollectionTest public class ItemCollectionTest
{ {
[Fact] [Fact]
public void Get_MissingValueReturnsNull() public void Get_MissingValueReturnsNull()
{ {
// Arrange // Arrange
var items = new DefaultItemCollection(); var items = new ItemCollection();
// Act // Act
var value = items["foo"]; var value = items["foo"];
@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Razor.Language
public void GetAndSet_ReturnsValue() public void GetAndSet_ReturnsValue()
{ {
// Arrange // Arrange
var items = new DefaultItemCollection(); var items = new ItemCollection();
var expected = "bar"; var expected = "bar";
items["foo"] = expected; items["foo"] = expected;
@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Razor.Language
public void Set_CanSetValueToNull() public void Set_CanSetValueToNull()
{ {
// Arrange // Arrange
var items = new DefaultItemCollection(); var items = new ItemCollection();
items["foo"] = "bar"; items["foo"] = "bar";

View File

@ -206,7 +206,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
private class BasicIntermediateNode : IntermediateNode private class BasicIntermediateNode : IntermediateNode
{ {
public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection();
public override void Accept(IntermediateNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {

View File

@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
private class TestExtensionIntermediateNode : ExtensionIntermediateNode private class TestExtensionIntermediateNode : ExtensionIntermediateNode
{ {
public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance; public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly;
public override void Accept(IntermediateNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {

View File

@ -305,7 +305,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public void InsertAfter_SingleNode_ThrowsForReadOnlyCollection() public void InsertAfter_SingleNode_ThrowsForReadOnlyCollection()
{ {
// Arrange // Arrange
var parent = new BasicIntermediateNode("Parent", ReadOnlyIntermediateNodeCollection.Instance); var parent = new BasicIntermediateNode("Parent", IntermediateNodeCollection.ReadOnly);
var node1 = new BasicIntermediateNode("Node1"); var node1 = new BasicIntermediateNode("Node1");
@ -320,7 +320,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public void InsertAfter_MulipleNodes_ThrowsForReadOnlyCollection() public void InsertAfter_MulipleNodes_ThrowsForReadOnlyCollection()
{ {
// Arrange // Arrange
var parent = new BasicIntermediateNode("Parent", ReadOnlyIntermediateNodeCollection.Instance); var parent = new BasicIntermediateNode("Parent", IntermediateNodeCollection.ReadOnly);
var node1 = new BasicIntermediateNode("Node1"); var node1 = new BasicIntermediateNode("Node1");
@ -335,7 +335,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public void InsertBefore_SingleNode_ThrowsForReadOnlyCollection() public void InsertBefore_SingleNode_ThrowsForReadOnlyCollection()
{ {
// Arrange // Arrange
var parent = new BasicIntermediateNode("Parent", ReadOnlyIntermediateNodeCollection.Instance); var parent = new BasicIntermediateNode("Parent", IntermediateNodeCollection.ReadOnly);
var node1 = new BasicIntermediateNode("Node1"); var node1 = new BasicIntermediateNode("Node1");
@ -350,7 +350,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public void InsertBefore_MulipleNodes_ThrowsForReadOnlyCollection() public void InsertBefore_MulipleNodes_ThrowsForReadOnlyCollection()
{ {
// Arrange // Arrange
var parent = new BasicIntermediateNode("Parent", ReadOnlyIntermediateNodeCollection.Instance); var parent = new BasicIntermediateNode("Parent", IntermediateNodeCollection.ReadOnly);
var node1 = new BasicIntermediateNode("Node1"); var node1 = new BasicIntermediateNode("Node1");
@ -365,7 +365,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public void Remove_ThrowsForReadOnlyCollection() public void Remove_ThrowsForReadOnlyCollection()
{ {
// Arrange // Arrange
var parent = new BasicIntermediateNode("Parent", ReadOnlyIntermediateNodeCollection.Instance); var parent = new BasicIntermediateNode("Parent", IntermediateNodeCollection.ReadOnly);
var node1 = new BasicIntermediateNode("Node1"); var node1 = new BasicIntermediateNode("Node1");
@ -380,7 +380,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public void Replace_ThrowsForReadOnlyCollection() public void Replace_ThrowsForReadOnlyCollection()
{ {
// Arrange // Arrange
var parent = new BasicIntermediateNode("Parent", ReadOnlyIntermediateNodeCollection.Instance); var parent = new BasicIntermediateNode("Parent", IntermediateNodeCollection.ReadOnly);
var node1 = new BasicIntermediateNode("Node1"); var node1 = new BasicIntermediateNode("Node1");
@ -484,7 +484,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
private class BasicIntermediateNode : IntermediateNode private class BasicIntermediateNode : IntermediateNode
{ {
public BasicIntermediateNode(string name) public BasicIntermediateNode(string name)
: this(name, new DefaultIntermediateNodeCollection()) : this(name, new IntermediateNodeCollection())
{ {
Name = name; Name = name;
} }

View File

@ -124,7 +124,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public string Name { get; } public string Name { get; }
public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection(); public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection();
public override void Accept(IntermediateNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {