Skip to content

Commit c42d1a3

Browse files
authored
Annotate Components.Forms \ Components.Web \ Component.Server with nullable attributes (#23204)
* Annotate Components.Forms \ Components.Web with nullable attributes Contributes to #5680 * Fixup * Fixup rebase * Undo nullable * Fixup
1 parent 55b5f95 commit c42d1a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+316
-273
lines changed

src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static partial class BindConverter
2727
public static string? FormatValue(long? value, System.Globalization.CultureInfo? culture = null) { throw null; }
2828
public static string? FormatValue(float? value, System.Globalization.CultureInfo? culture = null) { throw null; }
2929
public static string FormatValue(float value, System.Globalization.CultureInfo? culture = null) { throw null; }
30-
public static string FormatValue(string value, System.Globalization.CultureInfo? culture = null) { throw null; }
30+
public static string? FormatValue(string? value, System.Globalization.CultureInfo? culture = null) { throw null; }
3131
public static object? FormatValue<T>(T value, System.Globalization.CultureInfo? culture = null) { throw null; }
3232
public static bool TryConvertToBool(object? obj, System.Globalization.CultureInfo? culture, out bool value) { throw null; }
3333
public static bool TryConvertToDateTime(object? obj, System.Globalization.CultureInfo? culture, out System.DateTime value) { throw null; }
@@ -399,29 +399,29 @@ public RenderTreeBuilder() { }
399399
public void AddAttribute(int sequence, in Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame frame) { }
400400
public void AddAttribute(int sequence, string name, Microsoft.AspNetCore.Components.EventCallback value) { }
401401
public void AddAttribute(int sequence, string name, bool value) { }
402-
public void AddAttribute(int sequence, string name, System.MulticastDelegate value) { }
403-
public void AddAttribute(int sequence, string name, object value) { }
404-
public void AddAttribute(int sequence, string name, string value) { }
402+
public void AddAttribute(int sequence, string name, System.MulticastDelegate? value) { }
403+
public void AddAttribute(int sequence, string name, object? value) { }
404+
public void AddAttribute(int sequence, string name, string? value) { }
405405
public void AddAttribute<TArgument>(int sequence, string name, Microsoft.AspNetCore.Components.EventCallback<TArgument> value) { }
406-
public void AddComponentReferenceCapture(int sequence, System.Action<object> componentReferenceCaptureAction) { }
406+
public void AddComponentReferenceCapture(int sequence, System.Action<object?> componentReferenceCaptureAction) { }
407407
public void AddContent(int sequence, Microsoft.AspNetCore.Components.MarkupString markupContent) { }
408-
public void AddContent(int sequence, Microsoft.AspNetCore.Components.RenderFragment fragment) { }
409-
public void AddContent(int sequence, object textContent) { }
410-
public void AddContent(int sequence, string textContent) { }
411-
public void AddContent<TValue>(int sequence, Microsoft.AspNetCore.Components.RenderFragment<TValue> fragment, TValue value) { }
408+
public void AddContent(int sequence, Microsoft.AspNetCore.Components.RenderFragment? fragment) { }
409+
public void AddContent(int sequence, object? textContent) { }
410+
public void AddContent(int sequence, string? textContent) { }
411+
public void AddContent<TValue>(int sequence, Microsoft.AspNetCore.Components.RenderFragment<TValue>? fragment, TValue value) { }
412412
public void AddElementReferenceCapture(int sequence, System.Action<Microsoft.AspNetCore.Components.ElementReference> elementReferenceCaptureAction) { }
413-
public void AddMarkupContent(int sequence, string markupContent) { }
414-
public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>> attributes) { }
413+
public void AddMarkupContent(int sequence, string? markupContent) { }
414+
public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>? attributes) { }
415415
public void Clear() { }
416416
public void CloseComponent() { }
417417
public void CloseElement() { }
418418
public void CloseRegion() { }
419419
public Microsoft.AspNetCore.Components.RenderTree.ArrayRange<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame> GetFrames() { throw null; }
420420
public void OpenComponent(int sequence, System.Type componentType) { }
421-
public void OpenComponent<TComponent>(int sequence) where TComponent : Microsoft.AspNetCore.Components.IComponent { }
421+
public void OpenComponent<TComponent>(int sequence) where TComponent : notnull, Microsoft.AspNetCore.Components.IComponent { }
422422
public void OpenElement(int sequence, string elementName) { }
423423
public void OpenRegion(int sequence) { }
424-
public void SetKey(object value) { }
424+
public void SetKey(object? value) { }
425425
public void SetUpdatesAttributeName(string updatesAttributeName) { }
426426
void System.IDisposable.Dispose() { }
427427
}

src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static partial class BindConverter
2727
public static string? FormatValue(long? value, System.Globalization.CultureInfo? culture = null) { throw null; }
2828
public static string? FormatValue(float? value, System.Globalization.CultureInfo? culture = null) { throw null; }
2929
public static string FormatValue(float value, System.Globalization.CultureInfo? culture = null) { throw null; }
30-
public static string FormatValue(string value, System.Globalization.CultureInfo? culture = null) { throw null; }
30+
public static string? FormatValue(string? value, System.Globalization.CultureInfo? culture = null) { throw null; }
3131
public static object? FormatValue<T>(T value, System.Globalization.CultureInfo? culture = null) { throw null; }
3232
public static bool TryConvertToBool(object? obj, System.Globalization.CultureInfo? culture, out bool value) { throw null; }
3333
public static bool TryConvertToDateTime(object? obj, System.Globalization.CultureInfo? culture, out System.DateTime value) { throw null; }
@@ -398,29 +398,29 @@ public RenderTreeBuilder() { }
398398
public void AddAttribute(int sequence, in Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame frame) { }
399399
public void AddAttribute(int sequence, string name, Microsoft.AspNetCore.Components.EventCallback value) { }
400400
public void AddAttribute(int sequence, string name, bool value) { }
401-
public void AddAttribute(int sequence, string name, System.MulticastDelegate value) { }
402-
public void AddAttribute(int sequence, string name, object value) { }
403-
public void AddAttribute(int sequence, string name, string value) { }
401+
public void AddAttribute(int sequence, string name, System.MulticastDelegate? value) { }
402+
public void AddAttribute(int sequence, string name, object? value) { }
403+
public void AddAttribute(int sequence, string name, string? value) { }
404404
public void AddAttribute<TArgument>(int sequence, string name, Microsoft.AspNetCore.Components.EventCallback<TArgument> value) { }
405-
public void AddComponentReferenceCapture(int sequence, System.Action<object> componentReferenceCaptureAction) { }
405+
public void AddComponentReferenceCapture(int sequence, System.Action<object?> componentReferenceCaptureAction) { }
406406
public void AddContent(int sequence, Microsoft.AspNetCore.Components.MarkupString markupContent) { }
407-
public void AddContent(int sequence, Microsoft.AspNetCore.Components.RenderFragment fragment) { }
408-
public void AddContent(int sequence, object textContent) { }
409-
public void AddContent(int sequence, string textContent) { }
410-
public void AddContent<TValue>(int sequence, Microsoft.AspNetCore.Components.RenderFragment<TValue> fragment, TValue value) { }
407+
public void AddContent(int sequence, Microsoft.AspNetCore.Components.RenderFragment? fragment) { }
408+
public void AddContent(int sequence, object? textContent) { }
409+
public void AddContent(int sequence, string? textContent) { }
410+
public void AddContent<TValue>(int sequence, Microsoft.AspNetCore.Components.RenderFragment<TValue>? fragment, TValue value) { }
411411
public void AddElementReferenceCapture(int sequence, System.Action<Microsoft.AspNetCore.Components.ElementReference> elementReferenceCaptureAction) { }
412-
public void AddMarkupContent(int sequence, string markupContent) { }
413-
public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>> attributes) { }
412+
public void AddMarkupContent(int sequence, string? markupContent) { }
413+
public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>? attributes) { }
414414
public void Clear() { }
415415
public void CloseComponent() { }
416416
public void CloseElement() { }
417417
public void CloseRegion() { }
418418
public Microsoft.AspNetCore.Components.RenderTree.ArrayRange<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame> GetFrames() { throw null; }
419419
public void OpenComponent(int sequence, System.Type componentType) { }
420-
public void OpenComponent<TComponent>(int sequence) where TComponent : Microsoft.AspNetCore.Components.IComponent { }
420+
public void OpenComponent<TComponent>(int sequence) where TComponent : notnull, Microsoft.AspNetCore.Components.IComponent { }
421421
public void OpenElement(int sequence, string elementName) { }
422422
public void OpenRegion(int sequence) { }
423-
public void SetKey(object value) { }
423+
public void SetKey(object? value) { }
424424
public void SetUpdatesAttributeName(string updatesAttributeName) { }
425425
void System.IDisposable.Dispose() { }
426426
}

src/Components/Components/src/BindConverter.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Concurrent;
66
using System.ComponentModel;
7-
using System.Diagnostics.CodeAnalysis;
87
using System.Globalization;
98
using System.Reflection;
109

@@ -36,9 +35,9 @@ public static class BindConverter
3635
/// The <see cref="CultureInfo"/> to use while formatting. Defaults to <see cref="CultureInfo.CurrentCulture"/>.
3736
/// </param>
3837
/// <returns>The formatted value.</returns>
39-
public static string FormatValue(string value, CultureInfo? culture = null) => FormatStringValueCore(value, culture);
38+
public static string? FormatValue(string? value, CultureInfo? culture = null) => FormatStringValueCore(value, culture);
4039

41-
private static string FormatStringValueCore(string value, CultureInfo? culture)
40+
private static string? FormatStringValueCore(string? value, CultureInfo? culture)
4241
{
4342
return value;
4443
}

src/Components/Components/src/RenderTree/RenderTreeFrame.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
#nullable disable warnings
4+
#nullable disable
55

66
using System;
77
using System.Runtime.InteropServices;

src/Components/Components/src/Rendering/RenderTreeBuilder.cs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
#nullable disable warnings
5-
64
using System;
75
using System.Collections.Generic;
86
using System.Diagnostics;
9-
using System.Threading.Tasks;
107
using Microsoft.AspNetCore.Components.RenderTree;
118

129
namespace Microsoft.AspNetCore.Components.Rendering
@@ -29,7 +26,7 @@ public sealed class RenderTreeBuilder : IDisposable
2926
private readonly Stack<int> _openElementIndices = new Stack<int>();
3027
private RenderTreeFrameType? _lastNonAttributeFrameType;
3128
private bool _hasSeenAddMultipleAttributes;
32-
private Dictionary<string, int> _seenAttributeNames;
29+
private Dictionary<string, int>? _seenAttributeNames;
3330

3431
/// <summary>
3532
/// The reserved parameter name used for supplying child content.
@@ -82,23 +79,23 @@ public void CloseElement()
8279
/// </summary>
8380
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
8481
/// <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)
8683
=> Append(RenderTreeFrame.Markup(sequence, markupContent ?? string.Empty));
8784

8885
/// <summary>
8986
/// Appends a frame representing text content.
9087
/// </summary>
9188
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
9289
/// <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)
9491
=> Append(RenderTreeFrame.Text(sequence, textContent ?? string.Empty));
9592

9693
/// <summary>
9794
/// Appends frames representing an arbitrary fragment of content.
9895
/// </summary>
9996
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
10097
/// <param name="fragment">Content to append.</param>
101-
public void AddContent(int sequence, RenderFragment fragment)
98+
public void AddContent(int sequence, RenderFragment? fragment)
10299
{
103100
if (fragment != null)
104101
{
@@ -118,7 +115,7 @@ public void AddContent(int sequence, RenderFragment fragment)
118115
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
119116
/// <param name="fragment">Content to append.</param>
120117
/// <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)
122119
{
123120
if (fragment != null)
124121
{
@@ -139,7 +136,7 @@ public void AddContent(int sequence, MarkupString markupContent)
139136
/// </summary>
140137
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
141138
/// <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)
143140
=> AddContent(sequence, textContent?.ToString());
144141

145142
/// <summary>
@@ -185,7 +182,7 @@ public void AddAttribute(int sequence, string name, bool value)
185182
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
186183
/// <param name="name">The name of the attribute.</param>
187184
/// <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)
189186
{
190187
AssertCanAddAttribute();
191188
if (value != null || _lastNonAttributeFrameType == RenderTreeFrameType.Component)
@@ -210,7 +207,7 @@ public void AddAttribute(int sequence, string name, string value)
210207
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
211208
/// <param name="name">The name of the attribute.</param>
212209
/// <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)
214211
{
215212
AssertCanAddAttribute();
216213
if (value != null || _lastNonAttributeFrameType == RenderTreeFrameType.Component)
@@ -320,7 +317,7 @@ public void AddAttribute<TArgument>(int sequence, string name, EventCallback<TAr
320317
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
321318
/// <param name="name">The name of the attribute.</param>
322319
/// <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)
324321
{
325322
// This looks a bit daunting because we need to handle the boxed/object version of all of the
326323
// types that AddAttribute special cases.
@@ -402,7 +399,7 @@ public void AddAttribute(int sequence, in RenderTreeFrame frame)
402399
/// </summary>
403400
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
404401
/// <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)
406403
{
407404
// Calling this up-front just to make sure we validate before mutating anything.
408405
AssertCanAddAttribute();
@@ -455,7 +452,7 @@ public void SetUpdatesAttributeName(string updatesAttributeName)
455452
/// </summary>
456453
/// <typeparam name="TComponent">The type of the child component.</typeparam>
457454
/// <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
459456
=> OpenComponentUnchecked(sequence, typeof(TComponent));
460457

461458
/// <summary>
@@ -477,7 +474,7 @@ public void OpenComponent(int sequence, Type componentType)
477474
/// Assigns the specified key value to the current element or component.
478475
/// </summary>
479476
/// <param name="value">The value for the key.</param>
480-
public void SetKey(object value)
477+
public void SetKey(object? value)
481478
{
482479
if (value == null)
483480
{
@@ -560,7 +557,7 @@ public void AddElementReferenceCapture(int sequence, Action<ElementReference> el
560557
/// </summary>
561558
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
562559
/// <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)
564561
{
565562
var parentFrameIndex = GetCurrentParentFrameIndex();
566563
if (!parentFrameIndex.HasValue)
@@ -640,7 +637,7 @@ public void Clear()
640637

641638
// internal because this should only be used during the post-event tree patching logic
642639
// 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)
644641
{
645642
// Replicate the same attribute omission logic as used elsewhere
646643
if ((attributeValue == null) || (attributeValue is bool boolValue && !boolValue))

src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0;$(DefaultNetCoreTargetFramework)</TargetFrameworks>
55
<TargetFrameworks Condition="'$(DotNetBuildFromSource)' == 'true'">$(DefaultNetCoreTargetFramework)</TargetFrameworks>
6+
<Nullable>annotations</Nullable>
67
</PropertyGroup>
78
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
89
<Compile Include="Microsoft.AspNetCore.Components.Forms.netstandard2.0.cs" />

0 commit comments

Comments
 (0)