From 724c2e75a7415e67f9f5ad33fc72bf55507b8d59 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Fri, 19 Jun 2020 11:38:37 -0700 Subject: [PATCH] Add nullable annotations to Microsoft.AspNetCore.Components (#22944) * Add nullable for Microsoft.AspNetCore.Components Contributes to https://github.com/dotnet/aspnetcore/issues/5680 * Fixup --- .../Microsoft.AspNetCore.Components.csproj | 1 + ...rosoft.AspNetCore.Components.netcoreapp.cs | 173 +++++------ ...ft.AspNetCore.Components.netstandard2.0.cs | 170 +++++------ .../Components/src/BindConverter.cs | 273 +++++++++--------- .../Components/src/BindElementAttribute.cs | 5 +- .../src/CascadingParameterAttribute.cs | 2 +- .../Components/src/CascadingParameterState.cs | 18 +- .../Components/src/CascadingValue.cs | 4 +- .../Components/src/ChangeDetection.cs | 4 +- .../Components/src/ChangeEventArgs.cs | 3 +- .../Components/src/ComponentBase.cs | 2 +- src/Components/Components/src/Dispatcher.cs | 2 +- .../Components/src/EventCallback.cs | 8 +- .../EventCallbackFactoryBinderExtensions.cs | 64 ++-- .../Components/src/EventCallbackOfT.cs | 8 +- .../Components/src/EventCallbackWorkItem.cs | 12 +- .../src/ICascadingValueComponent.cs | 4 +- .../Components/src/IEventCallback.cs | 4 +- src/Components/Components/src/IHandleEvent.cs | 2 +- .../Components/src/LayoutComponentBase.cs | 2 +- src/Components/Components/src/LayoutView.cs | 6 +- .../Microsoft.AspNetCore.Components.csproj | 1 + .../Components/src/NavigationManager.cs | 20 +- .../Components/src/OwningComponentBase.cs | 8 +- .../Components/src/ParameterView.cs | 26 +- .../src/Reflection/ComponentProperties.cs | 78 +++-- .../src/Reflection/MemberAssignment.cs | 16 +- src/Components/Components/src/RenderHandle.cs | 4 +- .../src/RenderTree/ArrayBuilderSegment.cs | 12 +- .../src/RenderTree/EventFieldInfo.cs | 2 +- .../src/RenderTree/RenderTreeDiffBuilder.cs | 2 + .../src/RenderTree/RenderTreeFrame.cs | 2 + .../Components/src/RenderTree/Renderer.Log.cs | 2 + .../Components/src/RenderTree/Renderer.cs | 2 + .../src/Rendering/ComponentState.cs | 17 +- .../src/Rendering/RenderTreeBuilder.cs | 2 + .../RendererSynchronizationContext.cs | 2 + src/Components/Components/src/RouteView.cs | 2 + .../Routing/OptionalTypeRouteConstraint.cs | 2 +- .../Components/src/Routing/RouteConstraint.cs | 4 +- .../Components/src/Routing/RouteContext.cs | 6 +- .../Components/src/Routing/RouteEntry.cs | 2 + .../src/Routing/RouteTableFactory.cs | 4 +- .../Components/src/Routing/Router.cs | 2 + .../Components/src/Routing/TemplateSegment.cs | 2 +- .../src/Routing/TypeRouteConstraint.cs | 8 +- .../test/CascadingParameterStateTest.cs | 40 +-- src/Components/Shared/src/ArrayBuilder.cs | 2 + .../HashCodeCombiner/HashCodeCombiner.cs | 8 +- 49 files changed, 550 insertions(+), 495 deletions(-) diff --git a/src/Components/Components/ref/Microsoft.AspNetCore.Components.csproj b/src/Components/Components/ref/Microsoft.AspNetCore.Components.csproj index 50f888c26a..c09fdf223f 100644 --- a/src/Components/Components/ref/Microsoft.AspNetCore.Components.csproj +++ b/src/Components/Components/ref/Microsoft.AspNetCore.Components.csproj @@ -3,6 +3,7 @@ netstandard2.0;$(DefaultNetCoreTargetFramework) $(DefaultNetCoreTargetFramework) + annotations diff --git a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp.cs b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp.cs index 17c4d7a4f5..3fd6df621a 100644 --- a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp.cs +++ b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp.cs @@ -5,69 +5,69 @@ namespace Microsoft.AspNetCore.Components { public static partial class BindConverter { - public static bool FormatValue(bool value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(System.DateTime value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(System.DateTime value, string format, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(System.DateTimeOffset value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(System.DateTimeOffset value, string format, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(decimal value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(double value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(short value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(int value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(long value, System.Globalization.CultureInfo culture = null) { throw null; } - public static bool? FormatValue(bool? value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(System.DateTimeOffset? value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(System.DateTimeOffset? value, string format, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(System.DateTime? value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(System.DateTime? value, string format, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(decimal? value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(double? value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(short? value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(int? value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(long? value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(float? value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(float value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(string value, System.Globalization.CultureInfo culture = null) { throw null; } - public static object FormatValue(T value, System.Globalization.CultureInfo culture = null) { throw null; } - public static bool TryConvertToBool(object obj, System.Globalization.CultureInfo culture, out bool value) { throw null; } - public static bool TryConvertToDateTime(object obj, System.Globalization.CultureInfo culture, out System.DateTime value) { throw null; } - public static bool TryConvertToDateTime(object obj, System.Globalization.CultureInfo culture, string format, out System.DateTime value) { throw null; } - public static bool TryConvertToDateTimeOffset(object obj, System.Globalization.CultureInfo culture, out System.DateTimeOffset value) { throw null; } - public static bool TryConvertToDateTimeOffset(object obj, System.Globalization.CultureInfo culture, string format, out System.DateTimeOffset value) { throw null; } - public static bool TryConvertToDecimal(object obj, System.Globalization.CultureInfo culture, out decimal value) { throw null; } - public static bool TryConvertToDouble(object obj, System.Globalization.CultureInfo culture, out double value) { throw null; } - public static bool TryConvertToFloat(object obj, System.Globalization.CultureInfo culture, out float value) { throw null; } - public static bool TryConvertToInt(object obj, System.Globalization.CultureInfo culture, out int value) { throw null; } - public static bool TryConvertToLong(object obj, System.Globalization.CultureInfo culture, out long value) { throw null; } - public static bool TryConvertToNullableBool(object obj, System.Globalization.CultureInfo culture, out bool? value) { throw null; } - public static bool TryConvertToNullableDateTime(object obj, System.Globalization.CultureInfo culture, out System.DateTime? value) { throw null; } - public static bool TryConvertToNullableDateTime(object obj, System.Globalization.CultureInfo culture, string format, out System.DateTime? value) { throw null; } - public static bool TryConvertToNullableDateTimeOffset(object obj, System.Globalization.CultureInfo culture, out System.DateTimeOffset? value) { throw null; } - public static bool TryConvertToNullableDateTimeOffset(object obj, System.Globalization.CultureInfo culture, string format, out System.DateTimeOffset? value) { throw null; } - public static bool TryConvertToNullableDecimal(object obj, System.Globalization.CultureInfo culture, out decimal? value) { throw null; } - public static bool TryConvertToNullableDouble(object obj, System.Globalization.CultureInfo culture, out double? value) { throw null; } - public static bool TryConvertToNullableFloat(object obj, System.Globalization.CultureInfo culture, out float? value) { throw null; } - public static bool TryConvertToNullableInt(object obj, System.Globalization.CultureInfo culture, out int? value) { throw null; } - public static bool TryConvertToNullableLong(object obj, System.Globalization.CultureInfo culture, out long? value) { throw null; } - public static bool TryConvertToNullableShort(object obj, System.Globalization.CultureInfo culture, out short? value) { throw null; } - public static bool TryConvertToShort(object obj, System.Globalization.CultureInfo culture, out short value) { throw null; } - public static bool TryConvertToString(object obj, System.Globalization.CultureInfo culture, out string value) { throw null; } - public static bool TryConvertTo(object obj, System.Globalization.CultureInfo culture, out T value) { throw null; } + public static bool FormatValue(bool value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string FormatValue(System.DateTime value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string FormatValue(System.DateTime value, string format, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string FormatValue(System.DateTimeOffset value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string FormatValue(System.DateTimeOffset value, string format, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string FormatValue(decimal value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(double value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string FormatValue(short value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(int value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string FormatValue(long value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static bool? FormatValue(bool? value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(System.DateTimeOffset? value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(System.DateTimeOffset? value, string format, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(System.DateTime? value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(System.DateTime? value, string? format, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(decimal? value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(double? value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(short? value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(int? value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(long? value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(float? value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string FormatValue(float value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string FormatValue(string value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static object? FormatValue(T value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static bool TryConvertToBool(object? obj, System.Globalization.CultureInfo? culture, out bool value) { throw null; } + public static bool TryConvertToDateTime(object? obj, System.Globalization.CultureInfo? culture, out System.DateTime value) { throw null; } + public static bool TryConvertToDateTime(object? obj, System.Globalization.CultureInfo? culture, string format, out System.DateTime value) { throw null; } + public static bool TryConvertToDateTimeOffset(object? obj, System.Globalization.CultureInfo? culture, out System.DateTimeOffset value) { throw null; } + public static bool TryConvertToDateTimeOffset(object? obj, System.Globalization.CultureInfo? culture, string format, out System.DateTimeOffset value) { throw null; } + public static bool TryConvertToDecimal(object? obj, System.Globalization.CultureInfo? culture, out decimal value) { throw null; } + public static bool TryConvertToDouble(object? obj, System.Globalization.CultureInfo? culture, out double value) { throw null; } + public static bool TryConvertToFloat(object? obj, System.Globalization.CultureInfo? culture, out float value) { throw null; } + public static bool TryConvertToInt(object? obj, System.Globalization.CultureInfo? culture, out int value) { throw null; } + public static bool TryConvertToLong(object? obj, System.Globalization.CultureInfo? culture, out long value) { throw null; } + public static bool TryConvertToNullableBool(object? obj, System.Globalization.CultureInfo? culture, out bool? value) { throw null; } + public static bool TryConvertToNullableDateTime(object? obj, System.Globalization.CultureInfo? culture, out System.DateTime? value) { throw null; } + public static bool TryConvertToNullableDateTime(object? obj, System.Globalization.CultureInfo? culture, string format, out System.DateTime? value) { throw null; } + public static bool TryConvertToNullableDateTimeOffset(object? obj, System.Globalization.CultureInfo? culture, out System.DateTimeOffset? value) { throw null; } + public static bool TryConvertToNullableDateTimeOffset(object? obj, System.Globalization.CultureInfo? culture, string format, out System.DateTimeOffset? value) { throw null; } + public static bool TryConvertToNullableDecimal(object? obj, System.Globalization.CultureInfo? culture, out decimal? value) { throw null; } + public static bool TryConvertToNullableDouble(object? obj, System.Globalization.CultureInfo? culture, out double? value) { throw null; } + public static bool TryConvertToNullableFloat(object? obj, System.Globalization.CultureInfo? culture, out float? value) { throw null; } + public static bool TryConvertToNullableInt(object? obj, System.Globalization.CultureInfo? culture, out int? value) { throw null; } + public static bool TryConvertToNullableLong(object? obj, System.Globalization.CultureInfo? culture, out long? value) { throw null; } + public static bool TryConvertToNullableShort(object? obj, System.Globalization.CultureInfo? culture, out short? value) { throw null; } + public static bool TryConvertToShort(object? obj, System.Globalization.CultureInfo? culture, out short value) { throw null; } + public static bool TryConvertToString(object? obj, System.Globalization.CultureInfo? culture, out string? value) { throw null; } + public static bool TryConvertTo(object? obj, System.Globalization.CultureInfo? culture, out T value) { throw null; } } [System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=true, Inherited=true)] public sealed partial class BindElementAttribute : System.Attribute { - public BindElementAttribute(string element, string suffix, string valueAttribute, string changeAttribute) { } + public BindElementAttribute(string element, string? suffix, string valueAttribute, string changeAttribute) { } public string ChangeAttribute { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public string Element { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } - public string Suffix { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } + public string? Suffix { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public string ValueAttribute { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } } [System.AttributeUsageAttribute(System.AttributeTargets.Property, AllowMultiple=false, Inherited=true)] public sealed partial class CascadingParameterAttribute : System.Attribute { public CascadingParameterAttribute() { } - public string Name { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public string? Name { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } } public partial class CascadingValue : Microsoft.AspNetCore.Components.IComponent { @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Components [Microsoft.AspNetCore.Components.ParameterAttribute] public bool IsFixed { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } [Microsoft.AspNetCore.Components.ParameterAttribute] - public string Name { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public string? Name { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } [Microsoft.AspNetCore.Components.ParameterAttribute] public TValue Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public void Attach(Microsoft.AspNetCore.Components.RenderHandle renderHandle) { } @@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Components public partial class ChangeEventArgs : System.EventArgs { public ChangeEventArgs() { } - public object Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public object? Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } } public abstract partial class ComponentBase : Microsoft.AspNetCore.Components.IComponent, Microsoft.AspNetCore.Components.IHandleAfterRender, Microsoft.AspNetCore.Components.IHandleEvent { @@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Components protected System.Threading.Tasks.Task InvokeAsync(System.Func workItem) { throw null; } void Microsoft.AspNetCore.Components.IComponent.Attach(Microsoft.AspNetCore.Components.RenderHandle renderHandle) { } System.Threading.Tasks.Task Microsoft.AspNetCore.Components.IHandleAfterRender.OnAfterRenderAsync() { throw null; } - System.Threading.Tasks.Task Microsoft.AspNetCore.Components.IHandleEvent.HandleEventAsync(Microsoft.AspNetCore.Components.EventCallbackWorkItem callback, object arg) { throw null; } + System.Threading.Tasks.Task Microsoft.AspNetCore.Components.IHandleEvent.HandleEventAsync(Microsoft.AspNetCore.Components.EventCallbackWorkItem callback, object? arg) { throw null; } protected virtual void OnAfterRender(bool firstRender) { } protected virtual System.Threading.Tasks.Task OnAfterRenderAsync(bool firstRender) { throw null; } protected virtual void OnInitialized() { } @@ -134,7 +134,7 @@ namespace Microsoft.AspNetCore.Components private readonly int _dummyPrimitive; public static readonly Microsoft.AspNetCore.Components.EventCallback Empty; public static readonly Microsoft.AspNetCore.Components.EventCallbackFactory Factory; - public EventCallback(Microsoft.AspNetCore.Components.IHandleEvent receiver, System.MulticastDelegate @delegate) { throw null; } + public EventCallback(Microsoft.AspNetCore.Components.IHandleEvent? receiver, System.MulticastDelegate? @delegate) { throw null; } public bool HasDelegate { get { throw null; } } public System.Threading.Tasks.Task InvokeAsync(object arg) { throw null; } } @@ -162,30 +162,30 @@ namespace Microsoft.AspNetCore.Components } public static partial class EventCallbackFactoryBinderExtensions { - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, bool existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTimeOffset existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTimeOffset existingValue, string format, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTime existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTime existingValue, string format, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, decimal existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, double existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, short existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, int existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, long existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, bool? existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTimeOffset? existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTimeOffset? existingValue, string format, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTime? existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTime? existingValue, string format, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, decimal? existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, double? existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, short? existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, int? existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, long? existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, float? existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, float existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, string existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, T existingValue, System.Globalization.CultureInfo culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, bool existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTimeOffset existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTimeOffset existingValue, string format, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTime existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTime existingValue, string format, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, decimal existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, double existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, short existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, int existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, long existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, bool? existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTimeOffset? existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTimeOffset? existingValue, string format, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTime? existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTime? existingValue, string format, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, decimal? existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, double? existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, short? existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, int? existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, long? existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, float? existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, float existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, string existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, T existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } } public static partial class EventCallbackFactoryEventArgsExtensions { @@ -200,8 +200,8 @@ namespace Microsoft.AspNetCore.Components private readonly object _dummy; private readonly int _dummyPrimitive; public static readonly Microsoft.AspNetCore.Components.EventCallbackWorkItem Empty; - public EventCallbackWorkItem(System.MulticastDelegate @delegate) { throw null; } - public System.Threading.Tasks.Task InvokeAsync(object arg) { throw null; } + public EventCallbackWorkItem(System.MulticastDelegate? @delegate) { throw null; } + public System.Threading.Tasks.Task InvokeAsync(object? arg) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct EventCallback @@ -209,7 +209,7 @@ namespace Microsoft.AspNetCore.Components private readonly object _dummy; private readonly int _dummyPrimitive; public static readonly Microsoft.AspNetCore.Components.EventCallback Empty; - public EventCallback(Microsoft.AspNetCore.Components.IHandleEvent receiver, System.MulticastDelegate @delegate) { throw null; } + public EventCallback(Microsoft.AspNetCore.Components.IHandleEvent? receiver, System.MulticastDelegate? @delegate) { throw null; } public bool HasDelegate { get { throw null; } } public System.Threading.Tasks.Task InvokeAsync(TValue arg) { throw null; } } @@ -234,7 +234,7 @@ namespace Microsoft.AspNetCore.Components } public partial interface IHandleEvent { - System.Threading.Tasks.Task HandleEventAsync(Microsoft.AspNetCore.Components.EventCallbackWorkItem item, object arg); + System.Threading.Tasks.Task HandleEventAsync(Microsoft.AspNetCore.Components.EventCallbackWorkItem item, object? arg); } [System.AttributeUsageAttribute(System.AttributeTargets.Property, AllowMultiple=false, Inherited=true)] public sealed partial class InjectAttribute : System.Attribute @@ -251,7 +251,7 @@ namespace Microsoft.AspNetCore.Components { protected LayoutComponentBase() { } [Microsoft.AspNetCore.Components.ParameterAttribute] - public Microsoft.AspNetCore.Components.RenderFragment Body { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public Microsoft.AspNetCore.Components.RenderFragment? Body { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } } public partial class LayoutView : Microsoft.AspNetCore.Components.IComponent { @@ -304,7 +304,7 @@ namespace Microsoft.AspNetCore.Components protected virtual void Dispose(bool disposing) { } void System.IDisposable.Dispose() { } } - public abstract partial class OwningComponentBase : Microsoft.AspNetCore.Components.OwningComponentBase, System.IDisposable + public abstract partial class OwningComponentBase : Microsoft.AspNetCore.Components.OwningComponentBase, System.IDisposable where TService : notnull { protected OwningComponentBase() { } protected TService Service { get { throw null; } } @@ -332,11 +332,12 @@ namespace Microsoft.AspNetCore.Components public static Microsoft.AspNetCore.Components.ParameterView Empty { get { throw null; } } public static Microsoft.AspNetCore.Components.ParameterView FromDictionary(System.Collections.Generic.IDictionary parameters) { throw null; } public Microsoft.AspNetCore.Components.ParameterView.Enumerator GetEnumerator() { throw null; } + [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public TValue GetValueOrDefault(string parameterName) { throw null; } public TValue GetValueOrDefault(string parameterName, TValue defaultValue) { throw null; } public void SetParameterProperties(object target) { } public System.Collections.Generic.IReadOnlyDictionary ToDictionary() { throw null; } - public bool TryGetValue(string parameterName, out TValue result) { throw null; } + public bool TryGetValue(string parameterName, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TValue result) { throw null; } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public partial struct Enumerator { diff --git a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs index 17c4d7a4f5..604a8f052b 100644 --- a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs +++ b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs @@ -5,69 +5,69 @@ namespace Microsoft.AspNetCore.Components { public static partial class BindConverter { - public static bool FormatValue(bool value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(System.DateTime value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(System.DateTime value, string format, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(System.DateTimeOffset value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(System.DateTimeOffset value, string format, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(decimal value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(double value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(short value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(int value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(long value, System.Globalization.CultureInfo culture = null) { throw null; } - public static bool? FormatValue(bool? value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(System.DateTimeOffset? value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(System.DateTimeOffset? value, string format, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(System.DateTime? value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(System.DateTime? value, string format, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(decimal? value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(double? value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(short? value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(int? value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(long? value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(float? value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(float value, System.Globalization.CultureInfo culture = null) { throw null; } - public static string FormatValue(string value, System.Globalization.CultureInfo culture = null) { throw null; } - public static object FormatValue(T value, System.Globalization.CultureInfo culture = null) { throw null; } - public static bool TryConvertToBool(object obj, System.Globalization.CultureInfo culture, out bool value) { throw null; } - public static bool TryConvertToDateTime(object obj, System.Globalization.CultureInfo culture, out System.DateTime value) { throw null; } - public static bool TryConvertToDateTime(object obj, System.Globalization.CultureInfo culture, string format, out System.DateTime value) { throw null; } - public static bool TryConvertToDateTimeOffset(object obj, System.Globalization.CultureInfo culture, out System.DateTimeOffset value) { throw null; } - public static bool TryConvertToDateTimeOffset(object obj, System.Globalization.CultureInfo culture, string format, out System.DateTimeOffset value) { throw null; } - public static bool TryConvertToDecimal(object obj, System.Globalization.CultureInfo culture, out decimal value) { throw null; } - public static bool TryConvertToDouble(object obj, System.Globalization.CultureInfo culture, out double value) { throw null; } - public static bool TryConvertToFloat(object obj, System.Globalization.CultureInfo culture, out float value) { throw null; } - public static bool TryConvertToInt(object obj, System.Globalization.CultureInfo culture, out int value) { throw null; } - public static bool TryConvertToLong(object obj, System.Globalization.CultureInfo culture, out long value) { throw null; } - public static bool TryConvertToNullableBool(object obj, System.Globalization.CultureInfo culture, out bool? value) { throw null; } - public static bool TryConvertToNullableDateTime(object obj, System.Globalization.CultureInfo culture, out System.DateTime? value) { throw null; } - public static bool TryConvertToNullableDateTime(object obj, System.Globalization.CultureInfo culture, string format, out System.DateTime? value) { throw null; } - public static bool TryConvertToNullableDateTimeOffset(object obj, System.Globalization.CultureInfo culture, out System.DateTimeOffset? value) { throw null; } - public static bool TryConvertToNullableDateTimeOffset(object obj, System.Globalization.CultureInfo culture, string format, out System.DateTimeOffset? value) { throw null; } - public static bool TryConvertToNullableDecimal(object obj, System.Globalization.CultureInfo culture, out decimal? value) { throw null; } - public static bool TryConvertToNullableDouble(object obj, System.Globalization.CultureInfo culture, out double? value) { throw null; } - public static bool TryConvertToNullableFloat(object obj, System.Globalization.CultureInfo culture, out float? value) { throw null; } - public static bool TryConvertToNullableInt(object obj, System.Globalization.CultureInfo culture, out int? value) { throw null; } - public static bool TryConvertToNullableLong(object obj, System.Globalization.CultureInfo culture, out long? value) { throw null; } - public static bool TryConvertToNullableShort(object obj, System.Globalization.CultureInfo culture, out short? value) { throw null; } - public static bool TryConvertToShort(object obj, System.Globalization.CultureInfo culture, out short value) { throw null; } - public static bool TryConvertToString(object obj, System.Globalization.CultureInfo culture, out string value) { throw null; } - public static bool TryConvertTo(object obj, System.Globalization.CultureInfo culture, out T value) { throw null; } + public static bool FormatValue(bool value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string FormatValue(System.DateTime value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string FormatValue(System.DateTime value, string format, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string FormatValue(System.DateTimeOffset value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string FormatValue(System.DateTimeOffset value, string format, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string FormatValue(decimal value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(double value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string FormatValue(short value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(int value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string FormatValue(long value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static bool? FormatValue(bool? value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(System.DateTimeOffset? value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(System.DateTimeOffset? value, string format, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(System.DateTime? value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(System.DateTime? value, string? format, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(decimal? value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(double? value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(short? value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(int? value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(long? value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string? FormatValue(float? value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string FormatValue(float value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static string FormatValue(string value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static object? FormatValue(T value, System.Globalization.CultureInfo? culture = null) { throw null; } + public static bool TryConvertToBool(object? obj, System.Globalization.CultureInfo? culture, out bool value) { throw null; } + public static bool TryConvertToDateTime(object? obj, System.Globalization.CultureInfo? culture, out System.DateTime value) { throw null; } + public static bool TryConvertToDateTime(object? obj, System.Globalization.CultureInfo? culture, string format, out System.DateTime value) { throw null; } + public static bool TryConvertToDateTimeOffset(object? obj, System.Globalization.CultureInfo? culture, out System.DateTimeOffset value) { throw null; } + public static bool TryConvertToDateTimeOffset(object? obj, System.Globalization.CultureInfo? culture, string format, out System.DateTimeOffset value) { throw null; } + public static bool TryConvertToDecimal(object? obj, System.Globalization.CultureInfo? culture, out decimal value) { throw null; } + public static bool TryConvertToDouble(object? obj, System.Globalization.CultureInfo? culture, out double value) { throw null; } + public static bool TryConvertToFloat(object? obj, System.Globalization.CultureInfo? culture, out float value) { throw null; } + public static bool TryConvertToInt(object? obj, System.Globalization.CultureInfo? culture, out int value) { throw null; } + public static bool TryConvertToLong(object? obj, System.Globalization.CultureInfo? culture, out long value) { throw null; } + public static bool TryConvertToNullableBool(object? obj, System.Globalization.CultureInfo? culture, out bool? value) { throw null; } + public static bool TryConvertToNullableDateTime(object? obj, System.Globalization.CultureInfo? culture, out System.DateTime? value) { throw null; } + public static bool TryConvertToNullableDateTime(object? obj, System.Globalization.CultureInfo? culture, string format, out System.DateTime? value) { throw null; } + public static bool TryConvertToNullableDateTimeOffset(object? obj, System.Globalization.CultureInfo? culture, out System.DateTimeOffset? value) { throw null; } + public static bool TryConvertToNullableDateTimeOffset(object? obj, System.Globalization.CultureInfo? culture, string format, out System.DateTimeOffset? value) { throw null; } + public static bool TryConvertToNullableDecimal(object? obj, System.Globalization.CultureInfo? culture, out decimal? value) { throw null; } + public static bool TryConvertToNullableDouble(object? obj, System.Globalization.CultureInfo? culture, out double? value) { throw null; } + public static bool TryConvertToNullableFloat(object? obj, System.Globalization.CultureInfo? culture, out float? value) { throw null; } + public static bool TryConvertToNullableInt(object? obj, System.Globalization.CultureInfo? culture, out int? value) { throw null; } + public static bool TryConvertToNullableLong(object? obj, System.Globalization.CultureInfo? culture, out long? value) { throw null; } + public static bool TryConvertToNullableShort(object? obj, System.Globalization.CultureInfo? culture, out short? value) { throw null; } + public static bool TryConvertToShort(object? obj, System.Globalization.CultureInfo? culture, out short value) { throw null; } + public static bool TryConvertToString(object? obj, System.Globalization.CultureInfo? culture, out string? value) { throw null; } + public static bool TryConvertTo(object? obj, System.Globalization.CultureInfo? culture, out T value) { throw null; } } [System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=true, Inherited=true)] public sealed partial class BindElementAttribute : System.Attribute { - public BindElementAttribute(string element, string suffix, string valueAttribute, string changeAttribute) { } + public BindElementAttribute(string element, string? suffix, string valueAttribute, string changeAttribute) { } public string ChangeAttribute { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public string Element { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } - public string Suffix { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } + public string? Suffix { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public string ValueAttribute { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } } [System.AttributeUsageAttribute(System.AttributeTargets.Property, AllowMultiple=false, Inherited=true)] public sealed partial class CascadingParameterAttribute : System.Attribute { public CascadingParameterAttribute() { } - public string Name { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public string? Name { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } } public partial class CascadingValue : Microsoft.AspNetCore.Components.IComponent { @@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Components [Microsoft.AspNetCore.Components.ParameterAttribute] public bool IsFixed { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } [Microsoft.AspNetCore.Components.ParameterAttribute] - public string Name { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public string? Name { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } [Microsoft.AspNetCore.Components.ParameterAttribute] public TValue Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public void Attach(Microsoft.AspNetCore.Components.RenderHandle renderHandle) { } @@ -86,7 +86,7 @@ namespace Microsoft.AspNetCore.Components public partial class ChangeEventArgs : System.EventArgs { public ChangeEventArgs() { } - public object Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public object? Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } } public abstract partial class ComponentBase : Microsoft.AspNetCore.Components.IComponent, Microsoft.AspNetCore.Components.IHandleAfterRender, Microsoft.AspNetCore.Components.IHandleEvent { @@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Components protected System.Threading.Tasks.Task InvokeAsync(System.Func workItem) { throw null; } void Microsoft.AspNetCore.Components.IComponent.Attach(Microsoft.AspNetCore.Components.RenderHandle renderHandle) { } System.Threading.Tasks.Task Microsoft.AspNetCore.Components.IHandleAfterRender.OnAfterRenderAsync() { throw null; } - System.Threading.Tasks.Task Microsoft.AspNetCore.Components.IHandleEvent.HandleEventAsync(Microsoft.AspNetCore.Components.EventCallbackWorkItem callback, object arg) { throw null; } + System.Threading.Tasks.Task Microsoft.AspNetCore.Components.IHandleEvent.HandleEventAsync(Microsoft.AspNetCore.Components.EventCallbackWorkItem callback, object? arg) { throw null; } protected virtual void OnAfterRender(bool firstRender) { } protected virtual System.Threading.Tasks.Task OnAfterRenderAsync(bool firstRender) { throw null; } protected virtual void OnInitialized() { } @@ -134,7 +134,7 @@ namespace Microsoft.AspNetCore.Components private readonly int _dummyPrimitive; public static readonly Microsoft.AspNetCore.Components.EventCallback Empty; public static readonly Microsoft.AspNetCore.Components.EventCallbackFactory Factory; - public EventCallback(Microsoft.AspNetCore.Components.IHandleEvent receiver, System.MulticastDelegate @delegate) { throw null; } + public EventCallback(Microsoft.AspNetCore.Components.IHandleEvent? receiver, System.MulticastDelegate? @delegate) { throw null; } public bool HasDelegate { get { throw null; } } public System.Threading.Tasks.Task InvokeAsync(object arg) { throw null; } } @@ -162,30 +162,30 @@ namespace Microsoft.AspNetCore.Components } public static partial class EventCallbackFactoryBinderExtensions { - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, bool existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTimeOffset existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTimeOffset existingValue, string format, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTime existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTime existingValue, string format, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, decimal existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, double existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, short existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, int existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, long existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, bool? existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTimeOffset? existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTimeOffset? existingValue, string format, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTime? existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTime? existingValue, string format, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, decimal? existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, double? existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, short? existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, int? existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, long? existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, float? existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, float existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, string existingValue, System.Globalization.CultureInfo culture = null) { throw null; } - public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, T existingValue, System.Globalization.CultureInfo culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, bool existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTimeOffset existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTimeOffset existingValue, string format, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTime existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTime existingValue, string format, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, decimal existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, double existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, short existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, int existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, long existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, bool? existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTimeOffset? existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTimeOffset? existingValue, string format, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTime? existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, System.DateTime? existingValue, string format, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, decimal? existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, double? existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, short? existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, int? existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, long? existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, float? existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, float existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, string existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } + public static Microsoft.AspNetCore.Components.EventCallback CreateBinder(this Microsoft.AspNetCore.Components.EventCallbackFactory factory, object receiver, System.Action setter, T existingValue, System.Globalization.CultureInfo? culture = null) { throw null; } } public static partial class EventCallbackFactoryEventArgsExtensions { @@ -200,8 +200,8 @@ namespace Microsoft.AspNetCore.Components private readonly object _dummy; private readonly int _dummyPrimitive; public static readonly Microsoft.AspNetCore.Components.EventCallbackWorkItem Empty; - public EventCallbackWorkItem(System.MulticastDelegate @delegate) { throw null; } - public System.Threading.Tasks.Task InvokeAsync(object arg) { throw null; } + public EventCallbackWorkItem(System.MulticastDelegate? @delegate) { throw null; } + public System.Threading.Tasks.Task InvokeAsync(object? arg) { throw null; } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public readonly partial struct EventCallback @@ -209,7 +209,7 @@ namespace Microsoft.AspNetCore.Components private readonly object _dummy; private readonly int _dummyPrimitive; public static readonly Microsoft.AspNetCore.Components.EventCallback Empty; - public EventCallback(Microsoft.AspNetCore.Components.IHandleEvent receiver, System.MulticastDelegate @delegate) { throw null; } + public EventCallback(Microsoft.AspNetCore.Components.IHandleEvent? receiver, System.MulticastDelegate? @delegate) { throw null; } public bool HasDelegate { get { throw null; } } public System.Threading.Tasks.Task InvokeAsync(TValue arg) { throw null; } } @@ -234,7 +234,7 @@ namespace Microsoft.AspNetCore.Components } public partial interface IHandleEvent { - System.Threading.Tasks.Task HandleEventAsync(Microsoft.AspNetCore.Components.EventCallbackWorkItem item, object arg); + System.Threading.Tasks.Task HandleEventAsync(Microsoft.AspNetCore.Components.EventCallbackWorkItem item, object? arg); } [System.AttributeUsageAttribute(System.AttributeTargets.Property, AllowMultiple=false, Inherited=true)] public sealed partial class InjectAttribute : System.Attribute @@ -251,7 +251,7 @@ namespace Microsoft.AspNetCore.Components { protected LayoutComponentBase() { } [Microsoft.AspNetCore.Components.ParameterAttribute] - public Microsoft.AspNetCore.Components.RenderFragment Body { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public Microsoft.AspNetCore.Components.RenderFragment? Body { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } } public partial class LayoutView : Microsoft.AspNetCore.Components.IComponent { @@ -304,7 +304,7 @@ namespace Microsoft.AspNetCore.Components protected virtual void Dispose(bool disposing) { } void System.IDisposable.Dispose() { } } - public abstract partial class OwningComponentBase : Microsoft.AspNetCore.Components.OwningComponentBase, System.IDisposable + public abstract partial class OwningComponentBase : Microsoft.AspNetCore.Components.OwningComponentBase, System.IDisposable where TService : notnull { protected OwningComponentBase() { } protected TService Service { get { throw null; } } diff --git a/src/Components/Components/src/BindConverter.cs b/src/Components/Components/src/BindConverter.cs index c8fcfcff7e..68170010dc 100644 --- a/src/Components/Components/src/BindConverter.cs +++ b/src/Components/Components/src/BindConverter.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Concurrent; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Reflection; @@ -18,14 +19,14 @@ namespace Microsoft.AspNetCore.Components // to allocate. public static class BindConverter { - private static object BoxedTrue = true; - private static object BoxedFalse = false; + private static readonly object BoxedTrue = true; + private static readonly object BoxedFalse = false; - private delegate object BindFormatter(T value, CultureInfo culture); - private delegate object BindFormatterWithFormat(T value, CultureInfo culture, string format); + private delegate object? BindFormatter(T value, CultureInfo? culture); + private delegate object BindFormatterWithFormat(T value, CultureInfo? culture, string format); - internal delegate bool BindParser(object obj, CultureInfo culture, out T value); - internal delegate bool BindParserWithFormat(object obj, CultureInfo culture, string format, out T value); + internal delegate bool BindParser(object? obj, CultureInfo? culture, out T value); + internal delegate bool BindParserWithFormat(object? obj, CultureInfo? culture, string? format, out T value); /// /// Formats the provided as a . @@ -35,9 +36,9 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(string value, CultureInfo culture = null) => FormatStringValueCore(value, culture); + public static string FormatValue(string value, CultureInfo? culture = null) => FormatStringValueCore(value, culture); - private static string FormatStringValueCore(string value, CultureInfo culture) + private static string FormatStringValueCore(string value, CultureInfo? culture) { return value; } @@ -50,7 +51,7 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static bool FormatValue(bool value, CultureInfo culture = null) + public static bool FormatValue(bool value, CultureInfo? culture = null) { // Formatting for bool is special-cased. We need to produce a boolean value for conditional attributes // to work. @@ -58,7 +59,7 @@ namespace Microsoft.AspNetCore.Components } // Used with generics - private static object FormatBoolValueCore(bool value, CultureInfo culture) + private static object FormatBoolValueCore(bool value, CultureInfo? culture) { // Formatting for bool is special-cased. We need to produce a boolean value for conditional attributes // to work. @@ -73,7 +74,7 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static bool? FormatValue(bool? value, CultureInfo culture = null) + public static bool? FormatValue(bool? value, CultureInfo? culture = null) { // Formatting for bool is special-cased. We need to produce a boolean value for conditional attributes // to work. @@ -81,7 +82,7 @@ namespace Microsoft.AspNetCore.Components } // Used with generics - private static object FormatNullableBoolValueCore(bool? value, CultureInfo culture) + private static object? FormatNullableBoolValueCore(bool? value, CultureInfo? culture) { // Formatting for bool is special-cased. We need to produce a boolean value for conditional attributes // to work. @@ -96,9 +97,9 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(int value, CultureInfo culture = null) => FormatIntValueCore(value, culture); + public static string? FormatValue(int value, CultureInfo? culture = null) => FormatIntValueCore(value, culture); - private static string FormatIntValueCore(int value, CultureInfo culture) + private static string? FormatIntValueCore(int value, CultureInfo? culture) { return value.ToString(culture ?? CultureInfo.CurrentCulture); } @@ -111,9 +112,9 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(int? value, CultureInfo culture = null) => FormatNullableIntValueCore(value, culture); + public static string? FormatValue(int? value, CultureInfo? culture = null) => FormatNullableIntValueCore(value, culture); - private static string FormatNullableIntValueCore(int? value, CultureInfo culture) + private static string? FormatNullableIntValueCore(int? value, CultureInfo? culture) { if (value == null) { @@ -131,9 +132,9 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(long value, CultureInfo culture = null) => FormatLongValueCore(value, culture); + public static string FormatValue(long value, CultureInfo? culture = null) => FormatLongValueCore(value, culture); - private static string FormatLongValueCore(long value, CultureInfo culture) + private static string FormatLongValueCore(long value, CultureInfo? culture) { return value.ToString(culture ?? CultureInfo.CurrentCulture); } @@ -146,9 +147,9 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(long? value, CultureInfo culture = null) => FormatNullableLongValueCore(value, culture); + public static string? FormatValue(long? value, CultureInfo? culture = null) => FormatNullableLongValueCore(value, culture); - private static string FormatNullableLongValueCore(long? value, CultureInfo culture) + private static string? FormatNullableLongValueCore(long? value, CultureInfo? culture) { if (value == null) { @@ -166,9 +167,9 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(short value, CultureInfo culture = null) => FormatShortValueCore(value, culture); + public static string FormatValue(short value, CultureInfo? culture = null) => FormatShortValueCore(value, culture); - private static string FormatShortValueCore(short value, CultureInfo culture) + private static string FormatShortValueCore(short value, CultureInfo? culture) { return value.ToString(culture ?? CultureInfo.CurrentCulture); } @@ -181,9 +182,9 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(short? value, CultureInfo culture = null) => FormatNullableShortValueCore(value, culture); + public static string? FormatValue(short? value, CultureInfo? culture = null) => FormatNullableShortValueCore(value, culture); - private static string FormatNullableShortValueCore(short? value, CultureInfo culture) + private static string? FormatNullableShortValueCore(short? value, CultureInfo? culture) { if (value == null) { @@ -201,9 +202,9 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(float value, CultureInfo culture = null) => FormatFloatValueCore(value, culture); + public static string FormatValue(float value, CultureInfo? culture = null) => FormatFloatValueCore(value, culture); - private static string FormatFloatValueCore(float value, CultureInfo culture) + private static string FormatFloatValueCore(float value, CultureInfo? culture) { return value.ToString(culture ?? CultureInfo.CurrentCulture); } @@ -216,9 +217,9 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(float? value, CultureInfo culture = null) => FormatNullableFloatValueCore(value, culture); + public static string? FormatValue(float? value, CultureInfo? culture = null) => FormatNullableFloatValueCore(value, culture); - private static string FormatNullableFloatValueCore(float? value, CultureInfo culture) + private static string? FormatNullableFloatValueCore(float? value, CultureInfo? culture) { if (value == null) { @@ -236,9 +237,9 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(double value, CultureInfo culture = null) => FormatDoubleValueCore(value, culture); + public static string? FormatValue(double value, CultureInfo? culture = null) => FormatDoubleValueCore(value, culture); - private static string FormatDoubleValueCore(double value, CultureInfo culture) + private static string FormatDoubleValueCore(double value, CultureInfo? culture) { return value.ToString(culture ?? CultureInfo.CurrentCulture); } @@ -251,9 +252,9 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(double? value, CultureInfo culture = null) => FormatNullableDoubleValueCore(value, culture); + public static string? FormatValue(double? value, CultureInfo? culture = null) => FormatNullableDoubleValueCore(value, culture); - private static string FormatNullableDoubleValueCore(double? value, CultureInfo culture) + private static string? FormatNullableDoubleValueCore(double? value, CultureInfo? culture) { if (value == null) { @@ -271,9 +272,9 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(decimal value, CultureInfo culture = null) => FormatDecimalValueCore(value, culture); + public static string FormatValue(decimal value, CultureInfo? culture = null) => FormatDecimalValueCore(value, culture); - private static string FormatDecimalValueCore(decimal value, CultureInfo culture) + private static string FormatDecimalValueCore(decimal value, CultureInfo? culture) { return value.ToString(culture ?? CultureInfo.CurrentCulture); } @@ -286,9 +287,9 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(decimal? value, CultureInfo culture = null) => FormatNullableDecimalValueCore(value, culture); + public static string? FormatValue(decimal? value, CultureInfo? culture = null) => FormatNullableDecimalValueCore(value, culture); - private static string FormatNullableDecimalValueCore(decimal? value, CultureInfo culture) + private static string? FormatNullableDecimalValueCore(decimal? value, CultureInfo? culture) { if (value == null) { @@ -306,7 +307,7 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(DateTime value, CultureInfo culture = null) => FormatDateTimeValueCore(value, format: null, culture); + public static string FormatValue(DateTime value, CultureInfo? culture = null) => FormatDateTimeValueCore(value, format: null, culture); /// /// Formats the provided as a . @@ -317,9 +318,9 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(DateTime value, string format, CultureInfo culture = null) => FormatDateTimeValueCore(value, format, culture); + public static string FormatValue(DateTime value, string format, CultureInfo? culture = null) => FormatDateTimeValueCore(value, format, culture); - private static string FormatDateTimeValueCore(DateTime value, string format, CultureInfo culture) + private static string FormatDateTimeValueCore(DateTime value, string? format, CultureInfo? culture) { if (format != null) { @@ -329,7 +330,7 @@ namespace Microsoft.AspNetCore.Components return value.ToString(culture ?? CultureInfo.CurrentCulture); } - private static string FormatDateTimeValueCore(DateTime value, CultureInfo culture) + private static string FormatDateTimeValueCore(DateTime value, CultureInfo? culture) { return value.ToString(culture ?? CultureInfo.CurrentCulture); } @@ -342,7 +343,7 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(DateTime? value, CultureInfo culture = null) => FormatNullableDateTimeValueCore(value, format: null, culture); + public static string? FormatValue(DateTime? value, CultureInfo? culture = null) => FormatNullableDateTimeValueCore(value, format: null, culture); /// /// Formats the provided as a . @@ -353,9 +354,9 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(DateTime? value, string format, CultureInfo culture = null) => FormatNullableDateTimeValueCore(value, format, culture); + public static string? FormatValue(DateTime? value, string? format, CultureInfo? culture = null) => FormatNullableDateTimeValueCore(value, format, culture); - private static string FormatNullableDateTimeValueCore(DateTime? value, string format, CultureInfo culture) + private static string? FormatNullableDateTimeValueCore(DateTime? value, string? format, CultureInfo? culture) { if (value == null) { @@ -370,7 +371,7 @@ namespace Microsoft.AspNetCore.Components return value.Value.ToString(culture ?? CultureInfo.CurrentCulture); } - private static string FormatNullableDateTimeValueCore(DateTime? value, CultureInfo culture) + private static string? FormatNullableDateTimeValueCore(DateTime? value, CultureInfo? culture) { if (value == null) { @@ -388,7 +389,7 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(DateTimeOffset value, CultureInfo culture = null) => FormatDateTimeOffsetValueCore(value, format: null, culture); + public static string FormatValue(DateTimeOffset value, CultureInfo? culture = null) => FormatDateTimeOffsetValueCore(value, format: null, culture); /// @@ -400,9 +401,9 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(DateTimeOffset value, string format, CultureInfo culture = null) => FormatDateTimeOffsetValueCore(value, format, culture); + public static string FormatValue(DateTimeOffset value, string format, CultureInfo? culture = null) => FormatDateTimeOffsetValueCore(value, format, culture); - private static string FormatDateTimeOffsetValueCore(DateTimeOffset value, string format, CultureInfo culture) + private static string FormatDateTimeOffsetValueCore(DateTimeOffset value, string? format, CultureInfo? culture) { if (format != null) { @@ -412,7 +413,7 @@ namespace Microsoft.AspNetCore.Components return value.ToString(culture ?? CultureInfo.CurrentCulture); } - private static string FormatDateTimeOffsetValueCore(DateTimeOffset value, CultureInfo culture) + private static string FormatDateTimeOffsetValueCore(DateTimeOffset value, CultureInfo? culture) { return value.ToString(culture ?? CultureInfo.CurrentCulture); } @@ -425,7 +426,7 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(DateTimeOffset? value, CultureInfo culture = null) => FormatNullableDateTimeOffsetValueCore(value, format: null, culture); + public static string? FormatValue(DateTimeOffset? value, CultureInfo? culture = null) => FormatNullableDateTimeOffsetValueCore(value, format: null, culture); /// /// Formats the provided as a . @@ -436,9 +437,9 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(DateTimeOffset? value, string format, CultureInfo culture = null) => FormatNullableDateTimeOffsetValueCore(value, format, culture); + public static string? FormatValue(DateTimeOffset? value, string format, CultureInfo? culture = null) => FormatNullableDateTimeOffsetValueCore(value, format, culture); - private static string FormatNullableDateTimeOffsetValueCore(DateTimeOffset? value, string format, CultureInfo culture) + private static string? FormatNullableDateTimeOffsetValueCore(DateTimeOffset? value, string? format, CultureInfo? culture) { if (value == null) { @@ -453,7 +454,7 @@ namespace Microsoft.AspNetCore.Components return value.Value.ToString(culture ?? CultureInfo.CurrentCulture); } - private static string FormatNullableDateTimeOffsetValueCore(DateTimeOffset? value, CultureInfo culture) + private static string? FormatNullableDateTimeOffsetValueCore(DateTimeOffset? value, CultureInfo? culture) { if (value == null) { @@ -463,12 +464,12 @@ namespace Microsoft.AspNetCore.Components return value.Value.ToString(culture ?? CultureInfo.CurrentCulture); } - private static string FormatEnumValueCore(T value, CultureInfo culture) where T : struct, Enum + private static string FormatEnumValueCore(T value, CultureInfo? culture) where T : struct, Enum { return value.ToString(); // The overload that accepts a culture is [Obsolete] } - private static string FormatNullableEnumValueCore(T? value, CultureInfo culture) where T : struct, Enum + private static string? FormatNullableEnumValueCore(T? value, CultureInfo? culture) where T : struct, Enum { if (value == null) { @@ -486,7 +487,7 @@ namespace Microsoft.AspNetCore.Components /// The to use while formatting. Defaults to . /// /// The formatted value. - public static object FormatValue(T value, CultureInfo culture = null) + public static object? FormatValue(T value, CultureInfo? culture = null) { var formatter = FormatterDelegateCache.Get(); return formatter(value, culture); @@ -499,17 +500,17 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToString(object obj, CultureInfo culture, out string value) + public static bool TryConvertToString(object? obj, CultureInfo? culture, out string? value) { return ConvertToStringCore(obj, culture, out value); } - internal readonly static BindParser ConvertToString = ConvertToStringCore; + internal readonly static BindParser ConvertToString = ConvertToStringCore; - private static bool ConvertToStringCore(object obj, CultureInfo culture, out string value) + private static bool ConvertToStringCore(object? obj, CultureInfo? culture, out string? value) { // We expect the input to already be a string. - value = (string)obj; + value = (string?)obj; return true; } @@ -520,7 +521,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToBool(object obj, CultureInfo culture, out bool value) + public static bool TryConvertToBool(object? obj, CultureInfo? culture, out bool value) { return ConvertToBoolCore(obj, culture, out value); } @@ -532,7 +533,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToNullableBool(object obj, CultureInfo culture, out bool? value) + public static bool TryConvertToNullableBool(object? obj, CultureInfo? culture, out bool? value) { return ConvertToNullableBoolCore(obj, culture, out value); } @@ -540,14 +541,14 @@ namespace Microsoft.AspNetCore.Components internal readonly static BindParser ConvertToBool = ConvertToBoolCore; internal readonly static BindParser ConvertToNullableBool = ConvertToNullableBoolCore; - private static bool ConvertToBoolCore(object obj, CultureInfo culture, out bool value) + private static bool ConvertToBoolCore(object? obj, CultureInfo? culture, out bool value) { // We expect the input to already be a bool. - value = (bool)obj; + value = (bool)obj!; return true; } - private static bool ConvertToNullableBoolCore(object obj, CultureInfo culture, out bool? value) + private static bool ConvertToNullableBoolCore(object? obj, CultureInfo? culture, out bool? value) { // We expect the input to already be a bool. value = (bool?)obj; @@ -561,7 +562,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToInt(object obj, CultureInfo culture, out int value) + public static bool TryConvertToInt(object? obj, CultureInfo? culture, out int value) { return ConvertToIntCore(obj, culture, out value); } @@ -573,7 +574,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToNullableInt(object obj, CultureInfo culture, out int? value) + public static bool TryConvertToNullableInt(object? obj, CultureInfo? culture, out int? value) { return ConvertToNullableIntCore(obj, culture, out value); } @@ -581,9 +582,9 @@ namespace Microsoft.AspNetCore.Components internal static BindParser ConvertToInt = ConvertToIntCore; internal static BindParser ConvertToNullableInt = ConvertToNullableIntCore; - private static bool ConvertToIntCore(object obj, CultureInfo culture, out int value) + private static bool ConvertToIntCore(object? obj, CultureInfo? culture, out int value) { - var text = (string)obj; + var text = (string?)obj; if (string.IsNullOrEmpty(text)) { value = default; @@ -600,9 +601,9 @@ namespace Microsoft.AspNetCore.Components return true; } - private static bool ConvertToNullableIntCore(object obj, CultureInfo culture, out int? value) + private static bool ConvertToNullableIntCore(object? obj, CultureInfo? culture, out int? value) { - var text = (string)obj; + var text = (string?)obj; if (string.IsNullOrEmpty(text)) { value = default; @@ -626,7 +627,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToLong(object obj, CultureInfo culture, out long value) + public static bool TryConvertToLong(object? obj, CultureInfo? culture, out long value) { return ConvertToLongCore(obj, culture, out value); } @@ -638,7 +639,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToNullableLong(object obj, CultureInfo culture, out long? value) + public static bool TryConvertToNullableLong(object? obj, CultureInfo? culture, out long? value) { return ConvertToNullableLongCore(obj, culture, out value); } @@ -646,9 +647,9 @@ namespace Microsoft.AspNetCore.Components internal static BindParser ConvertToLong = ConvertToLongCore; internal static BindParser ConvertToNullableLong = ConvertToNullableLongCore; - private static bool ConvertToLongCore(object obj, CultureInfo culture, out long value) + private static bool ConvertToLongCore(object? obj, CultureInfo? culture, out long value) { - var text = (string)obj; + var text = (string?)obj; if (string.IsNullOrEmpty(text)) { value = default; @@ -665,9 +666,9 @@ namespace Microsoft.AspNetCore.Components return true; } - private static bool ConvertToNullableLongCore(object obj, CultureInfo culture, out long? value) + private static bool ConvertToNullableLongCore(object? obj, CultureInfo? culture, out long? value) { - var text = (string)obj; + var text = (string?)obj; if (string.IsNullOrEmpty(text)) { value = default; @@ -691,7 +692,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToShort(object obj, CultureInfo culture, out short value) + public static bool TryConvertToShort(object? obj, CultureInfo? culture, out short value) { return ConvertToShortCore(obj, culture, out value); } @@ -703,7 +704,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToNullableShort(object obj, CultureInfo culture, out short? value) + public static bool TryConvertToNullableShort(object? obj, CultureInfo? culture, out short? value) { return ConvertToNullableShort(obj, culture, out value); } @@ -711,9 +712,9 @@ namespace Microsoft.AspNetCore.Components internal static BindParser ConvertToShort = ConvertToShortCore; internal static BindParser ConvertToNullableShort = ConvertToNullableShortCore; - private static bool ConvertToShortCore(object obj, CultureInfo culture, out short value) + private static bool ConvertToShortCore(object? obj, CultureInfo? culture, out short value) { - var text = (string)obj; + var text = (string?)obj; if (string.IsNullOrEmpty(text)) { value = default; @@ -730,9 +731,9 @@ namespace Microsoft.AspNetCore.Components return true; } - private static bool ConvertToNullableShortCore(object obj, CultureInfo culture, out short? value) + private static bool ConvertToNullableShortCore(object? obj, CultureInfo? culture, out short? value) { - var text = (string)obj; + var text = (string?)obj; if (string.IsNullOrEmpty(text)) { value = default; @@ -756,7 +757,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToFloat(object obj, CultureInfo culture, out float value) + public static bool TryConvertToFloat(object? obj, CultureInfo? culture, out float value) { return ConvertToFloatCore(obj, culture, out value); } @@ -768,7 +769,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToNullableFloat(object obj, CultureInfo culture, out float? value) + public static bool TryConvertToNullableFloat(object? obj, CultureInfo? culture, out float? value) { return ConvertToNullableFloatCore(obj, culture, out value); } @@ -776,9 +777,9 @@ namespace Microsoft.AspNetCore.Components internal static BindParser ConvertToFloat = ConvertToFloatCore; internal static BindParser ConvertToNullableFloat = ConvertToNullableFloatCore; - private static bool ConvertToFloatCore(object obj, CultureInfo culture, out float value) + private static bool ConvertToFloatCore(object? obj, CultureInfo? culture, out float value) { - var text = (string)obj; + var text = (string?)obj; if (string.IsNullOrEmpty(text)) { value = default; @@ -801,9 +802,9 @@ namespace Microsoft.AspNetCore.Components return true; } - private static bool ConvertToNullableFloatCore(object obj, CultureInfo culture, out float? value) + private static bool ConvertToNullableFloatCore(object? obj, CultureInfo? culture, out float? value) { - var text = (string)obj; + var text = (string?)obj; if (string.IsNullOrEmpty(text)) { value = default; @@ -833,7 +834,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToDouble(object obj, CultureInfo culture, out double value) + public static bool TryConvertToDouble(object? obj, CultureInfo? culture, out double value) { return ConvertToDoubleCore(obj, culture, out value); } @@ -845,7 +846,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToNullableDouble(object obj, CultureInfo culture, out double? value) + public static bool TryConvertToNullableDouble(object? obj, CultureInfo? culture, out double? value) { return ConvertToNullableDoubleCore(obj, culture, out value); } @@ -853,9 +854,9 @@ namespace Microsoft.AspNetCore.Components internal static BindParser ConvertToDoubleDelegate = ConvertToDoubleCore; internal static BindParser ConvertToNullableDoubleDelegate = ConvertToNullableDoubleCore; - private static bool ConvertToDoubleCore(object obj, CultureInfo culture, out double value) + private static bool ConvertToDoubleCore(object? obj, CultureInfo? culture, out double value) { - var text = (string)obj; + var text = (string?)obj; if (string.IsNullOrEmpty(text)) { value = default; @@ -878,9 +879,9 @@ namespace Microsoft.AspNetCore.Components return true; } - private static bool ConvertToNullableDoubleCore(object obj, CultureInfo culture, out double? value) + private static bool ConvertToNullableDoubleCore(object? obj, CultureInfo? culture, out double? value) { - var text = (string)obj; + var text = (string?)obj; if (string.IsNullOrEmpty(text)) { value = default; @@ -910,7 +911,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToDecimal(object obj, CultureInfo culture, out decimal value) + public static bool TryConvertToDecimal(object? obj, CultureInfo? culture, out decimal value) { return ConvertToDecimalCore(obj, culture, out value); } @@ -922,7 +923,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToNullableDecimal(object obj, CultureInfo culture, out decimal? value) + public static bool TryConvertToNullableDecimal(object? obj, CultureInfo? culture, out decimal? value) { return ConvertToNullableDecimalCore(obj, culture, out value); } @@ -930,9 +931,9 @@ namespace Microsoft.AspNetCore.Components internal static BindParser ConvertToDecimal = ConvertToDecimalCore; internal static BindParser ConvertToNullableDecimal = ConvertToNullableDecimalCore; - private static bool ConvertToDecimalCore(object obj, CultureInfo culture, out decimal value) + private static bool ConvertToDecimalCore(object? obj, CultureInfo? culture, out decimal value) { - var text = (string)obj; + var text = (string?)obj; if (string.IsNullOrEmpty(text)) { value = default; @@ -949,9 +950,9 @@ namespace Microsoft.AspNetCore.Components return true; } - private static bool ConvertToNullableDecimalCore(object obj, CultureInfo culture, out decimal? value) + private static bool ConvertToNullableDecimalCore(object? obj, CultureInfo? culture, out decimal? value) { - var text = (string)obj; + var text = (string?)obj; if (string.IsNullOrEmpty(text)) { value = default; @@ -975,7 +976,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToDateTime(object obj, CultureInfo culture, out DateTime value) + public static bool TryConvertToDateTime(object? obj, CultureInfo? culture, out DateTime value) { return ConvertToDateTimeCore(obj, culture, out value); } @@ -988,7 +989,7 @@ namespace Microsoft.AspNetCore.Components /// The format string to use in conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToDateTime(object obj, CultureInfo culture, string format, out DateTime value) + public static bool TryConvertToDateTime(object? obj, CultureInfo? culture, string format, out DateTime value) { return ConvertToDateTimeCore(obj, culture, format, out value); } @@ -1000,7 +1001,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToNullableDateTime(object obj, CultureInfo culture, out DateTime? value) + public static bool TryConvertToNullableDateTime(object? obj, CultureInfo? culture, out DateTime? value) { return ConvertToNullableDateTimeCore(obj, culture, out value); } @@ -1013,7 +1014,7 @@ namespace Microsoft.AspNetCore.Components /// The format string to use in conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToNullableDateTime(object obj, CultureInfo culture, string format, out DateTime? value) + public static bool TryConvertToNullableDateTime(object? obj, CultureInfo? culture, string format, out DateTime? value) { return ConvertToNullableDateTimeCore(obj, culture, format, out value); } @@ -1023,14 +1024,14 @@ namespace Microsoft.AspNetCore.Components internal static BindParser ConvertToNullableDateTime = ConvertToNullableDateTimeCore; internal static BindParserWithFormat ConvertToNullableDateTimeWithFormat = ConvertToNullableDateTimeCore; - private static bool ConvertToDateTimeCore(object obj, CultureInfo culture, out DateTime value) + private static bool ConvertToDateTimeCore(object? obj, CultureInfo? culture, out DateTime value) { return ConvertToDateTimeCore(obj, culture, format: null, out value); } - private static bool ConvertToDateTimeCore(object obj, CultureInfo culture, string format, out DateTime value) + private static bool ConvertToDateTimeCore(object? obj, CultureInfo? culture, string? format, out DateTime value) { - var text = (string)obj; + var text = (string?)obj; if (string.IsNullOrEmpty(text)) { value = default; @@ -1052,14 +1053,14 @@ namespace Microsoft.AspNetCore.Components return false; } - private static bool ConvertToNullableDateTimeCore(object obj, CultureInfo culture, out DateTime? value) + private static bool ConvertToNullableDateTimeCore(object? obj, CultureInfo? culture, out DateTime? value) { return ConvertToNullableDateTimeCore(obj, culture, format: null, out value); } - private static bool ConvertToNullableDateTimeCore(object obj, CultureInfo culture, string format, out DateTime? value) + private static bool ConvertToNullableDateTimeCore(object? obj, CultureInfo? culture, string? format, out DateTime? value) { - var text = (string)obj; + var text = (string?)obj; if (string.IsNullOrEmpty(text)) { value = default; @@ -1088,7 +1089,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToDateTimeOffset(object obj, CultureInfo culture, out DateTimeOffset value) + public static bool TryConvertToDateTimeOffset(object? obj, CultureInfo? culture, out DateTimeOffset value) { return ConvertToDateTimeOffsetCore(obj, culture, out value); } @@ -1101,7 +1102,7 @@ namespace Microsoft.AspNetCore.Components /// The format string to use in conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToDateTimeOffset(object obj, CultureInfo culture, string format, out DateTimeOffset value) + public static bool TryConvertToDateTimeOffset(object? obj, CultureInfo? culture, string format, out DateTimeOffset value) { return ConvertToDateTimeOffsetCore(obj, culture, format, out value); } @@ -1113,7 +1114,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToNullableDateTimeOffset(object obj, CultureInfo culture, out DateTimeOffset? value) + public static bool TryConvertToNullableDateTimeOffset(object? obj, CultureInfo? culture, out DateTimeOffset? value) { return ConvertToNullableDateTimeOffsetCore(obj, culture, out value); } @@ -1126,7 +1127,7 @@ namespace Microsoft.AspNetCore.Components /// The format string to use in conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertToNullableDateTimeOffset(object obj, CultureInfo culture, string format, out DateTimeOffset? value) + public static bool TryConvertToNullableDateTimeOffset(object? obj, CultureInfo? culture, string format, out DateTimeOffset? value) { return ConvertToNullableDateTimeOffsetCore(obj, culture, format, out value); } @@ -1136,14 +1137,14 @@ namespace Microsoft.AspNetCore.Components internal static BindParser ConvertToNullableDateTimeOffset = ConvertToNullableDateTimeOffsetCore; internal static BindParserWithFormat ConvertToNullableDateTimeOffsetWithFormat = ConvertToNullableDateTimeOffsetCore; - private static bool ConvertToDateTimeOffsetCore(object obj, CultureInfo culture, out DateTimeOffset value) + private static bool ConvertToDateTimeOffsetCore(object? obj, CultureInfo? culture, out DateTimeOffset value) { return ConvertToDateTimeOffsetCore(obj, culture, format: null, out value); } - private static bool ConvertToDateTimeOffsetCore(object obj, CultureInfo culture, string format, out DateTimeOffset value) + private static bool ConvertToDateTimeOffsetCore(object? obj, CultureInfo? culture, string? format, out DateTimeOffset value) { - var text = (string)obj; + var text = (string?)obj; if (string.IsNullOrEmpty(text)) { value = default; @@ -1165,14 +1166,14 @@ namespace Microsoft.AspNetCore.Components return false; } - private static bool ConvertToNullableDateTimeOffsetCore(object obj, CultureInfo culture, out DateTimeOffset? value) + private static bool ConvertToNullableDateTimeOffsetCore(object? obj, CultureInfo? culture, out DateTimeOffset? value) { return ConvertToNullableDateTimeOffsetCore(obj, culture, format: null, out value); } - private static bool ConvertToNullableDateTimeOffsetCore(object obj, CultureInfo culture, string format, out DateTimeOffset? value) + private static bool ConvertToNullableDateTimeOffsetCore(object? obj, CultureInfo? culture, string? format, out DateTimeOffset? value) { - var text = (string)obj; + var text = (string?)obj; if (string.IsNullOrEmpty(text)) { value = default; @@ -1194,9 +1195,9 @@ namespace Microsoft.AspNetCore.Components return false; } - private static bool ConvertToEnum(object obj, CultureInfo culture, out T value) where T : struct, Enum + private static bool ConvertToEnum(object? obj, CultureInfo? culture, out T value) where T : struct, Enum { - var text = (string)obj; + var text = (string?)obj; if (string.IsNullOrEmpty(text)) { value = default; @@ -1219,9 +1220,9 @@ namespace Microsoft.AspNetCore.Components return true; } - private static bool ConvertToNullableEnum(object obj, CultureInfo culture, out T? value) where T : struct, Enum + private static bool ConvertToNullableEnum(object? obj, CultureInfo? culture, out T? value) where T : struct, Enum { - var text = (string)obj; + var text = (string?)obj; if (string.IsNullOrEmpty(text)) { value = default; @@ -1251,7 +1252,7 @@ namespace Microsoft.AspNetCore.Components /// The to use for conversion. /// The converted value. /// true if conversion is successful, otherwise false. - public static bool TryConvertTo(object obj, CultureInfo culture, out T value) + public static bool TryConvertTo(object? obj, CultureInfo? culture, out T value) { var converter = ParserDelegateCache.Get(); return converter(obj, culture, out value); @@ -1261,8 +1262,8 @@ namespace Microsoft.AspNetCore.Components { private readonly static ConcurrentDictionary _cache = new ConcurrentDictionary(); - private static MethodInfo _formatEnumValue; - private static MethodInfo _formatNullableEnumValue; + private static MethodInfo? _formatEnumValue; + private static MethodInfo? _formatNullableEnumValue; public static BindFormatter Get() { @@ -1349,13 +1350,13 @@ namespace Microsoft.AspNetCore.Components else if (typeof(T).IsEnum) { // We have to deal invoke this dynamically to work around the type constraint on Enum.TryParse. - var method = _formatEnumValue ??= typeof(BindConverter).GetMethod(nameof(FormatEnumValueCore), BindingFlags.NonPublic | BindingFlags.Static); + var method = _formatEnumValue ??= typeof(BindConverter).GetMethod(nameof(FormatEnumValueCore), BindingFlags.NonPublic | BindingFlags.Static)!; formatter = method.MakeGenericMethod(typeof(T)).CreateDelegate(typeof(BindFormatter), target: null); } else if (Nullable.GetUnderlyingType(typeof(T)) is Type innerType && innerType.IsEnum) { // We have to deal invoke this dynamically to work around the type constraint on Enum.TryParse. - var method = _formatNullableEnumValue ??= typeof(BindConverter).GetMethod(nameof(FormatNullableEnumValueCore), BindingFlags.NonPublic | BindingFlags.Static); + var method = _formatNullableEnumValue ??= typeof(BindConverter).GetMethod(nameof(FormatNullableEnumValueCore), BindingFlags.NonPublic | BindingFlags.Static)!; formatter = method.MakeGenericMethod(innerType).CreateDelegate(typeof(BindFormatter), target: null); } else @@ -1382,7 +1383,7 @@ namespace Microsoft.AspNetCore.Components return FormatWithTypeConverter; - string FormatWithTypeConverter(T value, CultureInfo culture) + string FormatWithTypeConverter(T value, CultureInfo? culture) { // We intentionally close-over the TypeConverter to cache it. The TypeDescriptor infrastructure is slow. return typeConverter.ConvertToString(context: null, culture ?? CultureInfo.CurrentCulture, value); @@ -1394,8 +1395,8 @@ namespace Microsoft.AspNetCore.Components { private readonly static ConcurrentDictionary _cache = new ConcurrentDictionary(); - private static MethodInfo _convertToEnum; - private static MethodInfo _convertToNullableEnum; + private static MethodInfo? _convertToEnum; + private static MethodInfo? _convertToNullableEnum; public static BindParser Get() { @@ -1482,13 +1483,13 @@ namespace Microsoft.AspNetCore.Components else if (typeof(T).IsEnum) { // We have to deal invoke this dynamically to work around the type constraint on Enum.TryParse. - var method = _convertToEnum ??= typeof(BindConverter).GetMethod(nameof(ConvertToEnum), BindingFlags.NonPublic | BindingFlags.Static); + var method = _convertToEnum ??= typeof(BindConverter).GetMethod(nameof(ConvertToEnum), BindingFlags.NonPublic | BindingFlags.Static)!; parser = method.MakeGenericMethod(typeof(T)).CreateDelegate(typeof(BindParser), target: null); } else if (Nullable.GetUnderlyingType(typeof(T)) is Type innerType && innerType.IsEnum) { // We have to deal invoke this dynamically to work around the type constraint on Enum.TryParse. - var method = _convertToNullableEnum ??= typeof(BindConverter).GetMethod(nameof(ConvertToNullableEnum), BindingFlags.NonPublic | BindingFlags.Static); + var method = _convertToNullableEnum ??= typeof(BindConverter).GetMethod(nameof(ConvertToNullableEnum), BindingFlags.NonPublic | BindingFlags.Static)!; parser = method.MakeGenericMethod(innerType).CreateDelegate(typeof(BindParser), target: null); } else @@ -1515,13 +1516,13 @@ namespace Microsoft.AspNetCore.Components return ConvertWithTypeConverter; - bool ConvertWithTypeConverter(object obj, CultureInfo culture, out T value) + bool ConvertWithTypeConverter(object? obj, CultureInfo? culture, out T value) { // We intentionally close-over the TypeConverter to cache it. The TypeDescriptor infrastructure is slow. var converted = typeConverter.ConvertFrom(context: null, culture ?? CultureInfo.CurrentCulture, obj); if (converted == null) { - value = default; + value = default!; return true; } diff --git a/src/Components/Components/src/BindElementAttribute.cs b/src/Components/Components/src/BindElementAttribute.cs index 4907b3e27e..1b48ee9408 100644 --- a/src/Components/Components/src/BindElementAttribute.cs +++ b/src/Components/Components/src/BindElementAttribute.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Components /// The suffix value. For example, set this to value for bind-value, or set this to for bind. /// The name of the value attribute to be bound. /// The name of an attribute that will register an associated change event. - public BindElementAttribute(string element, string suffix, string valueAttribute, string changeAttribute) + public BindElementAttribute(string element, string? suffix, string valueAttribute, string changeAttribute) { if (element == null) { @@ -38,6 +38,7 @@ namespace Microsoft.AspNetCore.Components Element = element; ValueAttribute = valueAttribute; ChangeAttribute = changeAttribute; + Suffix = suffix; } /// @@ -49,7 +50,7 @@ namespace Microsoft.AspNetCore.Components /// Gets the suffix value. /// For example, this will be value to mean bind-value, or to mean bind. /// - public string Suffix { get; } + public string? Suffix { get; } /// /// Gets the name of the value attribute to be bound. diff --git a/src/Components/Components/src/CascadingParameterAttribute.cs b/src/Components/Components/src/CascadingParameterAttribute.cs index ca8113976b..8e106b404c 100644 --- a/src/Components/Components/src/CascadingParameterAttribute.cs +++ b/src/Components/Components/src/CascadingParameterAttribute.cs @@ -22,6 +22,6 @@ namespace Microsoft.AspNetCore.Components /// that supplies a value with a compatible /// type. /// - public string Name { get; set; } + public string? Name { get; set; } } } diff --git a/src/Components/Components/src/CascadingParameterState.cs b/src/Components/Components/src/CascadingParameterState.cs index 8c3e445a86..6ae1783818 100644 --- a/src/Components/Components/src/CascadingParameterState.cs +++ b/src/Components/Components/src/CascadingParameterState.cs @@ -30,14 +30,14 @@ namespace Microsoft.AspNetCore.Components var infos = GetReflectedCascadingParameterInfos(componentType); // For components known not to have any cascading parameters, bail out early - if (infos == null) + if (infos.Length == 0) { - return null; + return Array.Empty(); } // Now try to find matches for each of the cascading parameters // Defer instantiation of the result list until we know there's at least one - List resultStates = null; + List? resultStates = null; var numInfos = infos.Length; for (var infoIndex = 0; infoIndex < numInfos; infoIndex++) @@ -56,10 +56,10 @@ namespace Microsoft.AspNetCore.Components } } - return resultStates; + return resultStates ?? (IReadOnlyList)Array.Empty(); } - private static ICascadingValueComponent GetMatchingCascadingValueSupplier(in ReflectedCascadingParameterInfo info, ComponentState componentState) + private static ICascadingValueComponent? GetMatchingCascadingValueSupplier(in ReflectedCascadingParameterInfo info, ComponentState componentState) { do { @@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Components private static ReflectedCascadingParameterInfo[] CreateReflectedCascadingParameterInfos(Type componentType) { - List result = null; + List? result = null; var candidateProps = ComponentProperties.GetCandidateBindableProperties(componentType); foreach (var prop in candidateProps) { @@ -108,17 +108,17 @@ namespace Microsoft.AspNetCore.Components } } - return result?.ToArray(); + return result?.ToArray() ?? Array.Empty(); } readonly struct ReflectedCascadingParameterInfo { public string ConsumerValueName { get; } - public string SupplierValueName { get; } + public string? SupplierValueName { get; } public Type ValueType { get; } public ReflectedCascadingParameterInfo( - string consumerValueName, Type valueType, string supplierValueName) + string consumerValueName, Type valueType, string? supplierValueName) { ConsumerValueName = consumerValueName; SupplierValueName = supplierValueName; diff --git a/src/Components/Components/src/CascadingValue.cs b/src/Components/Components/src/CascadingValue.cs index 605d24134d..39998adc11 100644 --- a/src/Components/Components/src/CascadingValue.cs +++ b/src/Components/Components/src/CascadingValue.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable warnings + using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -34,7 +36,7 @@ namespace Microsoft.AspNetCore.Components /// If no name is specified, then descendant components will receive the /// value based the type of value they are requesting. /// - [Parameter] public string Name { get; set; } + [Parameter] public string? Name { get; set; } /// /// If true, indicates that will not change. This is a diff --git a/src/Components/Components/src/ChangeDetection.cs b/src/Components/Components/src/ChangeDetection.cs index 9a0a1620be..3b4da57392 100644 --- a/src/Components/Components/src/ChangeDetection.cs +++ b/src/Components/Components/src/ChangeDetection.cs @@ -17,8 +17,8 @@ namespace Microsoft.AspNetCore.Components } else if (oldIsNotNull) // i.e., both are not null (considering previous check) { - var oldValueType = oldValue.GetType(); - var newValueType = newValue.GetType(); + var oldValueType = oldValue!.GetType(); + var newValueType = newValue!.GetType(); if (oldValueType != newValueType // Definitely different || !IsKnownImmutableType(oldValueType) // Maybe different || !oldValue.Equals(newValue)) // Somebody says they are different diff --git a/src/Components/Components/src/ChangeEventArgs.cs b/src/Components/Components/src/ChangeEventArgs.cs index e64e4c10c7..744c66429a 100644 --- a/src/Components/Components/src/ChangeEventArgs.cs +++ b/src/Components/Components/src/ChangeEventArgs.cs @@ -13,7 +13,6 @@ namespace Microsoft.AspNetCore.Components /// /// Gets or sets the new value. /// - public object Value { get; set; } - + public object? Value { get; set; } } } diff --git a/src/Components/Components/src/ComponentBase.cs b/src/Components/Components/src/ComponentBase.cs index e8f2a5ac88..dd80af0fd3 100644 --- a/src/Components/Components/src/ComponentBase.cs +++ b/src/Components/Components/src/ComponentBase.cs @@ -301,7 +301,7 @@ namespace Microsoft.AspNetCore.Components StateHasChanged(); } - Task IHandleEvent.HandleEventAsync(EventCallbackWorkItem callback, object arg) + Task IHandleEvent.HandleEventAsync(EventCallbackWorkItem callback, object? arg) { var task = callback.InvokeAsync(arg); var shouldAwaitTask = task.Status != TaskStatus.RanToCompletion && diff --git a/src/Components/Components/src/Dispatcher.cs b/src/Components/Components/src/Dispatcher.cs index 88ba020813..c294d27601 100644 --- a/src/Components/Components/src/Dispatcher.cs +++ b/src/Components/Components/src/Dispatcher.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Components /// /// Provides notifications of unhandled exceptions that occur within the dispatcher. /// - internal event UnhandledExceptionEventHandler UnhandledException; + internal event UnhandledExceptionEventHandler? UnhandledException; /// /// Validates that the currently executing code is running inside the dispatcher. diff --git a/src/Components/Components/src/EventCallback.cs b/src/Components/Components/src/EventCallback.cs index 3ba05ceaba..0acc823124 100644 --- a/src/Components/Components/src/EventCallback.cs +++ b/src/Components/Components/src/EventCallback.cs @@ -21,15 +21,15 @@ namespace Microsoft.AspNetCore.Components /// public static readonly EventCallback Empty = new EventCallback(null, (Action)(() => { })); - internal readonly MulticastDelegate Delegate; - internal readonly IHandleEvent Receiver; + internal readonly MulticastDelegate? Delegate; + internal readonly IHandleEvent? Receiver; /// /// Creates the new . /// /// The event receiver. /// The delegate to bind. - public EventCallback(IHandleEvent receiver, MulticastDelegate @delegate) + public EventCallback(IHandleEvent? receiver, MulticastDelegate? @delegate) { Receiver = receiver; Delegate = @delegate; @@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Components return Receiver.HandleEventAsync(new EventCallbackWorkItem(Delegate), arg); } - object IEventCallback.UnpackForRenderTree() + object? IEventCallback.UnpackForRenderTree() { return RequiresExplicitReceiver ? (object)this : Delegate; } diff --git a/src/Components/Components/src/EventCallbackFactoryBinderExtensions.cs b/src/Components/Components/src/EventCallbackFactoryBinderExtensions.cs index 0305c1b469..ac868f3ac6 100644 --- a/src/Components/Components/src/EventCallbackFactoryBinderExtensions.cs +++ b/src/Components/Components/src/EventCallbackFactoryBinderExtensions.cs @@ -34,11 +34,11 @@ namespace Microsoft.AspNetCore.Components public static EventCallback CreateBinder( this EventCallbackFactory factory, object receiver, - Action setter, + Action setter, string existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { - return CreateBinderCore(factory, receiver, setter, culture, ConvertToString); + return CreateBinderCore(factory, receiver, setter, culture, ConvertToString); } /// @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, bool existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ConvertToBool); } @@ -74,7 +74,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, bool? existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ConvertToNullableBool); } @@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, int existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ConvertToInt); } @@ -112,7 +112,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, int? existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ConvertToNullableInt); } @@ -131,7 +131,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, long existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ConvertToLong); } @@ -150,7 +150,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, short existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ConvertToShort); } @@ -169,7 +169,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, long? existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ConvertToNullableLong); } @@ -188,7 +188,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, short? existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ConvertToNullableShort); } @@ -207,7 +207,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, float existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ConvertToFloat); } @@ -226,7 +226,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, float? existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ConvertToNullableFloat); } @@ -245,7 +245,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, double existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ConvertToDoubleDelegate); } @@ -264,7 +264,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, double? existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ConvertToNullableDoubleDelegate); } @@ -283,7 +283,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, decimal existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ConvertToDecimal); } @@ -302,7 +302,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, decimal? existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ConvertToNullableDecimal); } @@ -321,7 +321,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, DateTime existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ConvertToDateTime); } @@ -342,7 +342,7 @@ namespace Microsoft.AspNetCore.Components Action setter, DateTime existingValue, string format, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, format, ConvertToDateTimeWithFormat); } @@ -361,7 +361,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, DateTime? existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ConvertToNullableDateTime); } @@ -382,7 +382,7 @@ namespace Microsoft.AspNetCore.Components Action setter, DateTime? existingValue, string format, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, format, ConvertToNullableDateTimeWithFormat); } @@ -401,7 +401,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, DateTimeOffset existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ConvertToDateTimeOffset); } @@ -422,7 +422,7 @@ namespace Microsoft.AspNetCore.Components Action setter, DateTimeOffset existingValue, string format, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, format, ConvertToDateTimeOffsetWithFormat); } @@ -441,7 +441,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, DateTimeOffset? existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ConvertToNullableDateTimeOffset); } @@ -462,7 +462,7 @@ namespace Microsoft.AspNetCore.Components Action setter, DateTimeOffset? existingValue, string format, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, format, ConvertToNullableDateTimeOffsetWithFormat); } @@ -482,7 +482,7 @@ namespace Microsoft.AspNetCore.Components object receiver, Action setter, T existingValue, - CultureInfo culture = null) + CultureInfo? culture = null) { return CreateBinderCore(factory, receiver, setter, culture, ParserDelegateCache.Get()); } @@ -491,7 +491,7 @@ namespace Microsoft.AspNetCore.Components this EventCallbackFactory factory, object receiver, Action setter, - CultureInfo culture, + CultureInfo? culture, BindConverter.BindParser converter) { Action callback = e => @@ -520,11 +520,11 @@ namespace Microsoft.AspNetCore.Components // know that the data they are submitting is different from what they think they've typed if (converted) { - setter(value); + setter(value!); } else if (string.Empty.Equals(e.Value)) { - setter(default); + setter(default!); } }; return factory.Create(receiver, callback); @@ -534,7 +534,7 @@ namespace Microsoft.AspNetCore.Components this EventCallbackFactory factory, object receiver, Action setter, - CultureInfo culture, + CultureInfo? culture, string format, BindConverter.BindParserWithFormat converter) { @@ -564,11 +564,11 @@ namespace Microsoft.AspNetCore.Components // know that the data they are submitting is different from what they think they've typed if (converted) { - setter(value); + setter(value!); } else if (string.Empty.Equals(e.Value)) { - setter(default); + setter(default!); } }; return factory.Create(receiver, callback); diff --git a/src/Components/Components/src/EventCallbackOfT.cs b/src/Components/Components/src/EventCallbackOfT.cs index 918d8d62e2..12072171fa 100644 --- a/src/Components/Components/src/EventCallbackOfT.cs +++ b/src/Components/Components/src/EventCallbackOfT.cs @@ -16,15 +16,15 @@ namespace Microsoft.AspNetCore.Components /// public static readonly EventCallback Empty = new EventCallback(null, (Action)(() => { })); - internal readonly MulticastDelegate Delegate; - internal readonly IHandleEvent Receiver; + internal readonly MulticastDelegate? Delegate; + internal readonly IHandleEvent? Receiver; /// /// Creates the new . /// /// The event receiver. /// The delegate to bind. - public EventCallback(IHandleEvent receiver, MulticastDelegate @delegate) + public EventCallback(IHandleEvent? receiver, MulticastDelegate? @delegate) { Receiver = receiver; Delegate = @delegate; @@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Components return new EventCallback(Receiver ?? Delegate?.Target as IHandleEvent, Delegate); } - object IEventCallback.UnpackForRenderTree() + object? IEventCallback.UnpackForRenderTree() { return RequiresExplicitReceiver ? (object)AsUntyped() : Delegate; } diff --git a/src/Components/Components/src/EventCallbackWorkItem.cs b/src/Components/Components/src/EventCallbackWorkItem.cs index bb7c8320b2..8382f8daeb 100644 --- a/src/Components/Components/src/EventCallbackWorkItem.cs +++ b/src/Components/Components/src/EventCallbackWorkItem.cs @@ -17,13 +17,13 @@ namespace Microsoft.AspNetCore.Components /// public static readonly EventCallbackWorkItem Empty = new EventCallbackWorkItem(null); - private readonly MulticastDelegate _delegate; + private readonly MulticastDelegate? _delegate; /// /// Creates a new with the provided . /// /// The callback delegate. - public EventCallbackWorkItem(MulticastDelegate @delegate) + public EventCallbackWorkItem(MulticastDelegate? @delegate) { _delegate = @delegate; } @@ -33,12 +33,12 @@ namespace Microsoft.AspNetCore.Components /// /// The argument to provide to the delegate. May be null. /// A then will complete asynchronously once the delegate has completed. - public Task InvokeAsync(object arg) + public Task InvokeAsync(object? arg) { - return InvokeAsync(_delegate, arg); + return InvokeAsync(_delegate, arg); } - internal static Task InvokeAsync(MulticastDelegate @delegate, T arg) + internal static Task InvokeAsync(MulticastDelegate? @delegate, T arg) { switch (@delegate) { @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Components // Since we fell into the DynamicInvoke case, any exception will be wrapped // in a TIE. We can expect this to be thrown synchronously, so it's low overhead // to unwrap it. - return Task.FromException(e.InnerException); + return Task.FromException(e.InnerException!); } } } diff --git a/src/Components/Components/src/ICascadingValueComponent.cs b/src/Components/Components/src/ICascadingValueComponent.cs index de9da715a2..258116bd4c 100644 --- a/src/Components/Components/src/ICascadingValueComponent.cs +++ b/src/Components/Components/src/ICascadingValueComponent.cs @@ -11,9 +11,9 @@ namespace Microsoft.AspNetCore.Components // This interface exists only so that CascadingParameterState has a way // to work with all CascadingValue types regardless of T. - bool CanSupplyValue(Type valueType, string valueName); + bool CanSupplyValue(Type valueType, string? valueName); - object CurrentValue { get; } + object? CurrentValue { get; } bool CurrentValueIsFixed { get; } diff --git a/src/Components/Components/src/IEventCallback.cs b/src/Components/Components/src/IEventCallback.cs index 6c9fcac7a3..c95f76734c 100644 --- a/src/Components/Components/src/IEventCallback.cs +++ b/src/Components/Components/src/IEventCallback.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace Microsoft.AspNetCore.Components @@ -8,6 +8,6 @@ namespace Microsoft.AspNetCore.Components { bool HasDelegate { get; } - object UnpackForRenderTree(); + object? UnpackForRenderTree(); } } diff --git a/src/Components/Components/src/IHandleEvent.cs b/src/Components/Components/src/IHandleEvent.cs index 478102cbe8..61912ca6ce 100644 --- a/src/Components/Components/src/IHandleEvent.cs +++ b/src/Components/Components/src/IHandleEvent.cs @@ -18,6 +18,6 @@ namespace Microsoft.AspNetCore.Components /// /// A that completes once the component has processed the state change. /// - Task HandleEventAsync(EventCallbackWorkItem item, object arg); + Task HandleEventAsync(EventCallbackWorkItem item, object? arg); } } diff --git a/src/Components/Components/src/LayoutComponentBase.cs b/src/Components/Components/src/LayoutComponentBase.cs index 776b97b280..4b7c216cf2 100644 --- a/src/Components/Components/src/LayoutComponentBase.cs +++ b/src/Components/Components/src/LayoutComponentBase.cs @@ -16,6 +16,6 @@ namespace Microsoft.AspNetCore.Components /// Gets the content to be rendered inside the layout. /// [Parameter] - public RenderFragment Body { get; set; } + public RenderFragment? Body { get; set; } } } diff --git a/src/Components/Components/src/LayoutView.cs b/src/Components/Components/src/LayoutView.cs index 7b88d181f0..d705649471 100644 --- a/src/Components/Components/src/LayoutView.cs +++ b/src/Components/Components/src/LayoutView.cs @@ -21,14 +21,14 @@ namespace Microsoft.AspNetCore.Components /// Gets or sets the content to display. /// [Parameter] - public RenderFragment ChildContent { get; set; } + public RenderFragment ChildContent { get; set; } = default!; /// /// Gets or sets the type of the layout in which to display the content. /// The type must implement and accept a parameter named . /// [Parameter] - public Type Layout { get; set; } + public Type Layout { get; set; } = default!; /// public void Attach(RenderHandle renderHandle) @@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Components }; } - private static Type GetParentLayoutType(Type type) + private static Type? GetParentLayoutType(Type type) => type.GetCustomAttribute()?.LayoutType; } } diff --git a/src/Components/Components/src/Microsoft.AspNetCore.Components.csproj b/src/Components/Components/src/Microsoft.AspNetCore.Components.csproj index 2f1841b906..30e1ef833a 100644 --- a/src/Components/Components/src/Microsoft.AspNetCore.Components.csproj +++ b/src/Components/Components/src/Microsoft.AspNetCore.Components.csproj @@ -6,6 +6,7 @@ Components feature for ASP.NET Core. true true + enable diff --git a/src/Components/Components/src/NavigationManager.cs b/src/Components/Components/src/NavigationManager.cs index 0ad565fb54..e5752e669a 100644 --- a/src/Components/Components/src/NavigationManager.cs +++ b/src/Components/Components/src/NavigationManager.cs @@ -28,14 +28,14 @@ namespace Microsoft.AspNetCore.Components } } - private EventHandler _locationChanged; + private EventHandler? _locationChanged; // For the baseUri it's worth storing as a System.Uri so we can do operations // on that type. System.Uri gives us access to the original string anyway. - private Uri _baseUri; + private Uri? _baseUri; // The URI. Always represented an absolute URI. - private string _uri; + private string? _uri; private bool _isInitialized; @@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Components get { AssertInitialized(); - return _baseUri.OriginalString; + return _baseUri!.OriginalString; } protected set { @@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Components value = NormalizeBaseUri(value); } - _baseUri = new Uri(value, UriKind.Absolute); + _baseUri = new Uri(value!, UriKind.Absolute); } } @@ -75,7 +75,7 @@ namespace Microsoft.AspNetCore.Components get { AssertInitialized(); - return _uri; + return _uri!; } protected set { @@ -150,7 +150,7 @@ namespace Microsoft.AspNetCore.Components public Uri ToAbsoluteUri(string relativeUri) { AssertInitialized(); - return new Uri(_baseUri, relativeUri); + return new Uri(_baseUri!, relativeUri); } /// @@ -161,7 +161,7 @@ namespace Microsoft.AspNetCore.Components /// A relative URI path. public string ToBaseRelativePath(string uri) { - if (uri.StartsWith(_baseUri.OriginalString, StringComparison.Ordinal)) + if (uri.StartsWith(_baseUri!.OriginalString, StringComparison.Ordinal)) { // The absolute URI must be of the form "{baseUri}something" (where // baseUri ends with a slash), and from that we return "something" @@ -203,7 +203,7 @@ namespace Microsoft.AspNetCore.Components { try { - _locationChanged?.Invoke(this, new LocationChangedEventArgs(_uri, isInterceptedLink)); + _locationChanged?.Invoke(this, new LocationChangedEventArgs(_uri!, isInterceptedLink)); } catch (Exception ex) { @@ -252,7 +252,7 @@ namespace Microsoft.AspNetCore.Components return false; } - private static void Validate(Uri baseUri, string uri) + private static void Validate(Uri? baseUri, string uri) { if (baseUri == null || uri == null) { diff --git a/src/Components/Components/src/OwningComponentBase.cs b/src/Components/Components/src/OwningComponentBase.cs index d5bcecb1f7..47c4b361f4 100644 --- a/src/Components/Components/src/OwningComponentBase.cs +++ b/src/Components/Components/src/OwningComponentBase.cs @@ -17,9 +17,9 @@ namespace Microsoft.AspNetCore.Components /// public abstract class OwningComponentBase : ComponentBase, IDisposable { - private IServiceScope _scope; + private IServiceScope? _scope; - [Inject] IServiceScopeFactory ScopeFactory { get; set; } + [Inject] IServiceScopeFactory ScopeFactory { get; set; } = default!; /// /// Gets a value determining if the component and associated services have been disposed. @@ -75,9 +75,9 @@ namespace Microsoft.AspNetCore.Components /// requires disposal such as a repository or database abstraction. Using /// as a base class ensures that the service and relates services that share its scope are disposed with the component. /// - public abstract class OwningComponentBase : OwningComponentBase, IDisposable + public abstract class OwningComponentBase : OwningComponentBase, IDisposable where TService : notnull { - private TService _item; + private TService _item = default!; /// /// Gets the that is associated with this component. diff --git a/src/Components/Components/src/ParameterView.cs b/src/Components/Components/src/ParameterView.cs index 33f87a5062..569b8ff2c2 100644 --- a/src/Components/Components/src/ParameterView.cs +++ b/src/Components/Components/src/ParameterView.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore.Components.Reflection; using Microsoft.AspNetCore.Components.Rendering; using Microsoft.AspNetCore.Components.RenderTree; @@ -21,24 +22,24 @@ namespace Microsoft.AspNetCore.Components RenderTreeFrame.Element(0, string.Empty).WithComponentSubtreeLength(1) }; - private static readonly ParameterView _empty = new ParameterView(ParameterViewLifetime.Unbound, _emptyFrames, 0, null); + private static readonly ParameterView _empty = new ParameterView(ParameterViewLifetime.Unbound, _emptyFrames, 0, Array.Empty()); private readonly ParameterViewLifetime _lifetime; private readonly RenderTreeFrame[] _frames; private readonly int _ownerIndex; - private readonly IReadOnlyList _cascadingParametersOrNull; + private readonly IReadOnlyList _cascadingParameters; internal ParameterView(in ParameterViewLifetime lifetime, RenderTreeFrame[] frames, int ownerIndex) - : this(lifetime, frames, ownerIndex, null) + : this(lifetime, frames, ownerIndex, Array.Empty()) { } - private ParameterView(in ParameterViewLifetime lifetime, RenderTreeFrame[] frames, int ownerIndex, IReadOnlyList cascadingParametersOrNull) + private ParameterView(in ParameterViewLifetime lifetime, RenderTreeFrame[] frames, int ownerIndex, IReadOnlyList cascadingParameters) { _lifetime = lifetime; _frames = frames; _ownerIndex = ownerIndex; - _cascadingParametersOrNull = cascadingParametersOrNull; + _cascadingParameters = cascadingParameters; } /// @@ -55,7 +56,7 @@ namespace Microsoft.AspNetCore.Components public Enumerator GetEnumerator() { _lifetime.AssertNotExpired(); - return new Enumerator(_frames, _ownerIndex, _cascadingParametersOrNull); + return new Enumerator(_frames, _ownerIndex, _cascadingParameters); } /// @@ -65,7 +66,7 @@ namespace Microsoft.AspNetCore.Components /// The name of the parameter. /// Receives the result, if any. /// True if a matching parameter was found; false otherwise. - public bool TryGetValue(string parameterName, out TValue result) + public bool TryGetValue(string parameterName, [MaybeNullWhen(false)] out TValue result) { foreach (var entry in this) { @@ -87,8 +88,9 @@ namespace Microsoft.AspNetCore.Components /// The type of the value. /// The name of the parameter. /// The parameter value if found; otherwise the default value for the specified type. + [return: MaybeNull] public TValue GetValueOrDefault(string parameterName) - => GetValueOrDefault(parameterName, default); + => GetValueOrDefault(parameterName, default!); /// /// Gets the value of the parameter with the specified name, or a specified default value @@ -350,19 +352,13 @@ namespace Microsoft.AspNetCore.Components public bool MoveNext() { - // Bail out early if there are no cascading parameters - if (_cascadingParameters == null) - { - return false; - } - var nextIndex = _currentIndex + 1; if (nextIndex < _cascadingParameters.Count) { _currentIndex = nextIndex; var state = _cascadingParameters[_currentIndex]; - _current = new ParameterValue(state.LocalValueName, state.ValueSupplier.CurrentValue, true); + _current = new ParameterValue(state.LocalValueName, state.ValueSupplier.CurrentValue!, true); return true; } else diff --git a/src/Components/Components/src/Reflection/ComponentProperties.cs b/src/Components/Components/src/Reflection/ComponentProperties.cs index 0b85a66a84..e47c53eeb9 100644 --- a/src/Components/Components/src/Reflection/ComponentProperties.cs +++ b/src/Components/Components/src/Reflection/ComponentProperties.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; @@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Components.Reflection { // Logic with components with a CaptureUnmatchedValues parameter var isCaptureUnmatchedValuesParameterSetExplicitly = false; - Dictionary unmatched = null; + Dictionary? unmatched = null; foreach (var parameter in parameters) { var parameterName = parameter.Name; @@ -82,33 +82,47 @@ namespace Microsoft.AspNetCore.Components.Reflection isCaptureUnmatchedValuesParameterSetExplicitly = true; } - var isUnmatchedValue = !writers.WritersByName.TryGetValue(parameterName, out var writer); - - if ((isUnmatchedValue && parameter.Cascading) || (writer != null && !writer.Cascading && parameter.Cascading)) + if (writers.WritersByName.TryGetValue(parameterName, out var writer)) { - // Don't allow an "extra" cascading value to be collected - or don't allow a non-cascading - // parameter to be set with a cascading value. - // - // This is likely a bug in our infrastructure or an attempt to deliberately do something unsupported. - ThrowForSettingParameterWithCascadingValue(targetType, parameterName); - throw null; // Unreachable - - } - else if (isUnmatchedValue || - - // Allow unmatched parameters to collide with the names of cascading parameters. This is - // valid because cascading parameter names are not part of the public API. There's no - // way for the user of a component to know what the names of cascading parameters - // are. - (writer.Cascading && !parameter.Cascading)) - { - unmatched ??= new Dictionary(StringComparer.OrdinalIgnoreCase); - unmatched[parameterName] = parameter.Value; + if (!writer.Cascading && parameter.Cascading) + { + // Don't allow an "extra" cascading value to be collected - or don't allow a non-cascading + // parameter to be set with a cascading value. + // + // This is likely a bug in our infrastructure or an attempt to deliberately do something unsupported. + ThrowForSettingParameterWithCascadingValue(targetType, parameterName); + throw null; // Unreachable + } + else if (writer.Cascading && !parameter.Cascading) + { + // Allow unmatched parameters to collide with the names of cascading parameters. This is + // valid because cascading parameter names are not part of the public API. There's no + // way for the user of a component to know what the names of cascading parameters + // are. + unmatched ??= new Dictionary(StringComparer.OrdinalIgnoreCase); + unmatched[parameterName] = parameter.Value; + } + else + { + SetProperty(target, writer, parameterName, parameter.Value); + } } else { - Debug.Assert(writer != null); - SetProperty(target, writer, parameterName, parameter.Value); + if (parameter.Cascading) + { + // Don't allow an "extra" cascading value to be collected - or don't allow a non-cascading + // parameter to be set with a cascading value. + // + // This is likely a bug in our infrastructure or an attempt to deliberately do something unsupported. + ThrowForSettingParameterWithCascadingValue(targetType, parameterName); + throw null; // Unreachable + } + else + { + unmatched ??= new Dictionary(StringComparer.OrdinalIgnoreCase); + unmatched[parameterName] = parameter.Value; + } } } @@ -120,13 +134,13 @@ namespace Microsoft.AspNetCore.Components.Reflection // 2. We also don't want to implicitly copy a value the user gives us. // // Either one of those implementation choices would do something unexpected. - ThrowForCaptureUnmatchedValuesConflict(targetType, writers.CaptureUnmatchedValuesPropertyName, unmatched); + ThrowForCaptureUnmatchedValuesConflict(targetType, writers.CaptureUnmatchedValuesPropertyName!, unmatched); throw null; // Unreachable } else if (unmatched != null) { // We had some unmatched values, set the CaptureUnmatchedValues property - SetProperty(target, writers.CaptureUnmatchedValuesWriter, writers.CaptureUnmatchedValuesPropertyName, unmatched); + SetProperty(target, writers.CaptureUnmatchedValuesWriter, writers.CaptureUnmatchedValuesPropertyName!, unmatched); } } @@ -148,6 +162,7 @@ namespace Microsoft.AspNetCore.Components.Reflection internal static IEnumerable GetCandidateBindableProperties(Type targetType) => MemberAssignment.GetPropertiesIncludingInherited(targetType, _bindablePropertyFlags); + [DoesNotReturn] private static void ThrowForUnknownIncomingParameterName(Type targetType, string parameterName) { // We know we're going to throw by this stage, so it doesn't matter that the following @@ -176,6 +191,7 @@ namespace Microsoft.AspNetCore.Components.Reflection } } + [DoesNotReturn] private static void ThrowForSettingCascadingParameterWithNonCascadingValue(Type targetType, string parameterName) { throw new InvalidOperationException( @@ -183,6 +199,7 @@ namespace Microsoft.AspNetCore.Components.Reflection $"but it does not have [{nameof(ParameterAttribute)}] applied."); } + [DoesNotReturn] private static void ThrowForSettingParameterWithCascadingValue(Type targetType, string parameterName) { throw new InvalidOperationException( @@ -190,6 +207,7 @@ namespace Microsoft.AspNetCore.Components.Reflection $"using a cascading value."); } + [DoesNotReturn] private static void ThrowForCaptureUnmatchedValuesConflict(Type targetType, string parameterName, Dictionary unmatched) { throw new InvalidOperationException( @@ -198,6 +216,7 @@ namespace Microsoft.AspNetCore.Components.Reflection string.Join(Environment.NewLine, unmatched.Keys.OrderBy(k => k))); } + [DoesNotReturn] private static void ThrowForMultipleCaptureUnmatchedValuesParameters(Type targetType) { // We don't care about perf here, we want to report an accurate and useful error. @@ -215,6 +234,7 @@ namespace Microsoft.AspNetCore.Components.Reflection string.Join(Environment.NewLine, propertyNames)); } + [DoesNotReturn] private static void ThrowForInvalidCaptureUnmatchedValuesParameterType(Type targetType, PropertyInfo propertyInfo) { throw new InvalidOperationException( @@ -280,9 +300,9 @@ namespace Microsoft.AspNetCore.Components.Reflection public Dictionary WritersByName { get; } - public IPropertySetter CaptureUnmatchedValuesWriter { get; } + public IPropertySetter? CaptureUnmatchedValuesWriter { get; } - public string CaptureUnmatchedValuesPropertyName { get; } + public string? CaptureUnmatchedValuesPropertyName { get; } } } } diff --git a/src/Components/Components/src/Reflection/MemberAssignment.cs b/src/Components/Components/src/Reflection/MemberAssignment.cs index ab0cf6b1e7..4510d4e81c 100644 --- a/src/Components/Components/src/Reflection/MemberAssignment.cs +++ b/src/Components/Components/src/Reflection/MemberAssignment.cs @@ -15,10 +15,12 @@ namespace Microsoft.AspNetCore.Components.Reflection { var dictionary = new Dictionary>(); - while (type != null) + Type? currentType = type; + + while (currentType != null) { - var properties = type.GetProperties(bindingFlags) - .Where(prop => prop.DeclaringType == type); + var properties = currentType.GetProperties(bindingFlags) + .Where(prop => prop.DeclaringType == currentType); foreach (var property in properties) { if (!dictionary.TryGetValue(property.Name, out var others)) @@ -37,7 +39,7 @@ namespace Microsoft.AspNetCore.Components.Reflection others.Add(property); } - type = type.BaseType; + currentType = currentType.BaseType; } return dictionary.Values.SelectMany(p => p); @@ -55,10 +57,10 @@ namespace Microsoft.AspNetCore.Components.Reflection return (IPropertySetter)Activator.CreateInstance( typeof(PropertySetter<,>).MakeGenericType(targetType, property.PropertyType), property.SetMethod, - cascading); + cascading)!; } - class PropertySetter : IPropertySetter + class PropertySetter : IPropertySetter where TTarget : notnull { private readonly Action _setterDelegate; @@ -75,7 +77,7 @@ namespace Microsoft.AspNetCore.Components.Reflection { if (value == null) { - _setterDelegate((TTarget)target, default); + _setterDelegate((TTarget)target, default!); } else { diff --git a/src/Components/Components/src/RenderHandle.cs b/src/Components/Components/src/RenderHandle.cs index fb646feeee..d6f3f986f5 100644 --- a/src/Components/Components/src/RenderHandle.cs +++ b/src/Components/Components/src/RenderHandle.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore.Components.RenderTree; namespace Microsoft.AspNetCore.Components @@ -16,7 +17,7 @@ namespace Microsoft.AspNetCore.Components internal RenderHandle(Renderer renderer, int componentId) { - _renderer = renderer ?? throw new System.ArgumentNullException(nameof(renderer)); + _renderer = renderer ?? throw new ArgumentNullException(nameof(renderer)); _componentId = componentId; } @@ -57,6 +58,7 @@ namespace Microsoft.AspNetCore.Components _renderer.AddToRenderQueue(_componentId, renderFragment); } + [DoesNotReturn] private static void ThrowNotInitialized() { throw new InvalidOperationException("The render handle is not yet assigned."); diff --git a/src/Components/Components/src/RenderTree/ArrayBuilderSegment.cs b/src/Components/Components/src/RenderTree/ArrayBuilderSegment.cs index 4820e2f5fd..0e540f9c8c 100644 --- a/src/Components/Components/src/RenderTree/ArrayBuilderSegment.cs +++ b/src/Components/Components/src/RenderTree/ArrayBuilderSegment.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable enable + using System; using System.Collections; using System.Collections.Generic; @@ -21,7 +23,7 @@ namespace Microsoft.AspNetCore.Components.RenderTree public readonly struct ArrayBuilderSegment : IEnumerable { // The following fields are memory mapped to the WASM client. Do not re-order or use auto-properties. - private readonly ArrayBuilder _builder; + private readonly ArrayBuilder? _builder; private readonly int _offset; private readonly int _count; @@ -35,7 +37,7 @@ namespace Microsoft.AspNetCore.Components.RenderTree /// /// Gets the current underlying array holding the segment's elements. /// - public T[] Array => _builder?.Buffer; + public T[] Array => _builder?.Buffer ?? System.Array.Empty(); /// /// Gets the offset into the underlying array holding the segment's elements. @@ -53,13 +55,13 @@ namespace Microsoft.AspNetCore.Components.RenderTree /// The index into the segment. /// The array entry at the specified index within the segment. public T this[int index] - => _builder.Buffer[_offset + index]; + => Array[_offset + index]; IEnumerator IEnumerable.GetEnumerator() - => ((IEnumerable)new ArraySegment(_builder.Buffer, _offset, _count)).GetEnumerator(); + => ((IEnumerable)new ArraySegment(Array, _offset, _count)).GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() - => ((IEnumerable)new ArraySegment(_builder.Buffer, _offset, _count)).GetEnumerator(); + => ((IEnumerable)new ArraySegment(Array, _offset, _count)).GetEnumerator(); // TODO: If this assembly later moves to netstandard2.1, consider adding a public // GetEnumerator method that returns ArraySegment.Enumerator to avoid boxing. diff --git a/src/Components/Components/src/RenderTree/EventFieldInfo.cs b/src/Components/Components/src/RenderTree/EventFieldInfo.cs index 129057ff73..4c05941911 100644 --- a/src/Components/Components/src/RenderTree/EventFieldInfo.cs +++ b/src/Components/Components/src/RenderTree/EventFieldInfo.cs @@ -21,6 +21,6 @@ namespace Microsoft.AspNetCore.Components.RenderTree /// /// Specifies the form field's new value. /// - public object FieldValue { get; set; } + public object FieldValue { get; set; } = default!; } } diff --git a/src/Components/Components/src/RenderTree/RenderTreeDiffBuilder.cs b/src/Components/Components/src/RenderTree/RenderTreeDiffBuilder.cs index 11f5540f4c..7ef9f94554 100644 --- a/src/Components/Components/src/RenderTree/RenderTreeDiffBuilder.cs +++ b/src/Components/Components/src/RenderTree/RenderTreeDiffBuilder.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable warnings + using System; using System.Collections.Generic; using Microsoft.AspNetCore.Components.Rendering; diff --git a/src/Components/Components/src/RenderTree/RenderTreeFrame.cs b/src/Components/Components/src/RenderTree/RenderTreeFrame.cs index c9a358c698..2a967eaf8e 100644 --- a/src/Components/Components/src/RenderTree/RenderTreeFrame.cs +++ b/src/Components/Components/src/RenderTree/RenderTreeFrame.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable warnings + using System; using System.Runtime.InteropServices; #if !IGNITOR diff --git a/src/Components/Components/src/RenderTree/Renderer.Log.cs b/src/Components/Components/src/RenderTree/Renderer.Log.cs index 9362ecf4f5..da658e5aae 100644 --- a/src/Components/Components/src/RenderTree/Renderer.Log.cs +++ b/src/Components/Components/src/RenderTree/Renderer.Log.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable warnings + using System; using Microsoft.AspNetCore.Components.Rendering; using Microsoft.Extensions.Logging; diff --git a/src/Components/Components/src/RenderTree/Renderer.cs b/src/Components/Components/src/RenderTree/Renderer.cs index 09470cebda..06e0602aa5 100644 --- a/src/Components/Components/src/RenderTree/Renderer.cs +++ b/src/Components/Components/src/RenderTree/Renderer.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable warnings + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/Components/Components/src/Rendering/ComponentState.cs b/src/Components/Components/src/Rendering/ComponentState.cs index dc372424b9..3655d49335 100644 --- a/src/Components/Components/src/Rendering/ComponentState.cs +++ b/src/Components/Components/src/Rendering/ComponentState.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; using Microsoft.AspNetCore.Components.RenderTree; @@ -17,9 +18,10 @@ namespace Microsoft.AspNetCore.Components.Rendering { private readonly Renderer _renderer; private readonly IReadOnlyList _cascadingParameters; + private readonly bool _hasCascadingParameters; private readonly bool _hasAnyCascadingParameterSubscriptions; private RenderTreeBuilder _renderTreeBuilderPrevious; - private ArrayBuilder _latestDirectParametersSnapshot; // Lazily instantiated + private ArrayBuilder? _latestDirectParametersSnapshot; // Lazily instantiated private bool _componentWasDisposed; /// @@ -39,8 +41,9 @@ namespace Microsoft.AspNetCore.Components.Rendering CurrentRenderTree = new RenderTreeBuilder(); _renderTreeBuilderPrevious = new RenderTreeBuilder(); - if (_cascadingParameters != null) + if (_cascadingParameters.Count != 0) { + _hasCascadingParameters = true; _hasAnyCascadingParameterSubscriptions = AddCascadingParameterSubscriptions(); } } @@ -76,7 +79,7 @@ namespace Microsoft.AspNetCore.Components.Rendering batchBuilder.InvalidateParameterViews(); } - public bool TryDisposeInBatch(RenderBatchBuilder batchBuilder, out Exception exception) + public bool TryDisposeInBatch(RenderBatchBuilder batchBuilder, [NotNullWhen(false)] out Exception? exception) { _componentWasDisposed = true; exception = null; @@ -149,7 +152,7 @@ namespace Microsoft.AspNetCore.Components.Rendering parameters.CaptureSnapshot(_latestDirectParametersSnapshot); } - if (_cascadingParameters != null) + if (_hasCascadingParameters) { parameters = parameters.WithCascadingParameters(_cascadingParameters); } @@ -162,7 +165,7 @@ namespace Microsoft.AspNetCore.Components.Rendering var directParams = _latestDirectParametersSnapshot != null ? new ParameterView(lifetime, _latestDirectParametersSnapshot.Buffer, 0) : ParameterView.Empty; - var allParams = directParams.WithCascadingParameters(_cascadingParameters); + var allParams = directParams.WithCascadingParameters(_cascadingParameters!); var task = Component.SetParametersAsync(allParams); _renderer.AddToPendingTasks(task); } @@ -170,7 +173,7 @@ namespace Microsoft.AspNetCore.Components.Rendering private bool AddCascadingParameterSubscriptions() { var hasSubscription = false; - var numCascadingParameters = _cascadingParameters.Count; + var numCascadingParameters = _cascadingParameters!.Count; for (var i = 0; i < numCascadingParameters; i++) { @@ -187,7 +190,7 @@ namespace Microsoft.AspNetCore.Components.Rendering private void RemoveCascadingParameterSubscriptions() { - var numCascadingParameters = _cascadingParameters.Count; + var numCascadingParameters = _cascadingParameters!.Count; for (var i = 0; i < numCascadingParameters; i++) { var supplier = _cascadingParameters[i].ValueSupplier; diff --git a/src/Components/Components/src/Rendering/RenderTreeBuilder.cs b/src/Components/Components/src/Rendering/RenderTreeBuilder.cs index 3cc4aed9bf..281a25cbfa 100644 --- a/src/Components/Components/src/Rendering/RenderTreeBuilder.cs +++ b/src/Components/Components/src/Rendering/RenderTreeBuilder.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable warnings + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/Components/Components/src/Rendering/RendererSynchronizationContext.cs b/src/Components/Components/src/Rendering/RendererSynchronizationContext.cs index d25d50b6de..571f846895 100644 --- a/src/Components/Components/src/Rendering/RendererSynchronizationContext.cs +++ b/src/Components/Components/src/Rendering/RendererSynchronizationContext.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable warnings + using System; using System.Diagnostics; using System.Threading; diff --git a/src/Components/Components/src/RouteView.cs b/src/Components/Components/src/RouteView.cs index 6f77169e06..4fbf3b9cfd 100644 --- a/src/Components/Components/src/RouteView.cs +++ b/src/Components/Components/src/RouteView.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable warnings + using System; using System.Reflection; using System.Threading.Tasks; diff --git a/src/Components/Components/src/Routing/OptionalTypeRouteConstraint.cs b/src/Components/Components/src/Routing/OptionalTypeRouteConstraint.cs index 43beb915fa..426b26b8f2 100644 --- a/src/Components/Components/src/Routing/OptionalTypeRouteConstraint.cs +++ b/src/Components/Components/src/Routing/OptionalTypeRouteConstraint.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Components.Routing _parser = parser; } - public override bool Match(string pathSegment, out object convertedValue) + public override bool Match(string pathSegment, out object? convertedValue) { // Unset values are set to null in the Parameters object created in // the RouteContext. To match this pattern, unset optional parmeters diff --git a/src/Components/Components/src/Routing/RouteConstraint.cs b/src/Components/Components/src/Routing/RouteConstraint.cs index 4028060c76..97ae19580f 100644 --- a/src/Components/Components/src/Routing/RouteConstraint.cs +++ b/src/Components/Components/src/Routing/RouteConstraint.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Components.Routing private static readonly ConcurrentDictionary _cachedConstraints = new ConcurrentDictionary(); - public abstract bool Match(string pathSegment, out object convertedValue); + public abstract bool Match(string pathSegment, out object? convertedValue); public static RouteConstraint Parse(string template, string segment, string constraint) { @@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Components.Routing /// /// String representation of the constraint /// Type-specific RouteConstraint object - private static RouteConstraint CreateRouteConstraint(string constraint) + private static RouteConstraint? CreateRouteConstraint(string constraint) { switch (constraint) { diff --git a/src/Components/Components/src/Routing/RouteContext.cs b/src/Components/Components/src/Routing/RouteContext.cs index 7061e9be41..b28b2fb16e 100644 --- a/src/Components/Components/src/Routing/RouteContext.cs +++ b/src/Components/Components/src/Routing/RouteContext.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Components.Routing { internal class RouteContext { - private static char[] Separator = new[] { '/' }; + private static readonly char[] Separator = new[] { '/' }; public RouteContext(string path) { @@ -24,8 +24,8 @@ namespace Microsoft.AspNetCore.Components.Routing public string[] Segments { get; } - public Type Handler { get; set; } + public Type? Handler { get; set; } - public IReadOnlyDictionary Parameters { get; set; } + public IReadOnlyDictionary? Parameters { get; set; } } } diff --git a/src/Components/Components/src/Routing/RouteEntry.cs b/src/Components/Components/src/Routing/RouteEntry.cs index 485c12a4d9..e21517daf1 100644 --- a/src/Components/Components/src/Routing/RouteEntry.cs +++ b/src/Components/Components/src/Routing/RouteEntry.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable warnings + using System; using System.Linq; using System.Collections.Generic; diff --git a/src/Components/Components/src/Routing/RouteTableFactory.cs b/src/Components/Components/src/Routing/RouteTableFactory.cs index c8da2329bc..d1e2991f5f 100644 --- a/src/Components/Components/src/Routing/RouteTableFactory.cs +++ b/src/Components/Components/src/Routing/RouteTableFactory.cs @@ -188,7 +188,7 @@ namespace Microsoft.AspNetCore.Components Assemblies = assemblies; } - public override bool Equals(object obj) + public override bool Equals(object? obj) { return obj is Key other ? base.Equals(other) : false; } @@ -199,7 +199,7 @@ namespace Microsoft.AspNetCore.Components { return true; } - else if (Assemblies == null ^ other.Assemblies == null) + else if ((Assemblies == null) || (other.Assemblies == null)) { return false; } diff --git a/src/Components/Components/src/Routing/Router.cs b/src/Components/Components/src/Routing/Router.cs index b93db4b6ac..252dd5c214 100644 --- a/src/Components/Components/src/Routing/Router.cs +++ b/src/Components/Components/src/Routing/Router.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable warnings + using System; using System.Collections.Generic; using System.Collections.ObjectModel; diff --git a/src/Components/Components/src/Routing/TemplateSegment.cs b/src/Components/Components/src/Routing/TemplateSegment.cs index bcc2e27843..ee2e58ceb4 100644 --- a/src/Components/Components/src/Routing/TemplateSegment.cs +++ b/src/Components/Components/src/Routing/TemplateSegment.cs @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Components.Routing public RouteConstraint[] Constraints { get; } - public bool Match(string pathSegment, out object matchedParameterValue) + public bool Match(string pathSegment, out object? matchedParameterValue) { if (IsParameter) { diff --git a/src/Components/Components/src/Routing/TypeRouteConstraint.cs b/src/Components/Components/src/Routing/TypeRouteConstraint.cs index 1026e88eac..11aa9f749b 100644 --- a/src/Components/Components/src/Routing/TypeRouteConstraint.cs +++ b/src/Components/Components/src/Routing/TypeRouteConstraint.cs @@ -1,6 +1,8 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Diagnostics.CodeAnalysis; + namespace Microsoft.AspNetCore.Components.Routing { /// @@ -9,7 +11,7 @@ namespace Microsoft.AspNetCore.Components.Routing /// The type to which the value must be parseable. internal class TypeRouteConstraint : RouteConstraint { - public delegate bool TryParseDelegate(string str, out T result); + public delegate bool TryParseDelegate(string str, [MaybeNullWhen(false)] out T result); private readonly TryParseDelegate _parser; @@ -18,7 +20,7 @@ namespace Microsoft.AspNetCore.Components.Routing _parser = parser; } - public override bool Match(string pathSegment, out object convertedValue) + public override bool Match(string pathSegment, out object? convertedValue) { if (_parser(pathSegment, out var result)) { diff --git a/src/Components/Components/test/CascadingParameterStateTest.cs b/src/Components/Components/test/CascadingParameterStateTest.cs index 5931d9d6fc..3e78185899 100644 --- a/src/Components/Components/test/CascadingParameterStateTest.cs +++ b/src/Components/Components/test/CascadingParameterStateTest.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Components.Test public class CascadingParameterStateTest { [Fact] - public void FindCascadingParameters_IfHasNoParameters_ReturnsNull() + public void FindCascadingParameters_IfHasNoParameters_ReturnsEmpty() { // Arrange var componentState = CreateComponentState(new ComponentWithNoParams()); @@ -24,11 +24,11 @@ namespace Microsoft.AspNetCore.Components.Test var result = CascadingParameterState.FindCascadingParameters(componentState); // Assert - Assert.Null(result); + Assert.Empty(result); } [Fact] - public void FindCascadingParameters_IfHasNoCascadingParameters_ReturnsNull() + public void FindCascadingParameters_IfHasNoCascadingParameters_ReturnsEmpty() { // Arrange var componentState = CreateComponentState(new ComponentWithNoCascadingParams()); @@ -37,11 +37,11 @@ namespace Microsoft.AspNetCore.Components.Test var result = CascadingParameterState.FindCascadingParameters(componentState); // Assert - Assert.Null(result); + Assert.Empty(result); } [Fact] - public void FindCascadingParameters_IfHasNoAncestors_ReturnsNull() + public void FindCascadingParameters_IfHasNoAncestors_ReturnsEmpty() { // Arrange var componentState = CreateComponentState(new ComponentWithCascadingParams()); @@ -50,11 +50,11 @@ namespace Microsoft.AspNetCore.Components.Test var result = CascadingParameterState.FindCascadingParameters(componentState); // Assert - Assert.Null(result); + Assert.Empty(result); } [Fact] - public void FindCascadingParameters_IfHasNoMatchesInAncestors_ReturnsNull() + public void FindCascadingParameters_IfHasNoMatchesInAncestors_ReturnsEmpty() { // Arrange: Build the ancestry list var states = CreateAncestry( @@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Components.Test var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert - Assert.Null(result); + Assert.Empty(result); } [Fact] @@ -178,7 +178,7 @@ namespace Microsoft.AspNetCore.Components.Test } [Fact] - public void FindCascadingParameters_ComponentRequestsDerivedType_ReturnsNull() + public void FindCascadingParameters_ComponentRequestsDerivedType_ReturnsEmpty() { // Arrange var states = CreateAncestry( @@ -189,7 +189,7 @@ namespace Microsoft.AspNetCore.Components.Test var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert - Assert.Null(result); + Assert.Empty(result); } [Fact] @@ -211,7 +211,7 @@ namespace Microsoft.AspNetCore.Components.Test } [Fact] - public void FindCascadingParameters_TypeAssignmentIsInvalidForNullValue_ReturnsNull() + public void FindCascadingParameters_TypeAssignmentIsInvalidForNullValue_ReturnsEmpty() { // Arrange var states = CreateAncestry( @@ -222,11 +222,11 @@ namespace Microsoft.AspNetCore.Components.Test var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert - Assert.Null(result); + Assert.Empty(result); } [Fact] - public void FindCascadingParameters_SupplierSpecifiesNameButConsumerDoesNot_ReturnsNull() + public void FindCascadingParameters_SupplierSpecifiesNameButConsumerDoesNot_ReturnsEmpty() { // Arrange var states = CreateAncestry( @@ -237,11 +237,11 @@ namespace Microsoft.AspNetCore.Components.Test var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert - Assert.Null(result); + Assert.Empty(result); } [Fact] - public void FindCascadingParameters_ConsumerSpecifiesNameButSupplierDoesNot_ReturnsNull() + public void FindCascadingParameters_ConsumerSpecifiesNameButSupplierDoesNot_ReturnsEmpty() { // Arrange var states = CreateAncestry( @@ -252,11 +252,11 @@ namespace Microsoft.AspNetCore.Components.Test var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert - Assert.Null(result); + Assert.Empty(result); } [Fact] - public void FindCascadingParameters_MismatchingNameButMatchingType_ReturnsNull() + public void FindCascadingParameters_MismatchingNameButMatchingType_ReturnsEmpty() { // Arrange var states = CreateAncestry( @@ -267,11 +267,11 @@ namespace Microsoft.AspNetCore.Components.Test var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert - Assert.Null(result); + Assert.Empty(result); } [Fact] - public void FindCascadingParameters_MatchingNameButMismatchingType_ReturnsNull() + public void FindCascadingParameters_MatchingNameButMismatchingType_ReturnsEmpty() { // Arrange var states = CreateAncestry( @@ -282,7 +282,7 @@ namespace Microsoft.AspNetCore.Components.Test var result = CascadingParameterState.FindCascadingParameters(states.Last()); // Assert - Assert.Null(result); + Assert.Empty(result); } [Fact] diff --git a/src/Components/Shared/src/ArrayBuilder.cs b/src/Components/Shared/src/ArrayBuilder.cs index 2705a54dc4..8efa1c7baf 100644 --- a/src/Components/Shared/src/ArrayBuilder.cs +++ b/src/Components/Shared/src/ArrayBuilder.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable disable warnings + using System; using System.Buffers; using System.Diagnostics; diff --git a/src/Shared/HashCodeCombiner/HashCodeCombiner.cs b/src/Shared/HashCodeCombiner/HashCodeCombiner.cs index 4df8b46b05..054601018a 100644 --- a/src/Shared/HashCodeCombiner/HashCodeCombiner.cs +++ b/src/Shared/HashCodeCombiner/HashCodeCombiner.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable enable + using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -33,7 +35,7 @@ namespace Microsoft.Extensions.Internal else { var count = 0; - foreach (object o in e) + foreach (object? o in e) { Add(o); count++; @@ -55,14 +57,14 @@ namespace Microsoft.Extensions.Internal } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Add(string s) + public void Add(string? s) { var hashCode = (s != null) ? s.GetHashCode() : 0; Add(hashCode); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Add(object o) + public void Add(object? o) { var hashCode = (o != null) ? o.GetHashCode() : 0; Add(hashCode);