Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Commit f0a70dc

Browse files
author
N. Taylor Mullen
committed
Addressed code review comments.
1 parent 56c2807 commit f0a70dc

File tree

5 files changed

+71
-71
lines changed

5 files changed

+71
-71
lines changed

src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpTagHelperCodeRenderer.cs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
1616
/// </summary>
1717
public class CSharpTagHelperCodeRenderer
1818
{
19-
internal static readonly string TagHelperExecutionContextVariableName = "__executionContext";
20-
internal static readonly string BufferedStringValueVariableName = "__tagHelperBufferedStringValue";
21-
internal static readonly string TagHelperScopeManagerVariableName = "__tagHelperScopeManager";
22-
internal static readonly string TagHelperRunnerVariableName = "__tagHelperRunner";
19+
internal static readonly string ExecutionContextVariableName = "__tagHelperExecutionContext";
20+
internal static readonly string StringValueBufferVariableName = "__tagHelperStringValueBuffer";
21+
internal static readonly string ScopeManagerVariableName = "__tagHelperScopeManager";
22+
internal static readonly string RunnerVariableName = "__tagHelperRunner";
2323

2424
private static readonly TagHelperAttributeDescriptorComparer AttributeDescriptorComparer =
2525
new TagHelperAttributeDescriptorComparer();
@@ -130,9 +130,9 @@ private void RenderBeginTagHelperScope(string tagName, ContentBehavior contentBe
130130
{
131131
// Call into the tag helper scope manager to start a new tag helper scope.
132132
// Also capture the value as the current execution context.
133-
_writer.WriteStartAssignment(TagHelperExecutionContextVariableName)
134-
.WriteStartInstanceMethodInvocation(TagHelperScopeManagerVariableName,
135-
_tagHelperContext.TagHelperScopeManagerBeginMethodName);
133+
_writer.WriteStartAssignment(ExecutionContextVariableName)
134+
.WriteStartInstanceMethodInvocation(ScopeManagerVariableName,
135+
_tagHelperContext.ScopeManagerBeginMethodName);
136136
_writer.WriteStringLiteral(tagName)
137137
.WriteEndMethodInvocation();
138138
}
@@ -157,7 +157,7 @@ private void RenderTagHelpersCreation(TagHelperChunk chunk)
157157
tagHelperDescriptor.TagHelperName)
158158
.WriteEndMethodInvocation();
159159

160-
_writer.WriteInstanceMethodInvocation(TagHelperExecutionContextVariableName,
160+
_writer.WriteInstanceMethodInvocation(ExecutionContextVariableName,
161161
_tagHelperContext.ExecutionContextAddMethodName,
162162
tagHelperVariableName);
163163

@@ -243,7 +243,7 @@ private void RenderBoundHTMLAttributes(IDictionary<string, Chunk> chunkAttribute
243243

244244
// We need to inform the context of the attribute value.
245245
_writer.WriteStartInstanceMethodInvocation(
246-
TagHelperExecutionContextVariableName,
246+
ExecutionContextVariableName,
247247
_tagHelperContext.ExecutionContextAddTagHelperAttributeMethodName);
248248

249249
_writer.WriteStringLiteral(attributeDescriptor.AttributeName)
@@ -277,7 +277,7 @@ private void RenderUnboundHTMLAttributes(IEnumerable<KeyValuePair<string, Chunk>
277277
BuildBufferedAttributeValue(attributeValue);
278278
}
279279

280-
_writer.WriteStartInstanceMethodInvocation(TagHelperExecutionContextVariableName,
280+
_writer.WriteStartInstanceMethodInvocation(ExecutionContextVariableName,
281281
_tagHelperContext.ExecutionContextAddHtmlAttributeMethodName);
282282
_writer.WriteStringLiteral(htmlAttribute.Key)
283283
.WriteParameterSeparator();
@@ -316,45 +316,45 @@ private void RenderTagHelperBody(IList<Chunk> children, ContentBehavior contentB
316316

317317
private void RenderEndTagHelpersScope()
318318
{
319-
_writer.WriteStartAssignment(TagHelperExecutionContextVariableName)
320-
.WriteInstanceMethodInvocation(TagHelperScopeManagerVariableName,
321-
_tagHelperContext.TagHelperScopeManagerEndMethodName);
319+
_writer.WriteStartAssignment(ExecutionContextVariableName)
320+
.WriteInstanceMethodInvocation(ScopeManagerVariableName,
321+
_tagHelperContext.ScopeManagerEndMethodName);
322322
}
323323

324324
private void RenderTagOutput(string tagOutputMethodName)
325325
{
326326
CSharpCodeVisitor.RenderPreWriteStart(_writer, _context);
327327

328-
_writer.Write(TagHelperExecutionContextVariableName)
328+
_writer.Write(ExecutionContextVariableName)
329329
.Write(".")
330330
.Write(_tagHelperContext.ExecutionContextOutputPropertyName)
331331
.Write(".")
332332
.WriteMethodInvocation(tagOutputMethodName, endLine: false)
333-
.WriteEndMethodInvocation(); ;
333+
.WriteEndMethodInvocation();
334334
}
335335

336336
private void RenderRunTagHelpers(bool bufferedBody)
337337
{
338-
_writer.Write(TagHelperExecutionContextVariableName)
338+
_writer.Write(ExecutionContextVariableName)
339339
.Write(".")
340340
.Write(_tagHelperContext.ExecutionContextOutputPropertyName)
341341
.Write(" = await ")
342-
.WriteStartInstanceMethodInvocation(TagHelperRunnerVariableName,
343-
_tagHelperContext.TagHelperRunnerRunAsyncMethodName);
344-
_writer.Write(TagHelperExecutionContextVariableName);
342+
.WriteStartInstanceMethodInvocation(RunnerVariableName,
343+
_tagHelperContext.RunnerRunAsyncMethodName);
344+
_writer.Write(ExecutionContextVariableName);
345345

346346
if (bufferedBody)
347347
{
348348
_writer.WriteParameterSeparator()
349-
.Write(BufferedStringValueVariableName);
349+
.Write(StringValueBufferVariableName);
350350
}
351351

352352
_writer.WriteEndMethodInvocation();
353353
}
354354

355355
private void RenderBufferedAttributeValueAccessor()
356356
{
357-
_writer.WriteInstanceMethodInvocation(BufferedStringValueVariableName,
357+
_writer.WriteInstanceMethodInvocation(StringValueBufferVariableName,
358358
"ToString",
359359
endLine: false);
360360
}
@@ -404,7 +404,7 @@ private void BuildBufferedWritingScope(Action renderCode)
404404

405405
renderCode();
406406

407-
_writer.WriteStartAssignment(BufferedStringValueVariableName)
407+
_writer.WriteStartAssignment(StringValueBufferVariableName)
408408
.WriteMethodInvocation(_tagHelperContext.EndWritingScopeMethodName);
409409
}
410410

@@ -416,7 +416,7 @@ private void RenderAttributeValue(TagHelperAttributeDescriptor attributeDescript
416416

417417
private static bool IsStringAttribute(TagHelperAttributeDescriptor attributeDescriptor)
418418
{
419-
return typeof(string) == attributeDescriptor.PropertyInfo.PropertyType;
419+
return attributeDescriptor.PropertyInfo.PropertyType == typeof(string);
420420
}
421421

422422
private static bool TryGetPlainTextValue(Chunk chunk, out string plainText)

src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpTagHelperDeclarationVisitor.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
99
{
1010
public class CSharpTagHelperDeclarationVisitor : CodeVisitor<CSharpCodeWriter>
1111
{
12+
private readonly HashSet<TagHelperDescriptor> _declaredDescriptors;
13+
private readonly GeneratedTagHelperContext _tagHelperContext;
1214
private bool _foundTagHelpers;
13-
private HashSet<TagHelperDescriptor> _declaredDescriptors;
14-
private GeneratedTagHelperContext _tagHelperContext;
1515

1616
public CSharpTagHelperDeclarationVisitor([NotNull] CSharpCodeWriter writer,
1717
[NotNull] CodeBuilderContext context)
@@ -29,20 +29,20 @@ protected override void Visit(TagHelperChunk chunk)
2929
_foundTagHelpers = true;
3030

3131
Writer.WriteVariableDeclaration(typeof(TextWriter).FullName,
32-
CSharpTagHelperCodeRenderer.BufferedStringValueVariableName,
32+
CSharpTagHelperCodeRenderer.StringValueBufferVariableName,
3333
null);
3434

35-
Writer.WriteVariableDeclaration(_tagHelperContext.TagHelpersExecutionContextTypeName,
36-
CSharpTagHelperCodeRenderer.TagHelperExecutionContextVariableName,
35+
Writer.WriteVariableDeclaration(_tagHelperContext.ExecutionContextTypeName,
36+
CSharpTagHelperCodeRenderer.ExecutionContextVariableName,
3737
null);
3838

3939
Writer.WriteVariableDeclaration("var",
40-
CSharpTagHelperCodeRenderer.TagHelperRunnerVariableName,
41-
"new " + _tagHelperContext.TagHelperRunnerTypeName + "()");
40+
CSharpTagHelperCodeRenderer.RunnerVariableName,
41+
"new " + _tagHelperContext.RunnerTypeName + "()");
4242

4343
Writer.WriteVariableDeclaration("var",
44-
CSharpTagHelperCodeRenderer.TagHelperScopeManagerVariableName,
45-
"new " + _tagHelperContext.TagHelperScopeManagerTypeName + "()");
44+
CSharpTagHelperCodeRenderer.ScopeManagerVariableName,
45+
"new " + _tagHelperContext.ScopeManagerTypeName + "()");
4646
}
4747

4848
foreach (var descriptor in chunk.Descriptors)

src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpUsingVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected override void Visit(UsingChunk chunk)
5353

5454
protected override void Visit(TagHelperChunk chunk)
5555
{
56-
if(!_foundTagHelpers)
56+
if (!_foundTagHelpers)
5757
{
5858
_foundTagHelpers = true;
5959

src/Microsoft.AspNet.Razor/Generator/GeneratedClassContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Microsoft.AspNet.Razor.Generator
88
{
9-
public class GeneratedClassContext
9+
public struct GeneratedClassContext
1010
{
1111
public static readonly string DefaultWriteMethodName = "Write";
1212
public static readonly string DefaultWriteLiteralMethodName = "WriteLiteral";
@@ -25,6 +25,7 @@ public GeneratedClassContext(GeneratedTagHelperContext generatedTagHelperContext
2525
string executeMethodName,
2626
string writeMethodName,
2727
string writeLiteralMethodName)
28+
: this()
2829
{
2930
if (generatedTagHelperContext == null)
3031
{

src/Microsoft.AspNet.Razor/Generator/GeneratedTagHelperContext.cs

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ public class GeneratedTagHelperContext
1717
/// <summary>
1818
/// Instantiates a new instance of the <see cref="GeneratedTagHelperContext"/> with default values.
1919
/// </summary>
20-
public GeneratedTagHelperContext()
20+
private GeneratedTagHelperContext()
2121
{
2222
CreateTagHelperMethodName = "CreateTagHelper";
23-
TagHelperRunnerRunAsyncMethodName = "RunAsync";
24-
TagHelperScopeManagerBeginMethodName = "Begin";
25-
TagHelperScopeManagerEndMethodName = "End";
23+
RunnerRunAsyncMethodName = "RunAsync";
24+
ScopeManagerBeginMethodName = "Begin";
25+
ScopeManagerEndMethodName = "End";
2626
TagHelperOutputGenerateStartTagMethodName = "GenerateStartTag";
2727
TagHelperOutputGenerateContentMethodName = "GenerateContent";
2828
TagHelperOutputGenerateEndTagMethodName = "GenerateEndTag";
@@ -32,98 +32,97 @@ public GeneratedTagHelperContext()
3232
ExecutionContextOutputPropertyName = "Output";
3333
StartWritingScopeMethodName = "StartWritingScope";
3434
EndWritingScopeMethodName = "EndWritingScope";
35-
TagHelperRunnerTypeName = "TagHelperRunner";
36-
TagHelperScopeManagerTypeName = "TagHelperScopeManager";
37-
TagHelpersExecutionContextTypeName = "TagHelperExecutionContext";
35+
RunnerTypeName = "TagHelperRunner";
36+
ScopeManagerTypeName = "TagHelperScopeManager";
37+
ExecutionContextTypeName = "TagHelperExecutionContext";
3838
}
3939

4040
/// <summary>
41-
/// The <see cref="string"/> method name used to create a tag helper.
41+
/// The name of the method used to create a tag helper.
4242
/// </summary>
4343
public string CreateTagHelperMethodName { get; set; }
4444

4545
/// <summary>
46-
/// The <see cref="string"/> method name used to run a tag helpers defined by the type
47-
/// <see cref="TagHelpersExecutionContextTypeName"/>.
46+
/// The name of the method used to run tag helpers.
4847
/// </summary>
49-
public string TagHelperRunnerRunAsyncMethodName { get; set; }
48+
public string RunnerRunAsyncMethodName { get; set; }
5049

5150
/// <summary>
52-
/// The <see cref="string"/> method name used to start a scope for the type defined by
53-
/// <see cref="TagHelpersExecutionContextTypeName"/>.
51+
/// The name of the method used to start a scope for the type defined by
52+
/// <see cref="ExecutionContextTypeName"/>.
5453
/// </summary>
55-
public string TagHelperScopeManagerBeginMethodName { get; set; }
54+
public string ScopeManagerBeginMethodName { get; set; }
5655

5756
/// <summary>
58-
/// The <see cref="string"/> method name used to end a scope for the type defined by
59-
/// <see cref="TagHelpersExecutionContextTypeName"/>.
57+
/// The name of the method used to end a scope for the type defined by
58+
/// <see cref="ExecutionContextTypeName"/>.
6059
/// </summary>
61-
public string TagHelperScopeManagerEndMethodName { get; set; }
60+
public string ScopeManagerEndMethodName { get; set; }
6261

6362
/// <summary>
64-
/// The <see cref="string"/> method name used to generate a tag helper outputs start tag.
63+
/// The name of the method used to generate a tag helper output's start tag.
6564
/// </summary>
6665
public string TagHelperOutputGenerateStartTagMethodName { get; set; }
6766

6867
/// <summary>
69-
/// The <see cref="string"/> method name used to generate a tag helper outputs content.
68+
/// The name of the method used to generate a tag helper outputs content.
7069
/// </summary>
7170
public string TagHelperOutputGenerateContentMethodName { get; set; }
7271

7372
/// <summary>
74-
/// The <see cref="string"/> method name used to generate a tag helper outputs end tag.
73+
/// The name of the method used to generate a tag helper outputs end tag.
7574
/// </summary>
7675
public string TagHelperOutputGenerateEndTagMethodName { get; set; }
7776

7877
/// <summary>
79-
/// The <see cref="string"/> method name used to add tag helper attributes to the type defined by
80-
/// <see cref="TagHelpersExecutionContextTypeName"/>.
78+
/// The method in <see cref="ExecutionContextTypeName"/> used to add tag helper attributes.
8179
/// </summary>
8280
public string ExecutionContextAddTagHelperAttributeMethodName { get; set; }
8381

8482
/// <summary>
85-
/// The <see cref="string"/> method name used to add HTML attributes to the type defined by
86-
/// <see cref="TagHelpersExecutionContextTypeName"/>.
83+
/// The name of the method used to add HTML attributes to the type defined by
84+
/// <see cref="ExecutionContextTypeName"/>.
8785
/// </summary>
8886
public string ExecutionContextAddHtmlAttributeMethodName { get; set; }
8987

9088
/// <summary>
91-
/// The <see cref="string"/> method name used to add tag helpers to the type defined by
92-
/// <see cref="TagHelpersExecutionContextTypeName"/>.
89+
/// The name of the method used to add tag helpers to the type defined by
90+
/// <see cref="ExecutionContextTypeName"/>.
9391
/// </summary>
9492
public string ExecutionContextAddMethodName { get; set; }
9593

9694
/// <summary>
97-
/// The <see cref="string"/> property accessor for the tag helpers output.
95+
/// The property accessor for the tag helper's output.
9896
/// </summary>
9997
public string ExecutionContextOutputPropertyName { get; set; }
10098

10199
/// <summary>
102-
/// The <see cref="string"/> method name to start a new writing scope on the generated Razor page.
100+
/// The name of the method to start a new writing scope.
103101
/// </summary>
104102
public string StartWritingScopeMethodName { get; set; }
105103

106104
/// <summary>
107-
/// The <see cref="string"/> method name used to end a writing scope that was started from a call to the method
105+
/// The name of the method used to end a writing scope that was started from a call to the method
108106
/// defined by <see cref="StartWritingScopeMethodName"/> on the generated Razor page.
109107
/// </summary>
110108
public string EndWritingScopeMethodName { get; set; }
111109

112110
/// <summary>
113-
/// The <see cref="string"/> type name of the object used to run tag helpers.
111+
/// The name of the type used to run tag helpers.
114112
/// </summary>
115-
public string TagHelperRunnerTypeName { get; set; }
113+
public string RunnerTypeName { get; set; }
116114

117115
/// <summary>
118-
/// The <see cref="string"/> type name of the object used to create scoped objects of the type defined by
119-
/// <see cref="TagHelpersExecutionContextTypeName"/>.
116+
/// The name of the type used to create scoped <see cref="ExecutionContextTypeName"/> instances.
120117
/// </summary>
121-
public string TagHelperScopeManagerTypeName { get; set; }
118+
public string ScopeManagerTypeName { get; set; }
122119

123120
/// <summary>
124-
/// The <see cref="string"/> type name of the object used manage tag helpers, tag helper attributes,
125-
/// html attributes, the HTML tag name and the tag helpers output.
121+
/// The name of the type [describing|containing information about] a specific tag helper scope.
126122
/// </summary>
127-
public string TagHelpersExecutionContextTypeName { get; set; }
123+
/// <remarks>
124+
/// Contains information about in-scope tag helpers, HTML attributes, and the tag helpers' output.
125+
/// </remarks>
126+
public string ExecutionContextTypeName { get; set; }
128127
}
129128
}

0 commit comments

Comments
 (0)