Skip to content

Commit 724c2e7

Browse files
authored
Add nullable annotations to Microsoft.AspNetCore.Components (#22944)
* Add nullable for Microsoft.AspNetCore.Components Contributes to #5680 * Fixup
1 parent 52de5ee commit 724c2e7

Some content is hidden

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

49 files changed

+550
-495
lines changed

src/Components/Components/ref/Microsoft.AspNetCore.Components.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.netstandard2.0.cs" />

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

Lines changed: 87 additions & 86 deletions
Large diffs are not rendered by default.

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

Lines changed: 85 additions & 85 deletions
Large diffs are not rendered by default.

src/Components/Components/src/BindConverter.cs

Lines changed: 137 additions & 136 deletions
Large diffs are not rendered by default.

src/Components/Components/src/BindElementAttribute.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public sealed class BindElementAttribute : Attribute
1818
/// <param name="suffix">The suffix value. For example, set this to <c>value</c> for <c>bind-value</c>, or set this to <see langword="null" /> for <c>bind</c>.</param>
1919
/// <param name="valueAttribute">The name of the value attribute to be bound.</param>
2020
/// <param name="changeAttribute">The name of an attribute that will register an associated change event.</param>
21-
public BindElementAttribute(string element, string suffix, string valueAttribute, string changeAttribute)
21+
public BindElementAttribute(string element, string? suffix, string valueAttribute, string changeAttribute)
2222
{
2323
if (element == null)
2424
{
@@ -38,6 +38,7 @@ public BindElementAttribute(string element, string suffix, string valueAttribute
3838
Element = element;
3939
ValueAttribute = valueAttribute;
4040
ChangeAttribute = changeAttribute;
41+
Suffix = suffix;
4142
}
4243

4344
/// <summary>
@@ -49,7 +50,7 @@ public BindElementAttribute(string element, string suffix, string valueAttribute
4950
/// Gets the suffix value.
5051
/// For example, this will be <c>value</c> to mean <c>bind-value</c>, or <see langword="null" /> to mean <c>bind</c>.
5152
/// </summary>
52-
public string Suffix { get; }
53+
public string? Suffix { get; }
5354

5455
/// <summary>
5556
/// Gets the name of the value attribute to be bound.

src/Components/Components/src/CascadingParameterAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ public sealed class CascadingParameterAttribute : Attribute
2222
/// <see cref="CascadingValue{T}"/> that supplies a value with a compatible
2323
/// type.
2424
/// </summary>
25-
public string Name { get; set; }
25+
public string? Name { get; set; }
2626
}
2727
}

src/Components/Components/src/CascadingParameterState.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ public static IReadOnlyList<CascadingParameterState> FindCascadingParameters(Com
3030
var infos = GetReflectedCascadingParameterInfos(componentType);
3131

3232
// For components known not to have any cascading parameters, bail out early
33-
if (infos == null)
33+
if (infos.Length == 0)
3434
{
35-
return null;
35+
return Array.Empty<CascadingParameterState>();
3636
}
3737

3838
// Now try to find matches for each of the cascading parameters
3939
// Defer instantiation of the result list until we know there's at least one
40-
List<CascadingParameterState> resultStates = null;
40+
List<CascadingParameterState>? resultStates = null;
4141

4242
var numInfos = infos.Length;
4343
for (var infoIndex = 0; infoIndex < numInfos; infoIndex++)
@@ -56,10 +56,10 @@ public static IReadOnlyList<CascadingParameterState> FindCascadingParameters(Com
5656
}
5757
}
5858

59-
return resultStates;
59+
return resultStates ?? (IReadOnlyList<CascadingParameterState>)Array.Empty<CascadingParameterState>();
6060
}
6161

62-
private static ICascadingValueComponent GetMatchingCascadingValueSupplier(in ReflectedCascadingParameterInfo info, ComponentState componentState)
62+
private static ICascadingValueComponent? GetMatchingCascadingValueSupplier(in ReflectedCascadingParameterInfo info, ComponentState componentState)
6363
{
6464
do
6565
{
@@ -89,7 +89,7 @@ private static ReflectedCascadingParameterInfo[] GetReflectedCascadingParameterI
8989

9090
private static ReflectedCascadingParameterInfo[] CreateReflectedCascadingParameterInfos(Type componentType)
9191
{
92-
List<ReflectedCascadingParameterInfo> result = null;
92+
List<ReflectedCascadingParameterInfo>? result = null;
9393
var candidateProps = ComponentProperties.GetCandidateBindableProperties(componentType);
9494
foreach (var prop in candidateProps)
9595
{
@@ -108,17 +108,17 @@ private static ReflectedCascadingParameterInfo[] CreateReflectedCascadingParamet
108108
}
109109
}
110110

111-
return result?.ToArray();
111+
return result?.ToArray() ?? Array.Empty<ReflectedCascadingParameterInfo>();
112112
}
113113

114114
readonly struct ReflectedCascadingParameterInfo
115115
{
116116
public string ConsumerValueName { get; }
117-
public string SupplierValueName { get; }
117+
public string? SupplierValueName { get; }
118118
public Type ValueType { get; }
119119

120120
public ReflectedCascadingParameterInfo(
121-
string consumerValueName, Type valueType, string supplierValueName)
121+
string consumerValueName, Type valueType, string? supplierValueName)
122122
{
123123
ConsumerValueName = consumerValueName;
124124
SupplierValueName = supplierValueName;

src/Components/Components/src/CascadingValue.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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+
46
using System;
57
using System.Collections.Generic;
68
using System.Threading.Tasks;
@@ -34,7 +36,7 @@ public class CascadingValue<TValue> : ICascadingValueComponent, IComponent
3436
/// If no name is specified, then descendant components will receive the
3537
/// value based the type of value they are requesting.
3638
/// </summary>
37-
[Parameter] public string Name { get; set; }
39+
[Parameter] public string? Name { get; set; }
3840

3941
/// <summary>
4042
/// If true, indicates that <see cref="Value"/> will not change. This is a

src/Components/Components/src/ChangeDetection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public static bool MayHaveChanged<T1, T2>(T1 oldValue, T2 newValue)
1717
}
1818
else if (oldIsNotNull) // i.e., both are not null (considering previous check)
1919
{
20-
var oldValueType = oldValue.GetType();
21-
var newValueType = newValue.GetType();
20+
var oldValueType = oldValue!.GetType();
21+
var newValueType = newValue!.GetType();
2222
if (oldValueType != newValueType // Definitely different
2323
|| !IsKnownImmutableType(oldValueType) // Maybe different
2424
|| !oldValue.Equals(newValue)) // Somebody says they are different

src/Components/Components/src/ChangeEventArgs.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class ChangeEventArgs : EventArgs
1313
/// <summary>
1414
/// Gets or sets the new value.
1515
/// </summary>
16-
public object Value { get; set; }
17-
16+
public object? Value { get; set; }
1817
}
1918
}

0 commit comments

Comments
 (0)