1
1
// Copyright (c) .NET Foundation. All rights reserved.
2
2
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
3
4
- #nullable disable warnings
5
-
6
4
using System ;
7
5
using System . Collections . Generic ;
8
6
using System . Diagnostics ;
9
- using System . Threading . Tasks ;
10
7
using Microsoft . AspNetCore . Components . RenderTree ;
11
8
12
9
namespace Microsoft . AspNetCore . Components . Rendering
@@ -29,7 +26,7 @@ public sealed class RenderTreeBuilder : IDisposable
29
26
private readonly Stack < int > _openElementIndices = new Stack < int > ( ) ;
30
27
private RenderTreeFrameType ? _lastNonAttributeFrameType ;
31
28
private bool _hasSeenAddMultipleAttributes ;
32
- private Dictionary < string , int > _seenAttributeNames ;
29
+ private Dictionary < string , int > ? _seenAttributeNames ;
33
30
34
31
/// <summary>
35
32
/// The reserved parameter name used for supplying child content.
@@ -82,23 +79,23 @@ public void CloseElement()
82
79
/// </summary>
83
80
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
84
81
/// <param name="markupContent">Content for the new markup frame.</param>
85
- public void AddMarkupContent ( int sequence , string markupContent )
82
+ public void AddMarkupContent ( int sequence , string ? markupContent )
86
83
=> Append ( RenderTreeFrame . Markup ( sequence , markupContent ?? string . Empty ) ) ;
87
84
88
85
/// <summary>
89
86
/// Appends a frame representing text content.
90
87
/// </summary>
91
88
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
92
89
/// <param name="textContent">Content for the new text frame.</param>
93
- public void AddContent ( int sequence , string textContent )
90
+ public void AddContent ( int sequence , string ? textContent )
94
91
=> Append ( RenderTreeFrame . Text ( sequence , textContent ?? string . Empty ) ) ;
95
92
96
93
/// <summary>
97
94
/// Appends frames representing an arbitrary fragment of content.
98
95
/// </summary>
99
96
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
100
97
/// <param name="fragment">Content to append.</param>
101
- public void AddContent ( int sequence , RenderFragment fragment )
98
+ public void AddContent ( int sequence , RenderFragment ? fragment )
102
99
{
103
100
if ( fragment != null )
104
101
{
@@ -118,7 +115,7 @@ public void AddContent(int sequence, RenderFragment fragment)
118
115
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
119
116
/// <param name="fragment">Content to append.</param>
120
117
/// <param name="value">The value used by <paramref name="fragment"/>.</param>
121
- public void AddContent < TValue > ( int sequence , RenderFragment < TValue > fragment , TValue value )
118
+ public void AddContent < TValue > ( int sequence , RenderFragment < TValue > ? fragment , TValue value )
122
119
{
123
120
if ( fragment != null )
124
121
{
@@ -139,7 +136,7 @@ public void AddContent(int sequence, MarkupString markupContent)
139
136
/// </summary>
140
137
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
141
138
/// <param name="textContent">Content for the new text frame.</param>
142
- public void AddContent ( int sequence , object textContent )
139
+ public void AddContent ( int sequence , object ? textContent )
143
140
=> AddContent ( sequence , textContent ? . ToString ( ) ) ;
144
141
145
142
/// <summary>
@@ -185,7 +182,7 @@ public void AddAttribute(int sequence, string name, bool value)
185
182
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
186
183
/// <param name="name">The name of the attribute.</param>
187
184
/// <param name="value">The value of the attribute.</param>
188
- public void AddAttribute ( int sequence , string name , string value )
185
+ public void AddAttribute ( int sequence , string name , string ? value )
189
186
{
190
187
AssertCanAddAttribute ( ) ;
191
188
if ( value != null || _lastNonAttributeFrameType == RenderTreeFrameType . Component )
@@ -210,7 +207,7 @@ public void AddAttribute(int sequence, string name, string value)
210
207
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
211
208
/// <param name="name">The name of the attribute.</param>
212
209
/// <param name="value">The value of the attribute.</param>
213
- public void AddAttribute ( int sequence , string name , MulticastDelegate value )
210
+ public void AddAttribute ( int sequence , string name , MulticastDelegate ? value )
214
211
{
215
212
AssertCanAddAttribute ( ) ;
216
213
if ( value != null || _lastNonAttributeFrameType == RenderTreeFrameType . Component )
@@ -320,7 +317,7 @@ public void AddAttribute<TArgument>(int sequence, string name, EventCallback<TAr
320
317
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
321
318
/// <param name="name">The name of the attribute.</param>
322
319
/// <param name="value">The value of the attribute.</param>
323
- public void AddAttribute ( int sequence , string name , object value )
320
+ public void AddAttribute ( int sequence , string name , object ? value )
324
321
{
325
322
// This looks a bit daunting because we need to handle the boxed/object version of all of the
326
323
// types that AddAttribute special cases.
@@ -402,7 +399,7 @@ public void AddAttribute(int sequence, in RenderTreeFrame frame)
402
399
/// </summary>
403
400
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
404
401
/// <param name="attributes">A collection of key-value pairs representing attributes.</param>
405
- public void AddMultipleAttributes ( int sequence , IEnumerable < KeyValuePair < string , object > > attributes )
402
+ public void AddMultipleAttributes ( int sequence , IEnumerable < KeyValuePair < string , object > > ? attributes )
406
403
{
407
404
// Calling this up-front just to make sure we validate before mutating anything.
408
405
AssertCanAddAttribute ( ) ;
@@ -455,7 +452,7 @@ public void SetUpdatesAttributeName(string updatesAttributeName)
455
452
/// </summary>
456
453
/// <typeparam name="TComponent">The type of the child component.</typeparam>
457
454
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
458
- public void OpenComponent < TComponent > ( int sequence ) where TComponent : IComponent
455
+ public void OpenComponent < TComponent > ( int sequence ) where TComponent : notnull , IComponent
459
456
=> OpenComponentUnchecked ( sequence , typeof ( TComponent ) ) ;
460
457
461
458
/// <summary>
@@ -477,7 +474,7 @@ public void OpenComponent(int sequence, Type componentType)
477
474
/// Assigns the specified key value to the current element or component.
478
475
/// </summary>
479
476
/// <param name="value">The value for the key.</param>
480
- public void SetKey ( object value )
477
+ public void SetKey ( object ? value )
481
478
{
482
479
if ( value == null )
483
480
{
@@ -560,7 +557,7 @@ public void AddElementReferenceCapture(int sequence, Action<ElementReference> el
560
557
/// </summary>
561
558
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
562
559
/// <param name="componentReferenceCaptureAction">An action to be invoked whenever the reference value changes.</param>
563
- public void AddComponentReferenceCapture ( int sequence , Action < object > componentReferenceCaptureAction )
560
+ public void AddComponentReferenceCapture ( int sequence , Action < object ? > componentReferenceCaptureAction )
564
561
{
565
562
var parentFrameIndex = GetCurrentParentFrameIndex ( ) ;
566
563
if ( ! parentFrameIndex . HasValue )
@@ -640,7 +637,7 @@ public void Clear()
640
637
641
638
// internal because this should only be used during the post-event tree patching logic
642
639
// It's expensive because it involves copying all the subsequent memory in the array
643
- internal void InsertAttributeExpensive ( int insertAtIndex , int sequence , string attributeName , object attributeValue )
640
+ internal void InsertAttributeExpensive ( int insertAtIndex , int sequence , string attributeName , object ? attributeValue )
644
641
{
645
642
// Replicate the same attribute omission logic as used elsewhere
646
643
if ( ( attributeValue == null ) || ( attributeValue is bool boolValue && ! boolValue ) )
0 commit comments