Răsfoiți Sursa

Annotate Components.Forms \ Components.Web \ Component.Server with nullable attributes (#23204)

* Annotate Components.Forms \ Components.Web with nullable attributes
Contributes to https://github.com/dotnet/aspnetcore/issues/5680

* Fixup

* Fixup rebase

* Undo nullable

* Fixup
Pranav K 5 ani în urmă
părinte
comite
c42d1a3858
48 a modificat fișierele cu 316 adăugiri și 273 ștergeri
  1. 13 13
      src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp.cs
  2. 13 13
      src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs
  3. 2 3
      src/Components/Components/src/BindConverter.cs
  4. 1 1
      src/Components/Components/src/RenderTree/RenderTreeFrame.cs
  5. 14 17
      src/Components/Components/src/Rendering/RenderTreeBuilder.cs
  6. 1 0
      src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.csproj
  7. 4 4
      src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.netcoreapp.cs
  8. 4 4
      src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.netstandard2.0.cs
  9. 1 1
      src/Components/Forms/src/DataAnnotationsValidator.cs
  10. 12 6
      src/Components/Forms/src/EditContext.cs
  11. 5 4
      src/Components/Forms/src/EditContextDataAnnotationsExtensions.cs
  12. 26 14
      src/Components/Forms/src/FieldIdentifier.cs
  13. 1 1
      src/Components/Forms/src/FieldState.cs
  14. 2 1
      src/Components/Forms/src/Microsoft.AspNetCore.Components.Forms.csproj
  15. 2 2
      src/Components/Forms/src/ValidationMessageStore.cs
  16. 1 0
      src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.csproj
  17. 1 1
      src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.netcoreapp.cs
  18. 1 1
      src/Components/Server/src/DependencyInjection/ComponentServiceCollectionExtensions.cs
  19. 4 2
      src/Components/Server/src/DependencyInjection/ServerSideBlazorBuilderExtensions.cs
  20. 2 1
      src/Components/Server/src/Microsoft.AspNetCore.Components.Server.csproj
  21. 1 0
      src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.csproj
  22. 43 39
      src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netcoreapp.cs
  23. 39 39
      src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netstandard2.0.cs
  24. 6 6
      src/Components/Web/src/BindInputElementAttribute.cs
  25. 11 6
      src/Components/Web/src/Forms/EditForm.cs
  26. 25 23
      src/Components/Web/src/Forms/InputBase.cs
  27. 3 2
      src/Components/Web/src/Forms/InputCheckbox.cs
  28. 5 4
      src/Components/Web/src/Forms/InputDate.cs
  29. 4 3
      src/Components/Web/src/Forms/InputNumber.cs
  30. 7 6
      src/Components/Web/src/Forms/InputSelect.cs
  31. 4 3
      src/Components/Web/src/Forms/InputText.cs
  32. 4 3
      src/Components/Web/src/Forms/InputTextArea.cs
  33. 6 6
      src/Components/Web/src/Forms/ValidationMessage.cs
  34. 4 4
      src/Components/Web/src/Forms/ValidationSummary.cs
  35. 2 1
      src/Components/Web/src/Microsoft.AspNetCore.Components.Web.csproj
  36. 15 14
      src/Components/Web/src/Routing/NavLink.cs
  37. 1 1
      src/Components/Web/src/Web/ClipboardEventArgs.cs
  38. 7 5
      src/Components/Web/src/Web/DataTransfer.cs
  39. 2 2
      src/Components/Web/src/Web/DataTransferItem.cs
  40. 1 1
      src/Components/Web/src/Web/DragEventArgs.cs
  41. 3 3
      src/Components/Web/src/Web/ErrorEventArgs.cs
  42. 1 1
      src/Components/Web/src/Web/FocusEventArgs.cs
  43. 3 3
      src/Components/Web/src/Web/KeyboardEventArgs.cs
  44. 1 1
      src/Components/Web/src/Web/MouseEventArgs.cs
  45. 1 1
      src/Components/Web/src/Web/PointerEventArgs.cs
  46. 1 1
      src/Components/Web/src/Web/ProgressEventArgs.cs
  47. 4 4
      src/Components/Web/src/Web/TouchEventArgs.cs
  48. 2 2
      src/Components/Web/src/WebEventDescriptor.cs

+ 13 - 13
src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp.cs

@@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Components
         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 string? FormatValue(string? value, System.Globalization.CultureInfo? culture = null) { throw null; }
         public static object? FormatValue<T>(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; }
@@ -399,29 +399,29 @@ namespace Microsoft.AspNetCore.Components.Rendering
         public void AddAttribute(int sequence, in Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame frame) { }
         public void AddAttribute(int sequence, string name, Microsoft.AspNetCore.Components.EventCallback value) { }
         public void AddAttribute(int sequence, string name, bool value) { }
-        public void AddAttribute(int sequence, string name, System.MulticastDelegate value) { }
-        public void AddAttribute(int sequence, string name, object value) { }
-        public void AddAttribute(int sequence, string name, string value) { }
+        public void AddAttribute(int sequence, string name, System.MulticastDelegate? value) { }
+        public void AddAttribute(int sequence, string name, object? value) { }
+        public void AddAttribute(int sequence, string name, string? value) { }
         public void AddAttribute<TArgument>(int sequence, string name, Microsoft.AspNetCore.Components.EventCallback<TArgument> value) { }
-        public void AddComponentReferenceCapture(int sequence, System.Action<object> componentReferenceCaptureAction) { }
+        public void AddComponentReferenceCapture(int sequence, System.Action<object?> componentReferenceCaptureAction) { }
         public void AddContent(int sequence, Microsoft.AspNetCore.Components.MarkupString markupContent) { }
-        public void AddContent(int sequence, Microsoft.AspNetCore.Components.RenderFragment fragment) { }
-        public void AddContent(int sequence, object textContent) { }
-        public void AddContent(int sequence, string textContent) { }
-        public void AddContent<TValue>(int sequence, Microsoft.AspNetCore.Components.RenderFragment<TValue> fragment, TValue value) { }
+        public void AddContent(int sequence, Microsoft.AspNetCore.Components.RenderFragment? fragment) { }
+        public void AddContent(int sequence, object? textContent) { }
+        public void AddContent(int sequence, string? textContent) { }
+        public void AddContent<TValue>(int sequence, Microsoft.AspNetCore.Components.RenderFragment<TValue>? fragment, TValue value) { }
         public void AddElementReferenceCapture(int sequence, System.Action<Microsoft.AspNetCore.Components.ElementReference> elementReferenceCaptureAction) { }
-        public void AddMarkupContent(int sequence, string markupContent) { }
-        public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>> attributes) { }
+        public void AddMarkupContent(int sequence, string? markupContent) { }
+        public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>? attributes) { }
         public void Clear() { }
         public void CloseComponent() { }
         public void CloseElement() { }
         public void CloseRegion() { }
         public Microsoft.AspNetCore.Components.RenderTree.ArrayRange<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame> GetFrames() { throw null; }
         public void OpenComponent(int sequence, System.Type componentType) { }
-        public void OpenComponent<TComponent>(int sequence) where TComponent : Microsoft.AspNetCore.Components.IComponent { }
+        public void OpenComponent<TComponent>(int sequence) where TComponent : notnull, Microsoft.AspNetCore.Components.IComponent { }
         public void OpenElement(int sequence, string elementName) { }
         public void OpenRegion(int sequence) { }
-        public void SetKey(object value) { }
+        public void SetKey(object? value) { }
         public void SetUpdatesAttributeName(string updatesAttributeName) { }
         void System.IDisposable.Dispose() { }
     }

+ 13 - 13
src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs

@@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Components
         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 string? FormatValue(string? value, System.Globalization.CultureInfo? culture = null) { throw null; }
         public static object? FormatValue<T>(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; }
@@ -398,29 +398,29 @@ namespace Microsoft.AspNetCore.Components.Rendering
         public void AddAttribute(int sequence, in Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame frame) { }
         public void AddAttribute(int sequence, string name, Microsoft.AspNetCore.Components.EventCallback value) { }
         public void AddAttribute(int sequence, string name, bool value) { }
-        public void AddAttribute(int sequence, string name, System.MulticastDelegate value) { }
-        public void AddAttribute(int sequence, string name, object value) { }
-        public void AddAttribute(int sequence, string name, string value) { }
+        public void AddAttribute(int sequence, string name, System.MulticastDelegate? value) { }
+        public void AddAttribute(int sequence, string name, object? value) { }
+        public void AddAttribute(int sequence, string name, string? value) { }
         public void AddAttribute<TArgument>(int sequence, string name, Microsoft.AspNetCore.Components.EventCallback<TArgument> value) { }
-        public void AddComponentReferenceCapture(int sequence, System.Action<object> componentReferenceCaptureAction) { }
+        public void AddComponentReferenceCapture(int sequence, System.Action<object?> componentReferenceCaptureAction) { }
         public void AddContent(int sequence, Microsoft.AspNetCore.Components.MarkupString markupContent) { }
-        public void AddContent(int sequence, Microsoft.AspNetCore.Components.RenderFragment fragment) { }
-        public void AddContent(int sequence, object textContent) { }
-        public void AddContent(int sequence, string textContent) { }
-        public void AddContent<TValue>(int sequence, Microsoft.AspNetCore.Components.RenderFragment<TValue> fragment, TValue value) { }
+        public void AddContent(int sequence, Microsoft.AspNetCore.Components.RenderFragment? fragment) { }
+        public void AddContent(int sequence, object? textContent) { }
+        public void AddContent(int sequence, string? textContent) { }
+        public void AddContent<TValue>(int sequence, Microsoft.AspNetCore.Components.RenderFragment<TValue>? fragment, TValue value) { }
         public void AddElementReferenceCapture(int sequence, System.Action<Microsoft.AspNetCore.Components.ElementReference> elementReferenceCaptureAction) { }
-        public void AddMarkupContent(int sequence, string markupContent) { }
-        public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>> attributes) { }
+        public void AddMarkupContent(int sequence, string? markupContent) { }
+        public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>? attributes) { }
         public void Clear() { }
         public void CloseComponent() { }
         public void CloseElement() { }
         public void CloseRegion() { }
         public Microsoft.AspNetCore.Components.RenderTree.ArrayRange<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame> GetFrames() { throw null; }
         public void OpenComponent(int sequence, System.Type componentType) { }
-        public void OpenComponent<TComponent>(int sequence) where TComponent : Microsoft.AspNetCore.Components.IComponent { }
+        public void OpenComponent<TComponent>(int sequence) where TComponent : notnull, Microsoft.AspNetCore.Components.IComponent { }
         public void OpenElement(int sequence, string elementName) { }
         public void OpenRegion(int sequence) { }
-        public void SetKey(object value) { }
+        public void SetKey(object? value) { }
         public void SetUpdatesAttributeName(string updatesAttributeName) { }
         void System.IDisposable.Dispose() { }
     }

+ 2 - 3
src/Components/Components/src/BindConverter.cs

@@ -4,7 +4,6 @@
 using System;
 using System.Collections.Concurrent;
 using System.ComponentModel;
-using System.Diagnostics.CodeAnalysis;
 using System.Globalization;
 using System.Reflection;
 
@@ -36,9 +35,9 @@ namespace Microsoft.AspNetCore.Components
         /// The <see cref="CultureInfo"/> to use while formatting. Defaults to <see cref="CultureInfo.CurrentCulture"/>.
         /// </param>
         /// <returns>The formatted value.</returns>
-        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;
         }

+ 1 - 1
src/Components/Components/src/RenderTree/RenderTreeFrame.cs

@@ -1,7 +1,7 @@
 // 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
+#nullable disable
 
 using System;
 using System.Runtime.InteropServices;

+ 14 - 17
src/Components/Components/src/Rendering/RenderTreeBuilder.cs

@@ -1,12 +1,9 @@
 // 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;
-using System.Threading.Tasks;
 using Microsoft.AspNetCore.Components.RenderTree;
 
 namespace Microsoft.AspNetCore.Components.Rendering
@@ -29,7 +26,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
         private readonly Stack<int> _openElementIndices = new Stack<int>();
         private RenderTreeFrameType? _lastNonAttributeFrameType;
         private bool _hasSeenAddMultipleAttributes;
-        private Dictionary<string, int> _seenAttributeNames;
+        private Dictionary<string, int>? _seenAttributeNames;
 
         /// <summary>
         /// The reserved parameter name used for supplying child content.
@@ -82,7 +79,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
         /// </summary>
         /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
         /// <param name="markupContent">Content for the new markup frame.</param>
-        public void AddMarkupContent(int sequence, string markupContent)
+        public void AddMarkupContent(int sequence, string? markupContent)
             => Append(RenderTreeFrame.Markup(sequence, markupContent ?? string.Empty));
 
         /// <summary>
@@ -90,7 +87,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
         /// </summary>
         /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
         /// <param name="textContent">Content for the new text frame.</param>
-        public void AddContent(int sequence, string textContent)
+        public void AddContent(int sequence, string? textContent)
             => Append(RenderTreeFrame.Text(sequence, textContent ?? string.Empty));
 
         /// <summary>
@@ -98,7 +95,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
         /// </summary>
         /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
         /// <param name="fragment">Content to append.</param>
-        public void AddContent(int sequence, RenderFragment fragment)
+        public void AddContent(int sequence, RenderFragment? fragment)
         {
             if (fragment != null)
             {
@@ -118,7 +115,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
         /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
         /// <param name="fragment">Content to append.</param>
         /// <param name="value">The value used by <paramref name="fragment"/>.</param>
-        public void AddContent<TValue>(int sequence, RenderFragment<TValue> fragment, TValue value)
+        public void AddContent<TValue>(int sequence, RenderFragment<TValue>? fragment, TValue value)
         {
             if (fragment != null)
             {
@@ -139,7 +136,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
         /// </summary>
         /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
         /// <param name="textContent">Content for the new text frame.</param>
-        public void AddContent(int sequence, object textContent)
+        public void AddContent(int sequence, object? textContent)
             => AddContent(sequence, textContent?.ToString());
 
         /// <summary>
@@ -185,7 +182,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
         /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
         /// <param name="name">The name of the attribute.</param>
         /// <param name="value">The value of the attribute.</param>
-        public void AddAttribute(int sequence, string name, string value)
+        public void AddAttribute(int sequence, string name, string? value)
         {
             AssertCanAddAttribute();
             if (value != null || _lastNonAttributeFrameType == RenderTreeFrameType.Component)
@@ -210,7 +207,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
         /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
         /// <param name="name">The name of the attribute.</param>
         /// <param name="value">The value of the attribute.</param>
-        public void AddAttribute(int sequence, string name, MulticastDelegate value)
+        public void AddAttribute(int sequence, string name, MulticastDelegate? value)
         {
             AssertCanAddAttribute();
             if (value != null || _lastNonAttributeFrameType == RenderTreeFrameType.Component)
@@ -320,7 +317,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
         /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
         /// <param name="name">The name of the attribute.</param>
         /// <param name="value">The value of the attribute.</param>
-        public void AddAttribute(int sequence, string name, object value)
+        public void AddAttribute(int sequence, string name, object? value)
         {
             // This looks a bit daunting because we need to handle the boxed/object version of all of the
             // types that AddAttribute special cases.
@@ -402,7 +399,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
         /// </summary>
         /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
         /// <param name="attributes">A collection of key-value pairs representing attributes.</param>
-        public void AddMultipleAttributes(int sequence, IEnumerable<KeyValuePair<string, object>> attributes)
+        public void AddMultipleAttributes(int sequence, IEnumerable<KeyValuePair<string, object>>? attributes)
         {
             // Calling this up-front just to make sure we validate before mutating anything.
             AssertCanAddAttribute();
@@ -455,7 +452,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
         /// </summary>
         /// <typeparam name="TComponent">The type of the child component.</typeparam>
         /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
-        public void OpenComponent<TComponent>(int sequence) where TComponent : IComponent
+        public void OpenComponent<TComponent>(int sequence) where TComponent : notnull, IComponent
             => OpenComponentUnchecked(sequence, typeof(TComponent));
 
         /// <summary>
@@ -477,7 +474,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
         /// Assigns the specified key value to the current element or component.
         /// </summary>
         /// <param name="value">The value for the key.</param>
-        public void SetKey(object value)
+        public void SetKey(object? value)
         {
             if (value == null)
             {
@@ -560,7 +557,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
         /// </summary>
         /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
         /// <param name="componentReferenceCaptureAction">An action to be invoked whenever the reference value changes.</param>
-        public void AddComponentReferenceCapture(int sequence, Action<object> componentReferenceCaptureAction)
+        public void AddComponentReferenceCapture(int sequence, Action<object?> componentReferenceCaptureAction)
         {
             var parentFrameIndex = GetCurrentParentFrameIndex();
             if (!parentFrameIndex.HasValue)
@@ -640,7 +637,7 @@ namespace Microsoft.AspNetCore.Components.Rendering
 
         // internal because this should only be used during the post-event tree patching logic
         // It's expensive because it involves copying all the subsequent memory in the array
-        internal void InsertAttributeExpensive(int insertAtIndex, int sequence, string attributeName, object attributeValue)
+        internal void InsertAttributeExpensive(int insertAtIndex, int sequence, string attributeName, object? attributeValue)
         {
             // Replicate the same attribute omission logic as used elsewhere
             if ((attributeValue == null) || (attributeValue is bool boolValue && !boolValue))

+ 1 - 0
src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.csproj

@@ -3,6 +3,7 @@
   <PropertyGroup>
     <TargetFrameworks>netstandard2.0;$(DefaultNetCoreTargetFramework)</TargetFrameworks>
     <TargetFrameworks Condition="'$(DotNetBuildFromSource)' == 'true'">$(DefaultNetCoreTargetFramework)</TargetFrameworks>
+    <Nullable>annotations</Nullable>
   </PropertyGroup>
   <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
     <Compile Include="Microsoft.AspNetCore.Components.Forms.netstandard2.0.cs" />

+ 4 - 4
src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.netcoreapp.cs

@@ -12,9 +12,9 @@ namespace Microsoft.AspNetCore.Components.Forms
     {
         public EditContext(object model) { }
         public object Model { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
-        public event System.EventHandler<Microsoft.AspNetCore.Components.Forms.FieldChangedEventArgs> OnFieldChanged { add { } remove { } }
-        public event System.EventHandler<Microsoft.AspNetCore.Components.Forms.ValidationRequestedEventArgs> OnValidationRequested { add { } remove { } }
-        public event System.EventHandler<Microsoft.AspNetCore.Components.Forms.ValidationStateChangedEventArgs> OnValidationStateChanged { add { } remove { } }
+        public event System.EventHandler<Microsoft.AspNetCore.Components.Forms.FieldChangedEventArgs>? OnFieldChanged { add { } remove { } }
+        public event System.EventHandler<Microsoft.AspNetCore.Components.Forms.ValidationRequestedEventArgs>? OnValidationRequested { add { } remove { } }
+        public event System.EventHandler<Microsoft.AspNetCore.Components.Forms.ValidationStateChangedEventArgs>? OnValidationStateChanged { add { } remove { } }
         public Microsoft.AspNetCore.Components.Forms.FieldIdentifier Field(string fieldName) { throw null; }
         public System.Collections.Generic.IEnumerable<string> GetValidationMessages() { throw null; }
         public System.Collections.Generic.IEnumerable<string> GetValidationMessages(Microsoft.AspNetCore.Components.Forms.FieldIdentifier fieldIdentifier) { throw null; }
@@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Components.Forms
         public object Model { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
         public static Microsoft.AspNetCore.Components.Forms.FieldIdentifier Create<TField>(System.Linq.Expressions.Expression<System.Func<TField>> accessor) { throw null; }
         public bool Equals(Microsoft.AspNetCore.Components.Forms.FieldIdentifier otherIdentifier) { throw null; }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         public override int GetHashCode() { throw null; }
     }
     public sealed partial class ValidationMessageStore

+ 4 - 4
src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.netstandard2.0.cs

@@ -12,9 +12,9 @@ namespace Microsoft.AspNetCore.Components.Forms
     {
         public EditContext(object model) { }
         public object Model { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
-        public event System.EventHandler<Microsoft.AspNetCore.Components.Forms.FieldChangedEventArgs> OnFieldChanged { add { } remove { } }
-        public event System.EventHandler<Microsoft.AspNetCore.Components.Forms.ValidationRequestedEventArgs> OnValidationRequested { add { } remove { } }
-        public event System.EventHandler<Microsoft.AspNetCore.Components.Forms.ValidationStateChangedEventArgs> OnValidationStateChanged { add { } remove { } }
+        public event System.EventHandler<Microsoft.AspNetCore.Components.Forms.FieldChangedEventArgs>? OnFieldChanged { add { } remove { } }
+        public event System.EventHandler<Microsoft.AspNetCore.Components.Forms.ValidationRequestedEventArgs>? OnValidationRequested { add { } remove { } }
+        public event System.EventHandler<Microsoft.AspNetCore.Components.Forms.ValidationStateChangedEventArgs>? OnValidationStateChanged { add { } remove { } }
         public Microsoft.AspNetCore.Components.Forms.FieldIdentifier Field(string fieldName) { throw null; }
         public System.Collections.Generic.IEnumerable<string> GetValidationMessages() { throw null; }
         public System.Collections.Generic.IEnumerable<string> GetValidationMessages(Microsoft.AspNetCore.Components.Forms.FieldIdentifier fieldIdentifier) { throw null; }
@@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Components.Forms
         public object Model { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
         public static Microsoft.AspNetCore.Components.Forms.FieldIdentifier Create<TField>(System.Linq.Expressions.Expression<System.Func<TField>> accessor) { throw null; }
         public bool Equals(Microsoft.AspNetCore.Components.Forms.FieldIdentifier otherIdentifier) { throw null; }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         public override int GetHashCode() { throw null; }
     }
     public sealed partial class ValidationMessageStore

+ 1 - 1
src/Components/Forms/src/DataAnnotationsValidator.cs

@@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Components.Forms
     /// </summary>
     public class DataAnnotationsValidator : ComponentBase
     {
-        [CascadingParameter] EditContext CurrentEditContext { get; set; }
+        [CascadingParameter] EditContext? CurrentEditContext { get; set; }
 
         /// <inheritdoc />
         protected override void OnInitialized()

+ 12 - 6
src/Components/Forms/src/EditContext.cs

@@ -36,17 +36,17 @@ namespace Microsoft.AspNetCore.Components.Forms
         /// <summary>
         /// An event that is raised when a field value changes.
         /// </summary>
-        public event EventHandler<FieldChangedEventArgs> OnFieldChanged;
+        public event EventHandler<FieldChangedEventArgs>? OnFieldChanged;
 
         /// <summary>
         /// An event that is raised when validation is requested.
         /// </summary>
-        public event EventHandler<ValidationRequestedEventArgs> OnValidationRequested;
+        public event EventHandler<ValidationRequestedEventArgs>? OnValidationRequested;
 
         /// <summary>
         /// An event that is raised when validation state has changed.
         /// </summary>
-        public event EventHandler<ValidationStateChangedEventArgs> OnValidationStateChanged;
+        public event EventHandler<ValidationStateChangedEventArgs>? OnValidationStateChanged;
 
         /// <summary>
         /// Supplies a <see cref="FieldIdentifier"/> corresponding to a specified field name
@@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Components.Forms
         /// <param name="fieldIdentifier">Identifies the field whose value has been changed.</param>
         public void NotifyFieldChanged(in FieldIdentifier fieldIdentifier)
         {
-            GetFieldState(fieldIdentifier, ensureExists: true).IsModified = true;
+            GetOrAddFieldState(fieldIdentifier).IsModified = true;
             OnFieldChanged?.Invoke(this, new FieldChangedEventArgs(fieldIdentifier));
         }
 
@@ -196,9 +196,15 @@ namespace Microsoft.AspNetCore.Components.Forms
             return !GetValidationMessages().Any();
         }
 
-        internal FieldState GetFieldState(in FieldIdentifier fieldIdentifier, bool ensureExists)
+        internal FieldState? GetFieldState(in FieldIdentifier fieldIdentifier)
         {
-            if (!_fieldStates.TryGetValue(fieldIdentifier, out var state) && ensureExists)
+            _fieldStates.TryGetValue(fieldIdentifier, out var state);
+            return state;
+        }
+
+        internal FieldState GetOrAddFieldState(in FieldIdentifier fieldIdentifier)
+        {
+            if (!_fieldStates.TryGetValue(fieldIdentifier, out var state))
             {
                 state = new FieldState(fieldIdentifier);
                 _fieldStates.Add(fieldIdentifier, state);

+ 5 - 4
src/Components/Forms/src/EditContextDataAnnotationsExtensions.cs

@@ -5,6 +5,7 @@ using System;
 using System.Collections.Concurrent;
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
+using System.Diagnostics.CodeAnalysis;
 using System.Linq;
 using System.Reflection;
 
@@ -15,8 +16,8 @@ namespace Microsoft.AspNetCore.Components.Forms
     /// </summary>
     public static class EditContextDataAnnotationsExtensions
     {
-        private static ConcurrentDictionary<(Type ModelType, string FieldName), PropertyInfo> _propertyInfoCache
-            = new ConcurrentDictionary<(Type, string), PropertyInfo>();
+        private static ConcurrentDictionary<(Type ModelType, string FieldName), PropertyInfo?> _propertyInfoCache
+            = new ConcurrentDictionary<(Type, string), PropertyInfo?>();
 
         /// <summary>
         /// Adds DataAnnotations validation support to the <see cref="EditContext"/>.
@@ -33,7 +34,7 @@ namespace Microsoft.AspNetCore.Components.Forms
 
             // Perform object-level validation on request
             editContext.OnValidationRequested +=
-                (sender, eventArgs) => ValidateModel((EditContext)sender, messages);
+                (sender, eventArgs) => ValidateModel((EditContext)sender!, messages);
 
             // Perform per-field validation on each field edit
             editContext.OnFieldChanged +=
@@ -88,7 +89,7 @@ namespace Microsoft.AspNetCore.Components.Forms
             }
         }
 
-        private static bool TryGetValidatableProperty(in FieldIdentifier fieldIdentifier, out PropertyInfo propertyInfo)
+        private static bool TryGetValidatableProperty(in FieldIdentifier fieldIdentifier, [NotNullWhen(true)] out PropertyInfo? propertyInfo)
         {
             var cacheKey = (ModelType: fieldIdentifier.Model.GetType(), fieldIdentifier.FieldName);
             if (!_propertyInfoCache.TryGetValue(cacheKey, out propertyInfo))

+ 26 - 14
src/Components/Forms/src/FieldIdentifier.cs

@@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Components.Forms
         }
 
         /// <inheritdoc />
-        public override bool Equals(object obj)
+        public override bool Equals(object? obj)
             => obj is FieldIdentifier otherIdentifier
             && Equals(otherIdentifier);
 
@@ -111,20 +111,32 @@ namespace Microsoft.AspNetCore.Components.Forms
 
             // Get a reference to the model object
             // i.e., given an value like "(something).MemberName", determine the runtime value of "(something)",
-            switch (memberExpression.Expression)
+            if (memberExpression.Expression is ConstantExpression constantExpression)
             {
-                case ConstantExpression constantExpression:
-                    model = constantExpression.Value;
-                    break;
-                default:
-                    // It would be great to cache this somehow, but it's unclear there's a reasonable way to do
-                    // so, given that it embeds captured values such as "this". We could consider special-casing
-                    // for "() => something.Member" and building a cache keyed by "something.GetType()" with values
-                    // of type Func<object, object> so we can cheaply map from "something" to "something.Member".
-                    var modelLambda = Expression.Lambda(memberExpression.Expression);
-                    var modelLambdaCompiled = (Func<object>)modelLambda.Compile();
-                    model = modelLambdaCompiled();
-                    break;
+                if (constantExpression.Value is null)
+                {
+                    throw new ArgumentException("The provided expression must evaluate to a non-null value.");
+                }
+                model = constantExpression.Value;
+            }
+            else if (memberExpression.Expression != null)
+            {
+                // It would be great to cache this somehow, but it's unclear there's a reasonable way to do
+                // so, given that it embeds captured values such as "this". We could consider special-casing
+                // for "() => something.Member" and building a cache keyed by "something.GetType()" with values
+                // of type Func<object, object> so we can cheaply map from "something" to "something.Member".
+                var modelLambda = Expression.Lambda(memberExpression.Expression);
+                var modelLambdaCompiled = (Func<object?>)modelLambda.Compile();
+                var result = modelLambdaCompiled();
+                if (result is null)
+                {
+                    throw new ArgumentException("The provided expression must evaluate to a non-null value.");
+                }
+                model = result;
+            }
+            else
+            {
+                throw new ArgumentException($"The provided expression contains a {accessorBody.GetType().Name} which is not supported. {nameof(FieldIdentifier)} only supports simple member accessors (fields, properties) of an object.");
             }
         }
     }

+ 1 - 1
src/Components/Forms/src/FieldState.cs

@@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Components.Forms
         // we can quickly evaluate the list of messages for the field without having to query all stores. This is
         // relevant because each validation component may define its own message store, so there might be as many
         // stores are there are fields or UI elements.
-        private HashSet<ValidationMessageStore> _validationMessageStores;
+        private HashSet<ValidationMessageStore>? _validationMessageStores;
 
         public FieldState(FieldIdentifier fieldIdentifier)
         {

+ 2 - 1
src/Components/Forms/src/Microsoft.AspNetCore.Components.Forms.csproj

@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
     <TargetFrameworks>netstandard2.0;$(DefaultNetCoreTargetFramework)</TargetFrameworks>
@@ -6,6 +6,7 @@
     <IsAspNetCoreApp>true</IsAspNetCoreApp>
     <Description>Forms and validation support for Blazor applications.</Description>
     <GenerateDocumentationFile>true</GenerateDocumentationFile>
+    <Nullable>enable</Nullable>
   </PropertyGroup>
 
   <ItemGroup>

+ 2 - 2
src/Components/Forms/src/ValidationMessageStore.cs

@@ -120,9 +120,9 @@ namespace Microsoft.AspNetCore.Components.Forms
         }
 
         private void AssociateWithField(in FieldIdentifier fieldIdentifier)
-            => _editContext.GetFieldState(fieldIdentifier, ensureExists: true).AssociateWithValidationMessageStore(this);
+            => _editContext.GetOrAddFieldState(fieldIdentifier).AssociateWithValidationMessageStore(this);
 
         private void DissociateFromField(in FieldIdentifier fieldIdentifier)
-            => _editContext.GetFieldState(fieldIdentifier, ensureExists: false)?.DissociateFromValidationMessageStore(this);
+            => _editContext.GetFieldState(fieldIdentifier)?.DissociateFromValidationMessageStore(this);
     }
 }

+ 1 - 0
src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.csproj

@@ -2,6 +2,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <TargetFrameworks>$(DefaultNetCoreTargetFramework)</TargetFrameworks>
+    <Nullable>annotations</Nullable>
   </PropertyGroup>
   <ItemGroup Condition="'$(TargetFramework)' == '$(DefaultNetCoreTargetFramework)'">
     <Compile Include="Microsoft.AspNetCore.Components.Server.netcoreapp.cs" />

+ 1 - 1
src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.netcoreapp.cs

@@ -63,7 +63,7 @@ namespace Microsoft.Extensions.DependencyInjection
 {
     public static partial class ComponentServiceCollectionExtensions
     {
-        public static Microsoft.Extensions.DependencyInjection.IServerSideBlazorBuilder AddServerSideBlazor(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action<Microsoft.AspNetCore.Components.Server.CircuitOptions> configure = null) { throw null; }
+        public static Microsoft.Extensions.DependencyInjection.IServerSideBlazorBuilder AddServerSideBlazor(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action<Microsoft.AspNetCore.Components.Server.CircuitOptions>? configure = null) { throw null; }
     }
     public partial interface IServerSideBlazorBuilder
     {

+ 1 - 1
src/Components/Server/src/DependencyInjection/ComponentServiceCollectionExtensions.cs

@@ -27,7 +27,7 @@ namespace Microsoft.Extensions.DependencyInjection
         /// <param name="services">The <see cref="IServiceCollection"/>.</param>
         /// <param name="configure">A callback to configure <see cref="CircuitOptions"/>.</param>
         /// <returns>An <see cref="IServerSideBlazorBuilder"/> that can be used to further customize the configuration.</returns>
-        public static IServerSideBlazorBuilder AddServerSideBlazor(this IServiceCollection services, Action<CircuitOptions> configure = null)
+        public static IServerSideBlazorBuilder AddServerSideBlazor(this IServiceCollection services, Action<CircuitOptions>? configure = null)
         {
             var builder = new DefaultServerSideBlazorBuilder(services);
 

+ 4 - 2
src/Components/Server/src/DependencyInjection/ServerSideBlazorBuilderExtensions.cs

@@ -48,11 +48,13 @@ namespace Microsoft.Extensions.DependencyInjection
                 throw new ArgumentNullException(nameof(builder));
             }
 
-            if (configure != null)
+            if (configure == null)
             {
-                builder.Services.Configure<HubOptions<ComponentHub>>(configure);
+                throw new ArgumentNullException(nameof(configure));
             }
 
+            builder.Services.Configure<HubOptions<ComponentHub>>(configure);
+
             return builder;
         }
     }

+ 2 - 1
src/Components/Server/src/Microsoft.AspNetCore.Components.Server.csproj

@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
     <Description>Runtime server features for ASP.NET Core Components.</Description>
@@ -10,6 +10,7 @@
     <DefineConstants>$(DefineConstants);ENABLE_UNSAFE_MSGPACK;SPAN_BUILTIN;MESSAGEPACK_INTERNAL;COMPONENTS_SERVER</DefineConstants>
     <IsPackable>false</IsPackable>
     <EmbeddedFilesManifestFileName>Microsoft.Extensions.FileProviders.Embedded.Manifest.xml</EmbeddedFilesManifestFileName>
+    <Nullable>annotations</Nullable>
   </PropertyGroup>
 
   <ItemGroup>

+ 1 - 0
src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.csproj

@@ -3,6 +3,7 @@
   <PropertyGroup>
     <TargetFrameworks>netstandard2.0;$(DefaultNetCoreTargetFramework)</TargetFrameworks>
     <TargetFrameworks Condition="'$(DotNetBuildFromSource)' == 'true'">$(DefaultNetCoreTargetFramework)</TargetFrameworks>
+    <Nullable>annotations</Nullable>
   </PropertyGroup>
   <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
     <Compile Include="Microsoft.AspNetCore.Components.Web.netstandard2.0.cs" />

+ 43 - 39
src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netcoreapp.cs

@@ -6,13 +6,13 @@ namespace Microsoft.AspNetCore.Components
     [System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=true, Inherited=true)]
     public sealed partial class BindInputElementAttribute : System.Attribute
     {
-        public BindInputElementAttribute(string type, string suffix, string valueAttribute, string changeAttribute, bool isInvariantCulture, string format) { }
-        public string ChangeAttribute { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
-        public string Format { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
+        public BindInputElementAttribute(string? type, string? suffix, string? valueAttribute, string? changeAttribute, bool isInvariantCulture, string? format) { }
+        public string? ChangeAttribute { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
+        public string? Format { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
         public bool IsInvariantCulture { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
-        public string Suffix { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
-        public string Type { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
-        public string ValueAttribute { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
+        public string? Suffix { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
+        public string? Type { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
+        public string? ValueAttribute { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
     }
 }
 namespace Microsoft.AspNetCore.Components.Forms
@@ -26,13 +26,13 @@ namespace Microsoft.AspNetCore.Components.Forms
     {
         public EditForm() { }
         [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)]
-        public System.Collections.Generic.IReadOnlyDictionary<string, object> AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public System.Collections.Generic.IReadOnlyDictionary<string, object>? AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
-        public Microsoft.AspNetCore.Components.RenderFragment<Microsoft.AspNetCore.Components.Forms.EditContext> ChildContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public Microsoft.AspNetCore.Components.RenderFragment<Microsoft.AspNetCore.Components.Forms.EditContext>? ChildContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
-        public Microsoft.AspNetCore.Components.Forms.EditContext EditContext { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public Microsoft.AspNetCore.Components.Forms.EditContext? EditContext { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
-        public object Model { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public object? Model { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
         public Microsoft.AspNetCore.Components.EventCallback<Microsoft.AspNetCore.Components.Forms.EditContext> OnInvalidSubmit { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
@@ -46,29 +46,33 @@ namespace Microsoft.AspNetCore.Components.Forms
     {
         protected InputBase() { }
         [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)]
-        public System.Collections.Generic.IReadOnlyDictionary<string, object> AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public System.Collections.Generic.IReadOnlyDictionary<string, object>? AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         protected string CssClass { get { throw null; } }
+        [System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
+        [System.Diagnostics.CodeAnalysis.AllowNullAttribute]
         protected TValue CurrentValue { get { throw null; } set { } }
-        protected string CurrentValueAsString { get { throw null; } set { } }
+        protected string? CurrentValueAsString { get { throw null; } set { } }
         protected Microsoft.AspNetCore.Components.Forms.EditContext EditContext { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         protected Microsoft.AspNetCore.Components.Forms.FieldIdentifier FieldIdentifier { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
+        [System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
+        [System.Diagnostics.CodeAnalysis.AllowNullAttribute]
         public TValue Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
         public Microsoft.AspNetCore.Components.EventCallback<TValue> ValueChanged { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
-        public System.Linq.Expressions.Expression<System.Func<TValue>> ValueExpression { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public System.Linq.Expressions.Expression<System.Func<TValue>>? ValueExpression { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         protected virtual void Dispose(bool disposing) { }
-        protected virtual string FormatValueAsString(TValue value) { throw null; }
+        protected virtual string? FormatValueAsString(TValue value) { throw null; }
         public override System.Threading.Tasks.Task SetParametersAsync(Microsoft.AspNetCore.Components.ParameterView parameters) { throw null; }
         void System.IDisposable.Dispose() { }
-        protected abstract bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage);
+        protected abstract bool TryParseValueFromString(string? value, [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] out TValue result, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(false)] out string? validationErrorMessage);
     }
     public partial class InputCheckbox : Microsoft.AspNetCore.Components.Forms.InputBase<bool>
     {
         public InputCheckbox() { }
         protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
-        protected override bool TryParseValueFromString(string value, out bool result, out string validationErrorMessage) { throw null; }
+        protected override bool TryParseValueFromString(string? value, out bool result, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(false)] out string? validationErrorMessage) { throw null; }
     }
     public partial class InputDate<TValue> : Microsoft.AspNetCore.Components.Forms.InputBase<TValue>
     {
@@ -77,7 +81,7 @@ namespace Microsoft.AspNetCore.Components.Forms
         public string ParsingErrorMessage { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
         protected override string FormatValueAsString(TValue value) { throw null; }
-        protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage) { throw null; }
+        protected override bool TryParseValueFromString(string? value, [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] out TValue result, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(false)] out string? validationErrorMessage) { throw null; }
     }
     public partial class InputNumber<TValue> : Microsoft.AspNetCore.Components.Forms.InputBase<TValue>
     {
@@ -85,36 +89,36 @@ namespace Microsoft.AspNetCore.Components.Forms
         [Microsoft.AspNetCore.Components.ParameterAttribute]
         public string ParsingErrorMessage { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
-        protected override string FormatValueAsString(TValue value) { throw null; }
-        protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage) { throw null; }
+        protected override string? FormatValueAsString(TValue value) { throw null; }
+        protected override bool TryParseValueFromString(string? value, [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] out TValue result, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(false)] out string? validationErrorMessage) { throw null; }
     }
     public partial class InputSelect<TValue> : Microsoft.AspNetCore.Components.Forms.InputBase<TValue>
     {
         public InputSelect() { }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
-        public Microsoft.AspNetCore.Components.RenderFragment ChildContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public Microsoft.AspNetCore.Components.RenderFragment? ChildContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
-        protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage) { throw null; }
+        protected override bool TryParseValueFromString(string? value, [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] out TValue result, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(false)] out string? validationErrorMessage) { throw null; }
     }
-    public partial class InputText : Microsoft.AspNetCore.Components.Forms.InputBase<string>
+    public partial class InputText : Microsoft.AspNetCore.Components.Forms.InputBase<string?>
     {
         public InputText() { }
         protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
-        protected override bool TryParseValueFromString(string value, out string result, out string validationErrorMessage) { throw null; }
+        protected override bool TryParseValueFromString(string? value, out string? result, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(false)] out string? validationErrorMessage) { throw null; }
     }
-    public partial class InputTextArea : Microsoft.AspNetCore.Components.Forms.InputBase<string>
+    public partial class InputTextArea : Microsoft.AspNetCore.Components.Forms.InputBase<string?>
     {
         public InputTextArea() { }
         protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
-        protected override bool TryParseValueFromString(string value, out string result, out string validationErrorMessage) { throw null; }
+        protected override bool TryParseValueFromString(string? value, out string? result, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(false)] out string? validationErrorMessage) { throw null; }
     }
     public partial class ValidationMessage<TValue> : Microsoft.AspNetCore.Components.ComponentBase, System.IDisposable
     {
         public ValidationMessage() { }
         [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)]
-        public System.Collections.Generic.IReadOnlyDictionary<string, object> AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public System.Collections.Generic.IReadOnlyDictionary<string, object>? AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
-        public System.Linq.Expressions.Expression<System.Func<TValue>> For { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public System.Linq.Expressions.Expression<System.Func<TValue>>? For { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
         protected virtual void Dispose(bool disposing) { }
         protected override void OnParametersSet() { }
@@ -124,9 +128,9 @@ namespace Microsoft.AspNetCore.Components.Forms
     {
         public ValidationSummary() { }
         [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)]
-        public System.Collections.Generic.IReadOnlyDictionary<string, object> AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public System.Collections.Generic.IReadOnlyDictionary<string, object>? AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
-        public object Model { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public object? Model { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
         protected virtual void Dispose(bool disposing) { }
         protected override void OnParametersSet() { }
@@ -140,7 +144,7 @@ namespace Microsoft.AspNetCore.Components.RenderTree
         public WebEventDescriptor() { }
         public int BrowserRendererId { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         public string EventArgsType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
-        public Microsoft.AspNetCore.Components.RenderTree.EventFieldInfo EventFieldInfo { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public Microsoft.AspNetCore.Components.RenderTree.EventFieldInfo? EventFieldInfo { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         public ulong EventHandlerId { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
     }
 }
@@ -150,12 +154,12 @@ namespace Microsoft.AspNetCore.Components.Routing
     {
         public NavLink() { }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
-        public string ActiveClass { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public string? ActiveClass { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)]
-        public System.Collections.Generic.IReadOnlyDictionary<string, object> AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public System.Collections.Generic.IReadOnlyDictionary<string, object>? AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
-        public Microsoft.AspNetCore.Components.RenderFragment ChildContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
-        protected string CssClass { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public Microsoft.AspNetCore.Components.RenderFragment? ChildContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        protected string? CssClass { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
         public Microsoft.AspNetCore.Components.Routing.NavLinkMatch Match { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
@@ -199,7 +203,7 @@ namespace Microsoft.AspNetCore.Components.Web
     {
         public DataTransfer() { }
         public string DropEffect { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
-        public string EffectAllowed { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public string? EffectAllowed { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         public string[] Files { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         public Microsoft.AspNetCore.Components.Web.DataTransferItem[] Items { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         public string[] Types { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
@@ -219,10 +223,10 @@ namespace Microsoft.AspNetCore.Components.Web
     {
         public ErrorEventArgs() { }
         public int Colno { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
-        public string Filename { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public string? Filename { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         public int Lineno { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
-        public string Message { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
-        public string Type { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public string? Message { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public string? Type { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
     }
     [Microsoft.AspNetCore.Components.EventHandlerAttribute("onabort", typeof(Microsoft.AspNetCore.Components.Web.ProgressEventArgs), true, true)]
     [Microsoft.AspNetCore.Components.EventHandlerAttribute("onactivate", typeof(System.EventArgs), true, true)]
@@ -321,7 +325,7 @@ namespace Microsoft.AspNetCore.Components.Web
     public partial class FocusEventArgs : System.EventArgs
     {
         public FocusEventArgs() { }
-        public string Type { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public string? Type { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
     }
     public partial class KeyboardEventArgs : System.EventArgs
     {

+ 39 - 39
src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netstandard2.0.cs

@@ -6,13 +6,13 @@ namespace Microsoft.AspNetCore.Components
     [System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=true, Inherited=true)]
     public sealed partial class BindInputElementAttribute : System.Attribute
     {
-        public BindInputElementAttribute(string type, string suffix, string valueAttribute, string changeAttribute, bool isInvariantCulture, string format) { }
-        public string ChangeAttribute { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
-        public string Format { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
+        public BindInputElementAttribute(string? type, string? suffix, string? valueAttribute, string? changeAttribute, bool isInvariantCulture, string? format) { }
+        public string? ChangeAttribute { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
+        public string? Format { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
         public bool IsInvariantCulture { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
-        public string Suffix { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
-        public string Type { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
-        public string ValueAttribute { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
+        public string? Suffix { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
+        public string? Type { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
+        public string? ValueAttribute { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
     }
 }
 namespace Microsoft.AspNetCore.Components.Forms
@@ -26,13 +26,13 @@ namespace Microsoft.AspNetCore.Components.Forms
     {
         public EditForm() { }
         [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)]
-        public System.Collections.Generic.IReadOnlyDictionary<string, object> AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public System.Collections.Generic.IReadOnlyDictionary<string, object>? AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
-        public Microsoft.AspNetCore.Components.RenderFragment<Microsoft.AspNetCore.Components.Forms.EditContext> ChildContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public Microsoft.AspNetCore.Components.RenderFragment<Microsoft.AspNetCore.Components.Forms.EditContext>? ChildContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
-        public Microsoft.AspNetCore.Components.Forms.EditContext EditContext { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public Microsoft.AspNetCore.Components.Forms.EditContext? EditContext { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
-        public object Model { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public object? Model { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
         public Microsoft.AspNetCore.Components.EventCallback<Microsoft.AspNetCore.Components.Forms.EditContext> OnInvalidSubmit { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
@@ -46,10 +46,10 @@ namespace Microsoft.AspNetCore.Components.Forms
     {
         protected InputBase() { }
         [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)]
-        public System.Collections.Generic.IReadOnlyDictionary<string, object> AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public System.Collections.Generic.IReadOnlyDictionary<string, object>? AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         protected string CssClass { get { throw null; } }
         protected TValue CurrentValue { get { throw null; } set { } }
-        protected string CurrentValueAsString { get { throw null; } set { } }
+        protected string? CurrentValueAsString { get { throw null; } set { } }
         protected Microsoft.AspNetCore.Components.Forms.EditContext EditContext { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         protected Microsoft.AspNetCore.Components.Forms.FieldIdentifier FieldIdentifier { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
@@ -57,18 +57,18 @@ namespace Microsoft.AspNetCore.Components.Forms
         [Microsoft.AspNetCore.Components.ParameterAttribute]
         public Microsoft.AspNetCore.Components.EventCallback<TValue> ValueChanged { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
-        public System.Linq.Expressions.Expression<System.Func<TValue>> ValueExpression { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public System.Linq.Expressions.Expression<System.Func<TValue>>? ValueExpression { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         protected virtual void Dispose(bool disposing) { }
-        protected virtual string FormatValueAsString(TValue value) { throw null; }
+        protected virtual string? FormatValueAsString(TValue value) { throw null; }
         public override System.Threading.Tasks.Task SetParametersAsync(Microsoft.AspNetCore.Components.ParameterView parameters) { throw null; }
         void System.IDisposable.Dispose() { }
-        protected abstract bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage);
+        protected abstract bool TryParseValueFromString(string? value, out TValue result, out string? validationErrorMessage);
     }
     public partial class InputCheckbox : Microsoft.AspNetCore.Components.Forms.InputBase<bool>
     {
         public InputCheckbox() { }
         protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
-        protected override bool TryParseValueFromString(string value, out bool result, out string validationErrorMessage) { throw null; }
+        protected override bool TryParseValueFromString(string? value, out bool result, out string? validationErrorMessage) { throw null; }
     }
     public partial class InputDate<TValue> : Microsoft.AspNetCore.Components.Forms.InputBase<TValue>
     {
@@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Components.Forms
         public string ParsingErrorMessage { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
         protected override string FormatValueAsString(TValue value) { throw null; }
-        protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage) { throw null; }
+        protected override bool TryParseValueFromString(string? value, out TValue result, out string? validationErrorMessage) { throw null; }
     }
     public partial class InputNumber<TValue> : Microsoft.AspNetCore.Components.Forms.InputBase<TValue>
     {
@@ -85,36 +85,36 @@ namespace Microsoft.AspNetCore.Components.Forms
         [Microsoft.AspNetCore.Components.ParameterAttribute]
         public string ParsingErrorMessage { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
-        protected override string FormatValueAsString(TValue value) { throw null; }
-        protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage) { throw null; }
+        protected override string? FormatValueAsString(TValue value) { throw null; }
+        protected override bool TryParseValueFromString(string? value, out TValue result, out string? validationErrorMessage) { throw null; }
     }
     public partial class InputSelect<TValue> : Microsoft.AspNetCore.Components.Forms.InputBase<TValue>
     {
         public InputSelect() { }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
-        public Microsoft.AspNetCore.Components.RenderFragment ChildContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public Microsoft.AspNetCore.Components.RenderFragment? ChildContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
-        protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage) { throw null; }
+        protected override bool TryParseValueFromString(string? value, out TValue result, out string? validationErrorMessage) { throw null; }
     }
-    public partial class InputText : Microsoft.AspNetCore.Components.Forms.InputBase<string>
+    public partial class InputText : Microsoft.AspNetCore.Components.Forms.InputBase<string?>
     {
         public InputText() { }
         protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
-        protected override bool TryParseValueFromString(string value, out string result, out string validationErrorMessage) { throw null; }
+        protected override bool TryParseValueFromString(string? value, out string? result, out string? validationErrorMessage) { throw null; }
     }
-    public partial class InputTextArea : Microsoft.AspNetCore.Components.Forms.InputBase<string>
+    public partial class InputTextArea : Microsoft.AspNetCore.Components.Forms.InputBase<string?>
     {
         public InputTextArea() { }
         protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
-        protected override bool TryParseValueFromString(string value, out string result, out string validationErrorMessage) { throw null; }
+        protected override bool TryParseValueFromString(string? value, out string? result, out string? validationErrorMessage) { throw null; }
     }
     public partial class ValidationMessage<TValue> : Microsoft.AspNetCore.Components.ComponentBase, System.IDisposable
     {
         public ValidationMessage() { }
         [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)]
-        public System.Collections.Generic.IReadOnlyDictionary<string, object> AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public System.Collections.Generic.IReadOnlyDictionary<string, object>? AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
-        public System.Linq.Expressions.Expression<System.Func<TValue>> For { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public System.Linq.Expressions.Expression<System.Func<TValue>>? For { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
         protected virtual void Dispose(bool disposing) { }
         protected override void OnParametersSet() { }
@@ -124,9 +124,9 @@ namespace Microsoft.AspNetCore.Components.Forms
     {
         public ValidationSummary() { }
         [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)]
-        public System.Collections.Generic.IReadOnlyDictionary<string, object> AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public System.Collections.Generic.IReadOnlyDictionary<string, object>? AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
-        public object Model { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public object? Model { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
         protected virtual void Dispose(bool disposing) { }
         protected override void OnParametersSet() { }
@@ -140,7 +140,7 @@ namespace Microsoft.AspNetCore.Components.RenderTree
         public WebEventDescriptor() { }
         public int BrowserRendererId { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         public string EventArgsType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
-        public Microsoft.AspNetCore.Components.RenderTree.EventFieldInfo EventFieldInfo { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public Microsoft.AspNetCore.Components.RenderTree.EventFieldInfo? EventFieldInfo { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         public ulong EventHandlerId { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
     }
 }
@@ -150,12 +150,12 @@ namespace Microsoft.AspNetCore.Components.Routing
     {
         public NavLink() { }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
-        public string ActiveClass { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public string? ActiveClass { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)]
-        public System.Collections.Generic.IReadOnlyDictionary<string, object> AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public System.Collections.Generic.IReadOnlyDictionary<string, object>? AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
-        public Microsoft.AspNetCore.Components.RenderFragment ChildContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
-        protected string CssClass { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public Microsoft.AspNetCore.Components.RenderFragment? ChildContent { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        protected string? CssClass { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         [Microsoft.AspNetCore.Components.ParameterAttribute]
         public Microsoft.AspNetCore.Components.Routing.NavLinkMatch Match { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) { }
@@ -199,7 +199,7 @@ namespace Microsoft.AspNetCore.Components.Web
     {
         public DataTransfer() { }
         public string DropEffect { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
-        public string EffectAllowed { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public string? EffectAllowed { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         public string[] Files { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         public Microsoft.AspNetCore.Components.Web.DataTransferItem[] Items { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         public string[] Types { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
@@ -219,10 +219,10 @@ namespace Microsoft.AspNetCore.Components.Web
     {
         public ErrorEventArgs() { }
         public int Colno { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
-        public string Filename { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public string? Filename { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
         public int Lineno { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
-        public string Message { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
-        public string Type { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public string? Message { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public string? Type { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
     }
     [Microsoft.AspNetCore.Components.EventHandlerAttribute("onabort", typeof(Microsoft.AspNetCore.Components.Web.ProgressEventArgs), true, true)]
     [Microsoft.AspNetCore.Components.EventHandlerAttribute("onactivate", typeof(System.EventArgs), true, true)]
@@ -321,7 +321,7 @@ namespace Microsoft.AspNetCore.Components.Web
     public partial class FocusEventArgs : System.EventArgs
     {
         public FocusEventArgs() { }
-        public string Type { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
+        public string? Type { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
     }
     public partial class KeyboardEventArgs : System.EventArgs
     {

+ 6 - 6
src/Components/Web/src/BindInputElementAttribute.cs

@@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Components
         /// <param name="format">
         /// An optional format to use when converting values. 
         /// </param>
-        public BindInputElementAttribute(string type, string suffix, string valueAttribute, string changeAttribute, bool isInvariantCulture, string format)
+        public BindInputElementAttribute(string? type, string? suffix, string? valueAttribute, string? changeAttribute, bool isInvariantCulture, string? format)
         {
             if (valueAttribute == null)
             {
@@ -48,22 +48,22 @@ namespace Microsoft.AspNetCore.Components
         /// <summary>
         /// Gets the value of the element's <c>type</c> attribute.
         /// </summary>
-        public string Type { get; }
+        public string? Type { get; }
         
         /// <summary>
         /// Gets the suffix value.
         /// </summary>
-        public string Suffix { get; }
+        public string? Suffix { get; }
 
         /// <summary>
         /// Gets the name of the value attribute to be bound.
         /// </summary>
-        public string ValueAttribute { get; }
+        public string? ValueAttribute { get; }
 
         /// <summary>
         /// Gets the name of an attribute that will register an associated change event.
         /// </summary>
-        public string ChangeAttribute { get; }
+        public string? ChangeAttribute { get; }
 
         /// <summary>
         /// Gets a value that determines whether binding will use <see cref="CultureInfo.InvariantCulture" /> or
@@ -74,6 +74,6 @@ namespace Microsoft.AspNetCore.Components
         /// <summary>
         /// Gets an optional format to use when converting values.
         /// </summary>
-        public string Format { get; }
+        public string? Format { get; }
     }
 }

+ 11 - 6
src/Components/Web/src/Forms/EditForm.cs

@@ -3,6 +3,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Threading.Tasks;
 using Microsoft.AspNetCore.Components.Rendering;
 
@@ -15,7 +16,7 @@ namespace Microsoft.AspNetCore.Components.Forms
     {
         private readonly Func<Task> _handleSubmitDelegate; // Cache to avoid per-render allocations
 
-        private EditContext _fixedEditContext;
+        private EditContext? _fixedEditContext;
 
         /// <summary>
         /// Constructs an instance of <see cref="EditForm"/>.
@@ -28,26 +29,26 @@ namespace Microsoft.AspNetCore.Components.Forms
         /// <summary>
         /// Gets or sets a collection of additional attributes that will be applied to the created <c>form</c> element.
         /// </summary>
-        [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary<string, object> AdditionalAttributes { get; set; }
+        [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary<string, object>? AdditionalAttributes { get; set; }
 
         /// <summary>
         /// Supplies the edit context explicitly. If using this parameter, do not
         /// also supply <see cref="Model"/>, since the model value will be taken
         /// from the <see cref="EditContext.Model"/> property.
         /// </summary>
-        [Parameter] public EditContext EditContext { get; set; }
+        [Parameter] public EditContext? EditContext { get; set; }
 
         /// <summary>
         /// Specifies the top-level model object for the form. An edit context will
         /// be constructed for this model. If using this parameter, do not also supply
         /// a value for <see cref="EditContext"/>.
         /// </summary>
-        [Parameter] public object Model { get; set; }
+        [Parameter] public object? Model { get; set; }
 
         /// <summary>
         /// Specifies the content to be rendered inside this <see cref="EditForm"/>.
         /// </summary>
-        [Parameter] public RenderFragment<EditContext> ChildContent { get; set; }
+        [Parameter] public RenderFragment<EditContext>? ChildContent { get; set; }
 
         /// <summary>
         /// A callback that will be invoked when the form is submitted.
@@ -92,13 +93,15 @@ namespace Microsoft.AspNetCore.Components.Forms
             // potentially new EditContext, or if they are supplying a different Model
             if (_fixedEditContext == null || EditContext != null || Model != _fixedEditContext.Model)
             {
-                _fixedEditContext = EditContext ?? new EditContext(Model);
+                _fixedEditContext = EditContext ?? new EditContext(Model!);
             }
         }
 
         /// <inheritdoc />
         protected override void BuildRenderTree(RenderTreeBuilder builder)
         {
+            Debug.Assert(_fixedEditContext != null);
+
             // If _fixedEditContext changes, tear down and recreate all descendants.
             // This is so we can safely use the IsFixed optimization on CascadingValue,
             // optimizing for the common case where _fixedEditContext never changes.
@@ -119,6 +122,8 @@ namespace Microsoft.AspNetCore.Components.Forms
 
         private async Task HandleSubmitAsync()
         {
+            Debug.Assert(_fixedEditContext != null);
+
             if (OnSubmit.HasDelegate)
             {
                 // When using OnSubmit, the developer takes control of the validation lifecycle

+ 25 - 23
src/Components/Web/src/Forms/InputBase.cs

@@ -3,6 +3,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
 using System.Linq;
 using System.Linq.Expressions;
 using System.Threading.Tasks;
@@ -18,15 +19,15 @@ namespace Microsoft.AspNetCore.Components.Forms
     {
         private readonly EventHandler<ValidationStateChangedEventArgs> _validationStateChangedHandler;
         private bool _previousParsingAttemptFailed;
-        private ValidationMessageStore _parsingValidationMessages;
-        private Type _nullableUnderlyingType;
+        private ValidationMessageStore? _parsingValidationMessages;
+        private Type? _nullableUnderlyingType;
 
-        [CascadingParameter] EditContext CascadedEditContext { get; set; }
+        [CascadingParameter] EditContext CascadedEditContext { get; set; } = default!;
 
         /// <summary>
         /// Gets or sets a collection of additional attributes that will be applied to the created element.
         /// </summary>
-        [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary<string, object> AdditionalAttributes { get; set; }
+        [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary<string, object>? AdditionalAttributes { get; set; }
 
         /// <summary>
         /// Gets or sets the value of the input. This should be used with two-way binding.
@@ -34,7 +35,10 @@ namespace Microsoft.AspNetCore.Components.Forms
         /// <example>
         /// @bind-Value="model.PropertyName"
         /// </example>
-        [Parameter] public TValue Value { get; set; }
+        [AllowNull]
+        [MaybeNull]
+        [Parameter]
+        public TValue Value { get; set; } = default;
 
         /// <summary>
         /// Gets or sets a callback that updates the bound value.
@@ -44,12 +48,12 @@ namespace Microsoft.AspNetCore.Components.Forms
         /// <summary>
         /// Gets or sets an expression that identifies the bound value.
         /// </summary>
-        [Parameter] public Expression<Func<TValue>> ValueExpression { get; set; }
+        [Parameter] public Expression<Func<TValue>>? ValueExpression { get; set; }
 
         /// <summary>
         /// Gets the associated <see cref="Forms.EditContext"/>.
         /// </summary>
-        protected EditContext EditContext { get; set; }
+        protected EditContext EditContext { get; set; } = default!;
 
         /// <summary>
         /// Gets the <see cref="FieldIdentifier"/> for the bound value.
@@ -59,16 +63,18 @@ namespace Microsoft.AspNetCore.Components.Forms
         /// <summary>
         /// Gets or sets the current value of the input.
         /// </summary>
+        [AllowNull]
         protected TValue CurrentValue
         {
-            get => Value;
+            [return: MaybeNull]
+            get => Value!;
             set
             {
                 var hasChanged = !EqualityComparer<TValue>.Default.Equals(value, Value);
                 if (hasChanged)
                 {
-                    Value = value;
-                    _ = ValueChanged.InvokeAsync(value);
+                    Value = value!;
+                    _ = ValueChanged.InvokeAsync(Value);
                     EditContext.NotifyFieldChanged(FieldIdentifier);
                 }
             }
@@ -77,7 +83,7 @@ namespace Microsoft.AspNetCore.Components.Forms
         /// <summary>
         /// Gets or sets the current value of the input, represented as a string.
         /// </summary>
-        protected string CurrentValueAsString
+        protected string? CurrentValueAsString
         {
             get => FormatValueAsString(CurrentValue);
             set
@@ -92,12 +98,12 @@ namespace Microsoft.AspNetCore.Components.Forms
                     // Then all subclasses get nullable support almost automatically (they just have to
                     // not reject Nullable<T> based on the type itself).
                     parsingFailed = false;
-                    CurrentValue = default;
+                    CurrentValue = default!;
                 }
                 else if (TryParseValueFromString(value, out var parsedValue, out var validationErrorMessage))
                 {
                     parsingFailed = false;
-                    CurrentValue = parsedValue;
+                    CurrentValue = parsedValue!;
                 }
                 else
                 {
@@ -136,7 +142,7 @@ namespace Microsoft.AspNetCore.Components.Forms
         /// </summary>
         /// <param name="value">The value to format.</param>
         /// <returns>A string representation of the value.</returns>
-        protected virtual string FormatValueAsString(TValue value)
+        protected virtual string? FormatValueAsString(TValue value)
             => value?.ToString();
 
         /// <summary>
@@ -147,7 +153,7 @@ namespace Microsoft.AspNetCore.Components.Forms
         /// <param name="result">An instance of <typeparamref name="TValue"/>.</param>
         /// <param name="validationErrorMessage">If the value could not be parsed, provides a validation error message.</param>
         /// <returns>True if the value could be parsed; otherwise false.</returns>
-        protected abstract bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage);
+        protected abstract bool TryParseValueFromString(string? value, [MaybeNull] out TValue result, [NotNullWhen(false)] out string? validationErrorMessage);
 
         /// <summary>
         /// Gets a string that indicates the status of the field being edited. This will include
@@ -223,7 +229,7 @@ namespace Microsoft.AspNetCore.Components.Forms
             return base.SetParametersAsync(ParameterView.Empty);
         }
 
-        private void OnValidateStateChanged(object sender, ValidationStateChangedEventArgs eventArgs)
+        private void OnValidateStateChanged(object? sender, ValidationStateChangedEventArgs eventArgs)
         {
             SetAdditionalAttributesIfValidationFailed();
 
@@ -255,9 +261,9 @@ namespace Microsoft.AspNetCore.Components.Forms
         /// Returns a dictionary with the same values as the specified <paramref name="source"/>.
         /// </summary>
         /// <returns>true, if a new dictrionary with copied values was created. false - otherwise.</returns>
-        private bool ConvertToDictionary(IReadOnlyDictionary<string, object> source, out Dictionary<string, object> result)
+        private bool ConvertToDictionary(IReadOnlyDictionary<string, object>? source, out Dictionary<string, object> result)
         {
-            bool newDictionaryCreated = true;
+            var newDictionaryCreated = true;
             if (source == null)
             {
                 result = new Dictionary<string, object>();
@@ -285,11 +291,7 @@ namespace Microsoft.AspNetCore.Components.Forms
 
         void IDisposable.Dispose()
         {
-            if (EditContext != null)
-            {
-                EditContext.OnValidationStateChanged -= _validationStateChangedHandler;
-            }
-
+            EditContext.OnValidationStateChanged -= _validationStateChangedHandler;
             Dispose(disposing: true);
         }
     }

+ 3 - 2
src/Components/Web/src/Forms/InputCheckbox.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.Rendering;
 
 namespace Microsoft.AspNetCore.Components.Forms
@@ -33,7 +34,7 @@ namespace Microsoft.AspNetCore.Components.Forms
         }
 
         /// <inheritdoc />
-        protected override bool TryParseValueFromString(string value, out bool result, out string validationErrorMessage)
-            => throw new NotImplementedException($"This component does not parse string inputs. Bind to the '{nameof(CurrentValue)}' property, not '{nameof(CurrentValueAsString)}'.");
+        protected override bool TryParseValueFromString(string? value, out bool result, [NotNullWhen(false)] out string? validationErrorMessage)
+            => throw new NotSupportedException($"This component does not parse string inputs. Bind to the '{nameof(CurrentValue)}' property, not '{nameof(CurrentValueAsString)}'.");
     }
 }

+ 5 - 4
src/Components/Web/src/Forms/InputDate.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 System.Globalization;
 using Microsoft.AspNetCore.Components.Rendering;
 
@@ -28,7 +29,7 @@ namespace Microsoft.AspNetCore.Components.Forms
             builder.AddAttribute(2, "type", "date");
             builder.AddAttribute(3, "class", CssClass);
             builder.AddAttribute(4, "value", BindConverter.FormatValue(CurrentValueAsString));
-            builder.AddAttribute(5, "onchange", EventCallback.Factory.CreateBinder<string>(this, __value => CurrentValueAsString = __value, CurrentValueAsString));
+            builder.AddAttribute(5, "onchange", EventCallback.Factory.CreateBinder<string?>(this, __value => CurrentValueAsString = __value, CurrentValueAsString));
             builder.CloseElement();
         }
 
@@ -47,7 +48,7 @@ namespace Microsoft.AspNetCore.Components.Forms
         }
 
         /// <inheritdoc />
-        protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage)
+        protected override bool TryParseValueFromString(string? value, [MaybeNull] out TValue result, [NotNullWhen(false)] out string? validationErrorMessage)
         {
             // Unwrap nullable types. We don't have to deal with receiving empty values for nullable
             // types here, because the underlying InputBase already covers that.
@@ -79,7 +80,7 @@ namespace Microsoft.AspNetCore.Components.Forms
             }
         }
 
-        static bool TryParseDateTime(string value, out TValue result)
+        static bool TryParseDateTime(string? value, [MaybeNullWhen(false)] out TValue result)
         {
             var success = BindConverter.TryConvertToDateTime(value, CultureInfo.InvariantCulture, DateFormat, out var parsedValue);
             if (success)
@@ -94,7 +95,7 @@ namespace Microsoft.AspNetCore.Components.Forms
             }
         }
 
-        static bool TryParseDateTimeOffset(string value, out TValue result)
+        static bool TryParseDateTimeOffset(string? value, [MaybeNullWhen(false)] out TValue result)
         {
             var success = BindConverter.TryConvertToDateTimeOffset(value, CultureInfo.InvariantCulture, DateFormat, out var parsedValue);
             if (success)

+ 4 - 3
src/Components/Web/src/Forms/InputNumber.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 System.Globalization;
 using Microsoft.AspNetCore.Components.Rendering;
 
@@ -49,12 +50,12 @@ namespace Microsoft.AspNetCore.Components.Forms
             builder.AddAttribute(3, "type", "number");
             builder.AddAttribute(4, "class", CssClass);
             builder.AddAttribute(5, "value", BindConverter.FormatValue(CurrentValueAsString));
-            builder.AddAttribute(6, "onchange", EventCallback.Factory.CreateBinder<string>(this, __value => CurrentValueAsString = __value, CurrentValueAsString));
+            builder.AddAttribute(6, "onchange", EventCallback.Factory.CreateBinder<string?>(this, __value => CurrentValueAsString = __value, CurrentValueAsString));
             builder.CloseElement();
         }
 
         /// <inheritdoc />
-        protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage)
+        protected override bool TryParseValueFromString(string? value, [MaybeNull] out TValue result, [NotNullWhen(false)] out string? validationErrorMessage)
         {
             if (BindConverter.TryConvertTo<TValue>(value, CultureInfo.InvariantCulture, out result))
             {
@@ -73,7 +74,7 @@ namespace Microsoft.AspNetCore.Components.Forms
         /// </summary>
         /// <param name="value">The value to format.</param>
         /// <returns>A string representation of the value.</returns>
-        protected override string FormatValueAsString(TValue value)
+        protected override string? FormatValueAsString(TValue value)
         {
             // Avoiding a cast to IFormattable to avoid boxing.
             switch (value)

+ 7 - 6
src/Components/Web/src/Forms/InputSelect.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 System.Globalization;
 using Microsoft.AspNetCore.Components.Rendering;
 
@@ -12,12 +13,12 @@ namespace Microsoft.AspNetCore.Components.Forms
     /// </summary>
     public class InputSelect<TValue> : InputBase<TValue>
     {
+        private static readonly Type? _nullableUnderlyingType = Nullable.GetUnderlyingType(typeof(TValue));
+
         /// <summary>
         /// Gets or sets the child content to be rendering inside the select element.
         /// </summary>
-        [Parameter] public RenderFragment ChildContent { get; set; }
-
-        private readonly Type _nullableUnderlyingType = Nullable.GetUnderlyingType(typeof(TValue));
+        [Parameter] public RenderFragment? ChildContent { get; set; }
 
         /// <inheritdoc />
         protected override void BuildRenderTree(RenderTreeBuilder builder)
@@ -26,17 +27,17 @@ namespace Microsoft.AspNetCore.Components.Forms
             builder.AddMultipleAttributes(1, AdditionalAttributes);
             builder.AddAttribute(2, "class", CssClass);
             builder.AddAttribute(3, "value", BindConverter.FormatValue(CurrentValueAsString));
-            builder.AddAttribute(4, "onchange", EventCallback.Factory.CreateBinder<string>(this, __value => CurrentValueAsString = __value, CurrentValueAsString));
+            builder.AddAttribute(4, "onchange", EventCallback.Factory.CreateBinder<string?>(this, __value => CurrentValueAsString = __value, CurrentValueAsString));
             builder.AddContent(5, ChildContent);
             builder.CloseElement();
         }
 
         /// <inheritdoc />
-        protected override bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage)
+        protected override bool TryParseValueFromString(string? value, [MaybeNull] out TValue result, [NotNullWhen(false)] out string? validationErrorMessage)
         {
             if (typeof(TValue) == typeof(string))
             {
-                result = (TValue)(object)value;
+                result = (TValue)(object?)value;
                 validationErrorMessage = null;
                 return true;
             }

+ 4 - 3
src/Components/Web/src/Forms/InputText.cs

@@ -1,6 +1,7 @@
 // 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;
 using Microsoft.AspNetCore.Components.Rendering;
 
 namespace Microsoft.AspNetCore.Components.Forms
@@ -17,7 +18,7 @@ namespace Microsoft.AspNetCore.Components.Forms
     /// <summary>
     /// An input component for editing <see cref="string"/> values.
     /// </summary>
-    public class InputText : InputBase<string>
+    public class InputText : InputBase<string?>
     {
         /// <inheritdoc />
         protected override void BuildRenderTree(RenderTreeBuilder builder)
@@ -26,12 +27,12 @@ namespace Microsoft.AspNetCore.Components.Forms
             builder.AddMultipleAttributes(1, AdditionalAttributes);
             builder.AddAttribute(2, "class", CssClass);
             builder.AddAttribute(3, "value", BindConverter.FormatValue(CurrentValue));
-            builder.AddAttribute(4, "onchange", EventCallback.Factory.CreateBinder<string>(this, __value => CurrentValueAsString = __value, CurrentValueAsString));
+            builder.AddAttribute(4, "onchange", EventCallback.Factory.CreateBinder<string?>(this, __value => CurrentValueAsString = __value, CurrentValueAsString));
             builder.CloseElement();
         }
 
         /// <inheritdoc />
-        protected override bool TryParseValueFromString(string value, out string result, out string validationErrorMessage)
+        protected override bool TryParseValueFromString(string? value, out string? result, [NotNullWhen(false)] out string? validationErrorMessage)
         {
             result = value;
             validationErrorMessage = null;

+ 4 - 3
src/Components/Web/src/Forms/InputTextArea.cs

@@ -1,6 +1,7 @@
 // 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;
 using Microsoft.AspNetCore.Components.Rendering;
 
 namespace Microsoft.AspNetCore.Components.Forms
@@ -17,7 +18,7 @@ namespace Microsoft.AspNetCore.Components.Forms
     /// <summary>
     /// A multiline input component for editing <see cref="string"/> values.
     /// </summary>
-    public class InputTextArea : InputBase<string>
+    public class InputTextArea : InputBase<string?>
     {
         /// <inheritdoc />
         protected override void BuildRenderTree(RenderTreeBuilder builder)
@@ -26,12 +27,12 @@ namespace Microsoft.AspNetCore.Components.Forms
             builder.AddMultipleAttributes(1, AdditionalAttributes);
             builder.AddAttribute(2, "class", CssClass);
             builder.AddAttribute(3, "value", BindConverter.FormatValue(CurrentValue));
-            builder.AddAttribute(4, "onchange", EventCallback.Factory.CreateBinder<string>(this, __value => CurrentValueAsString = __value, CurrentValueAsString));
+            builder.AddAttribute(4, "onchange", EventCallback.Factory.CreateBinder<string?>(this, __value => CurrentValueAsString = __value, CurrentValueAsString));
             builder.CloseElement();
         }
 
         /// <inheritdoc />
-        protected override bool TryParseValueFromString(string value, out string result, out string validationErrorMessage)
+        protected override bool TryParseValueFromString(string? value, out string? result, [NotNullWhen(false)] out string? validationErrorMessage)
         {
             result = value;
             validationErrorMessage = null;

+ 6 - 6
src/Components/Web/src/Forms/ValidationMessage.cs

@@ -13,22 +13,22 @@ namespace Microsoft.AspNetCore.Components.Forms
     /// </summary>
     public class ValidationMessage<TValue> : ComponentBase, IDisposable
     {
-        private EditContext _previousEditContext;
-        private Expression<Func<TValue>> _previousFieldAccessor;
-        private readonly EventHandler<ValidationStateChangedEventArgs> _validationStateChangedHandler;
+        private EditContext? _previousEditContext;
+        private Expression<Func<TValue>>? _previousFieldAccessor;
+        private readonly EventHandler<ValidationStateChangedEventArgs>? _validationStateChangedHandler;
         private FieldIdentifier _fieldIdentifier;
 
         /// <summary>
         /// Gets or sets a collection of additional attributes that will be applied to the created <c>div</c> element.
         /// </summary>
-        [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary<string, object> AdditionalAttributes { get; set; }
+        [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary<string, object>? AdditionalAttributes { get; set; }
 
-        [CascadingParameter] EditContext CurrentEditContext { get; set; }
+        [CascadingParameter] EditContext CurrentEditContext { get; set; } = default!;
 
         /// <summary>
         /// Specifies the field for which validation messages should be displayed.
         /// </summary>
-        [Parameter] public Expression<Func<TValue>> For { get; set; }
+        [Parameter] public Expression<Func<TValue>>? For { get; set; }
 
         /// <summary>`
         /// Constructs an instance of <see cref="ValidationMessage{TValue}"/>.

+ 4 - 4
src/Components/Web/src/Forms/ValidationSummary.cs

@@ -16,21 +16,21 @@ namespace Microsoft.AspNetCore.Components.Forms
     /// </summary>
     public class ValidationSummary : ComponentBase, IDisposable
     {
-        private EditContext _previousEditContext;
+        private EditContext? _previousEditContext;
         private readonly EventHandler<ValidationStateChangedEventArgs> _validationStateChangedHandler;
 
         /// <summary>
         /// Gets or sets the model to produce the list of validation messages for.
         /// When specified, this lists all errors that are associated with the model instance.
         /// </summary>
-        [Parameter] public object Model { get; set; }
+        [Parameter] public object? Model { get; set; }
 
         /// <summary>
         /// Gets or sets a collection of additional attributes that will be applied to the created <c>ul</c> element.
         /// </summary>
-        [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary<string, object> AdditionalAttributes { get; set; }
+        [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary<string, object>? AdditionalAttributes { get; set; }
 
-        [CascadingParameter] EditContext CurrentEditContext { get; set; }
+        [CascadingParameter] EditContext CurrentEditContext { get; set; } = default!;
 
         /// <summary>`
         /// Constructs an instance of <see cref="ValidationSummary"/>.

+ 2 - 1
src/Components/Web/src/Microsoft.AspNetCore.Components.Web.csproj

@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
     <TargetFrameworks>netstandard2.0;$(DefaultNetCoreTargetFramework)</TargetFrameworks>
@@ -7,6 +7,7 @@
     <Description>Support for rendering ASP.NET Core components for browsers.</Description>
     <GenerateDocumentationFile>true</GenerateDocumentationFile>
     <RootNamespace>Microsoft.AspNetCore.Components</RootNamespace>
+    <Nullable>enable</Nullable>
   </PropertyGroup>
 
   <ItemGroup>

+ 15 - 14
src/Components/Web/src/Routing/NavLink.cs

@@ -3,7 +3,7 @@
 
 using System;
 using System.Collections.Generic;
-using System.Threading.Tasks;
+using System.Diagnostics;
 using Microsoft.AspNetCore.Components.Rendering;
 
 namespace Microsoft.AspNetCore.Components.Routing
@@ -17,33 +17,33 @@ namespace Microsoft.AspNetCore.Components.Routing
         private const string DefaultActiveClass = "active";
 
         private bool _isActive;
-        private string _hrefAbsolute;
-        private string _class;
+        private string? _hrefAbsolute;
+        private string? _class;
 
         /// <summary>
         /// Gets or sets the CSS class name applied to the NavLink when the
         /// current route matches the NavLink href.
         /// </summary>
         [Parameter]
-        public string ActiveClass { get; set; }
+        public string? ActiveClass { get; set; }
 
         /// <summary>
         /// Gets or sets a collection of additional attributes that will be added to the generated
         /// <c>a</c> element.
         /// </summary>
         [Parameter(CaptureUnmatchedValues = true)]
-        public IReadOnlyDictionary<string, object> AdditionalAttributes { get; set; }
+        public IReadOnlyDictionary<string, object>? AdditionalAttributes { get; set; }
 
         /// <summary>
         /// Gets or sets the computed CSS class based on whether or not the link is active.
         /// </summary>
-        protected string CssClass { get; set; }
+        protected string? CssClass { get; set; }
 
         /// <summary>
         /// Gets or sets the child content of the component.
         /// </summary>
         [Parameter]
-        public RenderFragment ChildContent { get; set; }
+        public RenderFragment? ChildContent { get; set; }
 
         /// <summary>
         /// Gets or sets a value representing the URL matching behavior.
@@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Components.Routing
         [Parameter]
         public NavLinkMatch Match { get; set; }
 
-        [Inject] private NavigationManager NavigationManger { get; set; }
+        [Inject] private NavigationManager NavigationManger { get; set; } = default!;
 
         /// <inheritdoc />
         protected override void OnInitialized()
@@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Components.Routing
         protected override void OnParametersSet()
         {
             // Update computed state
-            var href = (string)null;
+            var href = (string?)null;
             if (AdditionalAttributes != null && AdditionalAttributes.TryGetValue("href", out var obj))
             {
                 href = Convert.ToString(obj);
@@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Components.Routing
             _hrefAbsolute = href == null ? null : NavigationManger.ToAbsoluteUri(href).AbsoluteUri;
             _isActive = ShouldMatch(NavigationManger.Uri);
 
-            _class = (string)null;
+            _class = (string?)null;
             if (AdditionalAttributes != null && AdditionalAttributes.TryGetValue("class", out obj))
             {
                 _class = Convert.ToString(obj);
@@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Components.Routing
             CssClass = _isActive ? CombineWithSpace(_class, ActiveClass ?? DefaultActiveClass) : _class;
         }
 
-        private void OnLocationChanged(object sender, LocationChangedEventArgs args)
+        private void OnLocationChanged(object? sender, LocationChangedEventArgs args)
         {
             // We could just re-render always, but for this component we know the
             // only relevant state change is to the _isActive property.
@@ -130,6 +130,8 @@ namespace Microsoft.AspNetCore.Components.Routing
 
         private bool EqualsHrefExactlyOrIfTrailingSlashAdded(string currentUriAbsolute)
         {
+            Debug.Assert(_hrefAbsolute != null);
+
             if (string.Equals(currentUriAbsolute, _hrefAbsolute, StringComparison.OrdinalIgnoreCase))
             {
                 return true;
@@ -166,9 +168,8 @@ namespace Microsoft.AspNetCore.Components.Routing
             builder.CloseElement();
         }
 
-        private string CombineWithSpace(string str1, string str2)
-            => str1 == null ? str2
-            : (str2 == null ? str1 : $"{str1} {str2}");
+        private string? CombineWithSpace(string? str1, string str2)
+            => str1 == null ? str2 : $"{str1} {str2}";
 
         private static bool IsStrictlyPrefixWithSeparator(string value, string prefix)
         {

+ 1 - 1
src/Components/Web/src/Web/ClipboardEventArgs.cs

@@ -13,6 +13,6 @@ namespace Microsoft.AspNetCore.Components.Web
         /// <summary>
         /// Gets or sets the type of the event.
         /// </summary>
-        public string Type { get; set; }
+        public string Type { get; set; } = default!;
     }
 }

+ 7 - 5
src/Components/Web/src/Web/DataTransfer.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.
 
+using System;
+
 namespace Microsoft.AspNetCore.Components.Web
 {
     /// <summary>
@@ -14,28 +16,28 @@ namespace Microsoft.AspNetCore.Components.Web
         /// Gets the type of drag-and-drop operation currently selected or sets the operation to a new type.
         /// The value must be none, copy, link or move.
         /// </summary>
-        public string DropEffect { get; set; }
+        public string DropEffect { get; set; } = default!;
 
         /// <summary>
         /// Provides all of the types of operations that are possible.
         /// Must be one of none, copy, copyLink, copyMove, link, linkMove, move, all or uninitialized.
         /// </summary>
-        public string EffectAllowed { get; set; }
+        public string? EffectAllowed { get; set; }
 
         /// <summary>
         /// Contains a list of all the local files available on the data transfer.
         /// If the drag operation doesn't involve dragging files, this property is an empty list.
         /// </summary>
-        public string[] Files { get; set; }
+        public string[] Files { get; set; } = Array.Empty<string>();
 
         /// <summary>
         /// Gives a <see cref="DataTransferItem"/> array which is a list of all of the drag data.
         /// </summary>
-        public DataTransferItem[] Items { get; set; }
+        public DataTransferItem[] Items { get; set; } = Array.Empty<DataTransferItem>();
 
         /// <summary>
         /// An array of <see cref="string"/> giving the formats that were set in the dragstart event.
         /// </summary>
-        public string[] Types { get; set; }
+        public string[] Types { get; set; } = Array.Empty<string>();
     }
 }

+ 2 - 2
src/Components/Web/src/Web/DataTransferItem.cs

@@ -13,11 +13,11 @@ namespace Microsoft.AspNetCore.Components.Web
         /// <summary>
         /// The kind of drag data item, string or file
         /// </summary>
-        public string Kind { get; set; }
+        public string Kind { get; set; } = default!;
 
         /// <summary>
         /// The drag data item's type, typically a MIME type
         /// </summary>
-        public string Type { get; set; }
+        public string Type { get; set; } = default!;
     }
 }

+ 1 - 1
src/Components/Web/src/Web/DragEventArgs.cs

@@ -12,6 +12,6 @@ namespace Microsoft.AspNetCore.Components.Web
         /// The data that underlies a drag-and-drop operation, known as the drag data store.
         /// See <see cref="DataTransfer"/>.
         /// </summary>
-        public DataTransfer DataTransfer { get; set; }
+        public DataTransfer DataTransfer { get; set; } = default!;
     }
 }

+ 3 - 3
src/Components/Web/src/Web/ErrorEventArgs.cs

@@ -13,12 +13,12 @@ namespace Microsoft.AspNetCore.Components.Web
         /// <summary>
         /// Gets a a human-readable error message describing the problem.
         /// </summary>
-        public string Message { get; set; }
+        public string? Message { get; set; }
 
         /// <summary>
         /// Gets the name of the script file in which the error occurred.
         /// </summary>
-        public string Filename { get; set; }
+        public string? Filename { get; set; }
 
         /// <summary>
         /// Gets the line number of the script file on which the error occurred.
@@ -33,6 +33,6 @@ namespace Microsoft.AspNetCore.Components.Web
         /// <summary>
         /// Gets or sets the type of the event.
         /// </summary>
-        public string Type { get; set; }
+        public string? Type { get; set; }
     }
 }

+ 1 - 1
src/Components/Web/src/Web/FocusEventArgs.cs

@@ -16,6 +16,6 @@ namespace Microsoft.AspNetCore.Components.Web
         /// <summary>
         /// Gets or sets the type of the event.
         /// </summary>
-        public string Type { get; set; }
+        public string? Type { get; set; }
     }
 }

+ 3 - 3
src/Components/Web/src/Web/KeyboardEventArgs.cs

@@ -16,13 +16,13 @@ namespace Microsoft.AspNetCore.Components.Web
         /// Otherwise, it's one of the key value strings specified in 'Key values'.
         /// If the key can't be identified, this is the string "Unidentified"
         /// </summary>
-        public string Key { get; set; }
+        public string Key { get; set; } = default!;
 
         /// <summary>
         /// Holds a string that identifies the physical key being pressed.
         /// The value is not affected by the current keyboard layout or modifier state, so a particular key will always return the same value.
         /// </summary>
-        public string Code { get; set; }
+        public string Code { get; set; } = default!;
 
         /// <summary>
         /// The location of the key on the device.
@@ -57,6 +57,6 @@ namespace Microsoft.AspNetCore.Components.Web
         /// <summary>
         /// Gets or sets the type of the event.
         /// </summary>
-        public string Type { get; set; }
+        public string Type { get; set; } = default!;
     }
 }

+ 1 - 1
src/Components/Web/src/Web/MouseEventArgs.cs

@@ -89,6 +89,6 @@ namespace Microsoft.AspNetCore.Components.Web
         /// <summary>
         /// Gets or sets the type of the event.
         /// </summary>
-        public string Type { get; set; }
+        public string Type { get; set; } = default!;
     }
 }

+ 1 - 1
src/Components/Web/src/Web/PointerEventArgs.cs

@@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Components.Web
         /// Indicates the device type that caused the event.
         /// Must be one of the strings mouse, pen or touch, or an empty string.
         /// </summary>
-        public string PointerType { get; set; }
+        public string PointerType { get; set; } = default!;
 
         /// <summary>
         /// Indicates if the pointer represents the primary pointer of this pointer type.

+ 1 - 1
src/Components/Web/src/Web/ProgressEventArgs.cs

@@ -30,6 +30,6 @@ namespace Microsoft.AspNetCore.Components.Web
         /// <summary>
         /// Gets or sets the type of the event.
         /// </summary>
-        public string Type { get; set; }
+        public string Type { get; set; } = default!;
     }
 }

+ 4 - 4
src/Components/Web/src/Web/TouchEventArgs.cs

@@ -18,12 +18,12 @@ namespace Microsoft.AspNetCore.Components.Web
         /// <summary>
         /// A list of <see cref="TouchPoint"/> for every point of contact currently touching the surface.
         /// </summary>
-        public TouchPoint[] Touches { get; set; }
+        public TouchPoint[] Touches { get; set; } = Array.Empty<TouchPoint>();
 
         /// <summary>
         /// A list of <see cref="TouchPoint"/> for every point of contact that is touching the surface and started on the element that is the target of the current event.
         /// </summary>
-        public TouchPoint[] TargetTouches { get; set; }
+        public TouchPoint[] TargetTouches { get; set; } = Array.Empty<TouchPoint>();
 
         /// <summary>
         /// A list of Touches for every point of contact which contributed to the event.
@@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Components.Web
         /// For the touchmove event this must be a list of the touch points that have moved since the last event.
         /// For the touchend and touchcancel events this must be a list of the touch points that have just been removed from the surface.
         /// </summary>
-        public TouchPoint[] ChangedTouches { get; set; }
+        public TouchPoint[] ChangedTouches { get; set; } = Array.Empty<TouchPoint>();
 
         /// <summary>
         /// true if the control key was down when the event was fired. false otherwise.
@@ -56,6 +56,6 @@ namespace Microsoft.AspNetCore.Components.Web
         /// <summary>
         /// Gets or sets the type of the event.
         /// </summary>
-        public string Type { get; set; }
+        public string Type { get; set; } = default!;
     }
 }

+ 2 - 2
src/Components/Web/src/WebEventDescriptor.cs

@@ -27,11 +27,11 @@ namespace Microsoft.AspNetCore.Components.RenderTree
         /// <summary>
         /// For framework use only.
         /// </summary>
-        public string EventArgsType { get; set; }
+        public string EventArgsType { get; set; } = default!;
 
         /// <summary>
         /// For framework use only.
         /// </summary>
-        public EventFieldInfo EventFieldInfo { get; set; }
+        public EventFieldInfo? EventFieldInfo { get; set; }
     }
 }