Skip to content

Commit 50dac13

Browse files
Remove RequiredAttributeDescriptor.Metadata property
RequiredAttributeDescriptor no longer needs a Metadata property.
1 parent ec2963e commit 50dac13

File tree

7 files changed

+5
-84
lines changed

7 files changed

+5
-84
lines changed
Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.Collections.Generic;
54
using Xunit;
65

76
namespace Microsoft.AspNetCore.Razor.Language;
@@ -41,56 +40,4 @@ public void Build_DisplayNameIsNameWithDots_NameComparisonPrefixMatch()
4140
// Assert
4241
Assert.Equal("asp-route-...", attribute.DisplayName);
4342
}
44-
45-
[Fact]
46-
public void Metadata_Same()
47-
{
48-
// When SetMetadata is called on multiple builders with the same metadata collection,
49-
// they should share the instance.
50-
51-
// Arrange
52-
var metadata = MetadataCollection.Create(KeyValuePair.Create<string, string?>("TestKey", "TestValue"));
53-
54-
var builder = TagHelperDescriptorBuilder.Create(TagHelperConventions.DefaultKind, "TestTagHelper", "Test")
55-
.TagMatchingRuleDescriptor(rule => rule
56-
.RequireAttributeDescriptor(attribute => attribute
57-
.Name("test1")
58-
.SetMetadata(metadata))
59-
.RequireAttributeDescriptor(attribute => attribute
60-
.Name("test2")
61-
.SetMetadata(metadata)));
62-
63-
// Act
64-
var tagHelper = builder.Build();
65-
var attribute1 = tagHelper.TagMatchingRules[0].Attributes[0];
66-
var attribute2 = tagHelper.TagMatchingRules[0].Attributes[1];
67-
68-
// Assert
69-
Assert.Same(attribute1.Metadata, attribute2.Metadata);
70-
}
71-
72-
[Fact]
73-
public void Metadata_NotSame()
74-
{
75-
// When Metadata is accessed on multiple builders with the same metadata,
76-
// they do not share the instance.
77-
78-
// Arrange
79-
var builder = TagHelperDescriptorBuilder.Create(TagHelperConventions.DefaultKind, "TestTagHelper", "Test")
80-
.TagMatchingRuleDescriptor(rule => rule
81-
.RequireAttributeDescriptor(attribute => attribute
82-
.Name("test1")
83-
.Metadata.Add("TestKey", "TestValue"))
84-
.RequireAttributeDescriptor(attribute => attribute
85-
.Name("test2")
86-
.Metadata.Add("TestKey", "TestValue")));
87-
88-
// Act
89-
var tagHelper = builder.Build();
90-
var attribute1 = tagHelper.TagMatchingRules[0].Attributes[0];
91-
var attribute2 = tagHelper.TagMatchingRules[0].Attributes[1];
92-
93-
// Assert
94-
Assert.NotSame(attribute1.Metadata, attribute2.Metadata);
95-
}
9643
}

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RequiredAttributeDescriptor.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,20 @@ public sealed class RequiredAttributeDescriptor : TagHelperObject<RequiredAttrib
2424
public bool CaseSensitive => _flags.IsFlagSet(RequiredAttributeDescriptorFlags.CaseSensitive);
2525
public bool IsDirectiveAttribute => _flags.IsFlagSet(RequiredAttributeDescriptorFlags.IsDirectiveAttribute);
2626

27-
public MetadataCollection Metadata { get; }
28-
2927
internal RequiredAttributeDescriptor(
3028
RequiredAttributeDescriptorFlags flags,
3129
string name,
3230
RequiredAttributeNameComparison nameComparison,
3331
string? value,
3432
RequiredAttributeValueComparison valueComparison,
35-
ImmutableArray<RazorDiagnostic> diagnostics,
36-
MetadataCollection metadata)
33+
ImmutableArray<RazorDiagnostic> diagnostics)
3734
: base(diagnostics)
3835
{
3936
_flags = flags;
4037
Name = name;
4138
NameComparison = nameComparison;
4239
Value = value;
4340
ValueComparison = valueComparison;
44-
Metadata = metadata ?? MetadataCollection.Empty;
4541
}
4642

4743
private protected override void BuildChecksum(in Checksum.Builder builder)
@@ -51,7 +47,6 @@ private protected override void BuildChecksum(in Checksum.Builder builder)
5147
builder.AppendData((int)NameComparison);
5248
builder.AppendData(Value);
5349
builder.AppendData((int)ValueComparison);
54-
builder.AppendData(Metadata.Checksum);
5550
}
5651

5752
public TagMatchingRuleDescriptor Parent

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RequiredAttributeDescriptorBuilder.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5-
using System.Collections.Generic;
65
using System.Collections.Immutable;
76
using System.Diagnostics;
87
using System.Diagnostics.CodeAnalysis;
@@ -15,7 +14,6 @@ public sealed partial class RequiredAttributeDescriptorBuilder : TagHelperObject
1514
[AllowNull]
1615
private TagMatchingRuleDescriptorBuilder _parent;
1716
private RequiredAttributeDescriptorFlags _flags;
18-
private MetadataHolder _metadata;
1917

2018
private RequiredAttributeDescriptorBuilder()
2119
{
@@ -39,14 +37,8 @@ public bool IsDirectiveAttribute
3937
set => _flags.UpdateFlag(RequiredAttributeDescriptorFlags.IsDirectiveAttribute, value);
4038
}
4139

42-
public IDictionary<string, string?> Metadata => _metadata.MetadataDictionary;
43-
44-
public void SetMetadata(MetadataCollection metadata) => _metadata.SetMetadataCollection(metadata);
45-
4640
private protected override RequiredAttributeDescriptor BuildCore(ImmutableArray<RazorDiagnostic> diagnostics)
4741
{
48-
var metadata = _metadata.GetMetadataCollection();
49-
5042
var flags = _flags;
5143

5244
if (CaseSensitive)
@@ -60,8 +52,7 @@ private protected override RequiredAttributeDescriptor BuildCore(ImmutableArray<
6052
NameComparison,
6153
Value,
6254
ValueComparison,
63-
diagnostics,
64-
metadata);
55+
diagnostics);
6556
}
6657

6758
private protected override void CollectDiagnostics(ref PooledHashSet<RazorDiagnostic> diagnostics)

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RequiredAttributeDescriptorBuilder_Pooling.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ private protected override void Reset()
2828
NameComparison = default;
2929
Value = null;
3030
ValueComparison = default;
31-
32-
_metadata.Clear();
3331
}
3432

3533
private sealed class Policy : PooledBuilderPolicy<RequiredAttributeDescriptorBuilder>

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Serialization/MessagePack/Formatters/TagHelpers/RequiredAttributeFormatter.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Microsoft.CodeAnalysis.Razor.Serialization.MessagePack.Formatters.TagH
99

1010
internal sealed class RequiredAttributeFormatter : ValueFormatter<RequiredAttributeDescriptor>
1111
{
12-
private const int PropertyCount = 7;
12+
private const int PropertyCount = 6;
1313

1414
public static readonly ValueFormatter<RequiredAttributeDescriptor> Instance = new RequiredAttributeFormatter();
1515

@@ -27,13 +27,10 @@ public override RequiredAttributeDescriptor Deserialize(ref MessagePackReader re
2727
var value = CachedStringFormatter.Instance.Deserialize(ref reader, options);
2828
var valueComparison = (RequiredAttributeValueComparison)reader.ReadInt32();
2929

30-
var metadata = reader.Deserialize<MetadataCollection>(options);
3130
var diagnostics = reader.Deserialize<ImmutableArray<RazorDiagnostic>>(options);
3231

3332
return new RequiredAttributeDescriptor(
34-
flags, name!, nameComparison,
35-
value, valueComparison,
36-
diagnostics, metadata);
33+
flags, name!, nameComparison, value, valueComparison, diagnostics);
3734
}
3835

3936
public override void Serialize(ref MessagePackWriter writer, RequiredAttributeDescriptor value, SerializerCachingOptions options)
@@ -46,7 +43,6 @@ public override void Serialize(ref MessagePackWriter writer, RequiredAttributeDe
4643
CachedStringFormatter.Instance.Serialize(ref writer, value.Value, options);
4744
writer.Write((int)value.ValueComparison);
4845

49-
writer.Serialize(value.Metadata, options);
5046
writer.Serialize(value.Diagnostics, options);
5147
}
5248

@@ -60,7 +56,6 @@ public override void Skim(ref MessagePackReader reader, SerializerCachingOptions
6056
CachedStringFormatter.Instance.Skim(ref reader, options); // Value
6157
reader.Skip(); // ValueComparison
6258

63-
MetadataCollectionFormatter.Instance.Skim(ref reader, options); // Metadata
6459
RazorDiagnosticFormatter.Instance.SkimArray(ref reader, options); // Diagnostics
6560
}
6661
}

src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectReaders_TagHelpers.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,10 @@ static RequiredAttributeDescriptor ReadFromProperties(JsonDataReader reader)
135135
var value = reader.ReadStringOrNull(nameof(RequiredAttributeDescriptor.Value));
136136
var valueComparison = (RequiredAttributeValueComparison)reader.ReadInt32OrZero(nameof(RequiredAttributeDescriptor.ValueComparison));
137137

138-
var metadata = ReadMetadata(reader, nameof(RequiredAttributeDescriptor.Metadata));
139138
var diagnostics = reader.ReadImmutableArrayOrEmpty(nameof(RequiredAttributeDescriptor.Diagnostics), ReadDiagnostic);
140139

141140
return new RequiredAttributeDescriptor(
142-
flags, Cached(name)!, nameComparison,
143-
Cached(value), valueComparison,
144-
diagnostics, metadata);
141+
flags, Cached(name)!, nameComparison, Cached(value), valueComparison, diagnostics);
145142
}
146143
}
147144

src/Shared/Microsoft.AspNetCore.Razor.Serialization.Json/ObjectWriters_TagHelpers.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ static void WriteRequiredAttribute(JsonDataWriter writer, RequiredAttributeDescr
9494
writer.WriteIfNotZero(nameof(value.NameComparison), (int)value.NameComparison);
9595
writer.WriteIfNotNull(nameof(value.Value), value.Value);
9696
writer.WriteIfNotZero(nameof(value.ValueComparison), (int)value.ValueComparison);
97-
98-
WriteMetadata(writer, nameof(value.Metadata), value.Metadata);
9997
writer.WriteArrayIfNotDefaultOrEmpty(nameof(value.Diagnostics), value.Diagnostics, Write);
10098
});
10199
}

0 commit comments

Comments
 (0)