Skip to content

Commit 79d0edb

Browse files
Clean up TypeParameter
- Enable nullability - Add constructor - Make properties readonly
1 parent 9762626 commit 79d0edb

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DefaultDocumentWriterTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ public void WriteDocument_WritesClass()
176176
BaseType = new BaseTypeWithModel("TestBase"),
177177
Interfaces = [IntermediateToken.CreateCSharpToken("IFoo"), IntermediateToken.CreateCSharpToken("IBar")],
178178
TypeParameters = [
179-
new TypeParameter() { ParameterName = "TKey" },
180-
new TypeParameter() { ParameterName = "TValue" }
179+
new TypeParameter("TKey"),
180+
new TypeParameter("TValue")
181181
],
182182
ClassName = "TestClass",
183183
});
@@ -219,8 +219,8 @@ public void WriteDocument_WithNullableContext_WritesClass()
219219
BaseType = new BaseTypeWithModel("TestBase"),
220220
Interfaces = [IntermediateToken.CreateCSharpToken("IFoo"), IntermediateToken.CreateCSharpToken("IBar")],
221221
TypeParameters = [
222-
new TypeParameter() { ParameterName = "TKey" },
223-
new TypeParameter() { ParameterName = "TValue" }
222+
new TypeParameter("TKey"),
223+
new TypeParameter("TValue")
224224
],
225225
ClassName = "TestClass",
226226
NullableContext = true,
@@ -265,8 +265,8 @@ public void WriteDocument_WritesClass_ConstrainedGenericTypeParameters()
265265
BaseType = new BaseTypeWithModel("TestBase"),
266266
Interfaces = [IntermediateToken.CreateCSharpToken("IFoo"), IntermediateToken.CreateCSharpToken("IBar")],
267267
TypeParameters = [
268-
new TypeParameter() { ParameterName = "TKey", Constraints = "where TKey : class" },
269-
new TypeParameter() { ParameterName = "TValue", Constraints = "where TValue : class" }
268+
new TypeParameter("TKey", constraints: "where TKey : class"),
269+
new TypeParameter("TValue", constraints: "where TValue : class")
270270
],
271271
ClassName = "TestClass",
272272
});

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentDocumentClassifierPass.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,11 @@ protected override void OnDocumentStructureCreated(
130130
var typeParameter = typeParamNode.Tokens.First();
131131
var constraints = typeParamNode.Tokens.Skip(1).FirstOrDefault();
132132

133-
typeParameters.Add(new TypeParameter()
134-
{
135-
ParameterName = typeParameter.Content,
136-
ParameterNameSource = typeParameter.Source,
137-
Constraints = constraints?.Content,
138-
ConstraintsSource = constraints?.Source,
139-
});
133+
typeParameters.Add(new TypeParameter(
134+
typeParameter.Content,
135+
typeParameter.Source,
136+
constraints?.Content,
137+
constraints?.Source));
140138
}
141139

142140
@class.UpdateTypeParameters(typeParameters.ToImmutableAndClear());
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
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-
#nullable disable
5-
64
namespace Microsoft.AspNetCore.Razor.Language.Intermediate;
75

8-
public sealed class TypeParameter
6+
public sealed class TypeParameter(
7+
string parameterName,
8+
SourceSpan? parameterNameSource = null,
9+
string? constraints = null,
10+
SourceSpan? constraintsSource = null)
911
{
10-
public string ParameterName { get; set; }
11-
public SourceSpan? ParameterNameSource { get; init; }
12-
public string Constraints { get; set; }
13-
public SourceSpan? ConstraintsSource { get; init; }
12+
public string ParameterName { get; } = parameterName;
13+
public SourceSpan? ParameterNameSource { get; } = parameterNameSource;
14+
public string? Constraints { get; } = constraints;
15+
public SourceSpan? ConstraintsSource { get; } = constraintsSource;
1416
}

0 commit comments

Comments
 (0)