diff --git a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp.cs b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp.cs index 3fd6df621ae8..cba973e779f3 100644 --- a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp.cs +++ b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp.cs @@ -27,7 +27,7 @@ public static partial class BindConverter 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 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 @@ public RenderTreeBuilder() { } 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(int sequence, string name, Microsoft.AspNetCore.Components.EventCallback value) { } - public void AddComponentReferenceCapture(int sequence, System.Action componentReferenceCaptureAction) { } + public void AddComponentReferenceCapture(int sequence, System.Action 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(int sequence, Microsoft.AspNetCore.Components.RenderFragment 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(int sequence, Microsoft.AspNetCore.Components.RenderFragment? fragment, TValue value) { } public void AddElementReferenceCapture(int sequence, System.Action elementReferenceCaptureAction) { } - public void AddMarkupContent(int sequence, string markupContent) { } - public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable> attributes) { } + public void AddMarkupContent(int sequence, string? markupContent) { } + public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable>? attributes) { } public void Clear() { } public void CloseComponent() { } public void CloseElement() { } public void CloseRegion() { } public Microsoft.AspNetCore.Components.RenderTree.ArrayRange GetFrames() { throw null; } public void OpenComponent(int sequence, System.Type componentType) { } - public void OpenComponent(int sequence) where TComponent : Microsoft.AspNetCore.Components.IComponent { } + public void OpenComponent(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() { } } diff --git a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs index 604a8f052ba0..a620231de7e7 100644 --- a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs +++ b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs @@ -27,7 +27,7 @@ public static partial class BindConverter 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 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 @@ public RenderTreeBuilder() { } 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(int sequence, string name, Microsoft.AspNetCore.Components.EventCallback value) { } - public void AddComponentReferenceCapture(int sequence, System.Action componentReferenceCaptureAction) { } + public void AddComponentReferenceCapture(int sequence, System.Action 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(int sequence, Microsoft.AspNetCore.Components.RenderFragment 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(int sequence, Microsoft.AspNetCore.Components.RenderFragment? fragment, TValue value) { } public void AddElementReferenceCapture(int sequence, System.Action elementReferenceCaptureAction) { } - public void AddMarkupContent(int sequence, string markupContent) { } - public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable> attributes) { } + public void AddMarkupContent(int sequence, string? markupContent) { } + public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable>? attributes) { } public void Clear() { } public void CloseComponent() { } public void CloseElement() { } public void CloseRegion() { } public Microsoft.AspNetCore.Components.RenderTree.ArrayRange GetFrames() { throw null; } public void OpenComponent(int sequence, System.Type componentType) { } - public void OpenComponent(int sequence) where TComponent : Microsoft.AspNetCore.Components.IComponent { } + public void OpenComponent(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() { } } diff --git a/src/Components/Components/src/BindConverter.cs b/src/Components/Components/src/BindConverter.cs index 68170010dc2c..57a6cacd213a 100644 --- a/src/Components/Components/src/BindConverter.cs +++ b/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 @@ public static class BindConverter /// The to use while formatting. Defaults to . /// /// The formatted value. - public static string FormatValue(string value, CultureInfo? culture = null) => FormatStringValueCore(value, culture); + public static string? FormatValue(string? value, CultureInfo? culture = null) => FormatStringValueCore(value, culture); - private static string FormatStringValueCore(string value, CultureInfo? culture) + private static string? FormatStringValueCore(string? value, CultureInfo? culture) { return value; } diff --git a/src/Components/Components/src/RenderTree/RenderTreeFrame.cs b/src/Components/Components/src/RenderTree/RenderTreeFrame.cs index 2a967eaf8eef..8fc59cfc7b0f 100644 --- a/src/Components/Components/src/RenderTree/RenderTreeFrame.cs +++ b/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; diff --git a/src/Components/Components/src/Rendering/RenderTreeBuilder.cs b/src/Components/Components/src/Rendering/RenderTreeBuilder.cs index 281a25cbfaa5..2c73c2783abd 100644 --- a/src/Components/Components/src/Rendering/RenderTreeBuilder.cs +++ b/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 @@ public sealed class RenderTreeBuilder : IDisposable private readonly Stack _openElementIndices = new Stack(); private RenderTreeFrameType? _lastNonAttributeFrameType; private bool _hasSeenAddMultipleAttributes; - private Dictionary _seenAttributeNames; + private Dictionary? _seenAttributeNames; /// /// The reserved parameter name used for supplying child content. @@ -82,7 +79,7 @@ public void CloseElement() /// /// An integer that represents the position of the instruction in the source code. /// Content for the new markup frame. - public void AddMarkupContent(int sequence, string markupContent) + public void AddMarkupContent(int sequence, string? markupContent) => Append(RenderTreeFrame.Markup(sequence, markupContent ?? string.Empty)); /// @@ -90,7 +87,7 @@ public void AddMarkupContent(int sequence, string markupContent) /// /// An integer that represents the position of the instruction in the source code. /// Content for the new text frame. - public void AddContent(int sequence, string textContent) + public void AddContent(int sequence, string? textContent) => Append(RenderTreeFrame.Text(sequence, textContent ?? string.Empty)); /// @@ -98,7 +95,7 @@ public void AddContent(int sequence, string textContent) /// /// An integer that represents the position of the instruction in the source code. /// Content to append. - public void AddContent(int sequence, RenderFragment fragment) + public void AddContent(int sequence, RenderFragment? fragment) { if (fragment != null) { @@ -118,7 +115,7 @@ public void AddContent(int sequence, RenderFragment fragment) /// An integer that represents the position of the instruction in the source code. /// Content to append. /// The value used by . - public void AddContent(int sequence, RenderFragment fragment, TValue value) + public void AddContent(int sequence, RenderFragment? fragment, TValue value) { if (fragment != null) { @@ -139,7 +136,7 @@ public void AddContent(int sequence, MarkupString markupContent) /// /// An integer that represents the position of the instruction in the source code. /// Content for the new text frame. - public void AddContent(int sequence, object textContent) + public void AddContent(int sequence, object? textContent) => AddContent(sequence, textContent?.ToString()); /// @@ -185,7 +182,7 @@ public void AddAttribute(int sequence, string name, bool value) /// An integer that represents the position of the instruction in the source code. /// The name of the attribute. /// The value of the attribute. - 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 @@ public void AddAttribute(int sequence, string name, string value) /// An integer that represents the position of the instruction in the source code. /// The name of the attribute. /// The value of the attribute. - 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 @@ public void AddAttribute(int sequence, string name, EventCallbackAn integer that represents the position of the instruction in the source code. /// The name of the attribute. /// The value of the attribute. - 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 @@ public void AddAttribute(int sequence, in RenderTreeFrame frame) /// /// An integer that represents the position of the instruction in the source code. /// A collection of key-value pairs representing attributes. - public void AddMultipleAttributes(int sequence, IEnumerable> attributes) + public void AddMultipleAttributes(int sequence, IEnumerable>? attributes) { // Calling this up-front just to make sure we validate before mutating anything. AssertCanAddAttribute(); @@ -455,7 +452,7 @@ public void SetUpdatesAttributeName(string updatesAttributeName) /// /// The type of the child component. /// An integer that represents the position of the instruction in the source code. - public void OpenComponent(int sequence) where TComponent : IComponent + public void OpenComponent(int sequence) where TComponent : notnull, IComponent => OpenComponentUnchecked(sequence, typeof(TComponent)); /// @@ -477,7 +474,7 @@ public void OpenComponent(int sequence, Type componentType) /// Assigns the specified key value to the current element or component. /// /// The value for the key. - public void SetKey(object value) + public void SetKey(object? value) { if (value == null) { @@ -560,7 +557,7 @@ public void AddElementReferenceCapture(int sequence, Action el /// /// An integer that represents the position of the instruction in the source code. /// An action to be invoked whenever the reference value changes. - public void AddComponentReferenceCapture(int sequence, Action componentReferenceCaptureAction) + public void AddComponentReferenceCapture(int sequence, Action componentReferenceCaptureAction) { var parentFrameIndex = GetCurrentParentFrameIndex(); if (!parentFrameIndex.HasValue) @@ -640,7 +637,7 @@ public void Clear() // 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)) diff --git a/src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.csproj b/src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.csproj index 0709f6d84b9f..ce5bb3e814f5 100644 --- a/src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.csproj +++ b/src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.csproj @@ -3,6 +3,7 @@ netstandard2.0;$(DefaultNetCoreTargetFramework) $(DefaultNetCoreTargetFramework) + annotations diff --git a/src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.netcoreapp.cs b/src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.netcoreapp.cs index c1961a8a25f0..fcdbb8563b9a 100644 --- a/src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.netcoreapp.cs +++ b/src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.netcoreapp.cs @@ -12,9 +12,9 @@ public sealed partial class EditContext { public EditContext(object model) { } public object Model { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } - public event System.EventHandler OnFieldChanged { add { } remove { } } - public event System.EventHandler OnValidationRequested { add { } remove { } } - public event System.EventHandler OnValidationStateChanged { add { } remove { } } + public event System.EventHandler? OnFieldChanged { add { } remove { } } + public event System.EventHandler? OnValidationRequested { add { } remove { } } + public event System.EventHandler? OnValidationStateChanged { add { } remove { } } public Microsoft.AspNetCore.Components.Forms.FieldIdentifier Field(string fieldName) { throw null; } public System.Collections.Generic.IEnumerable GetValidationMessages() { throw null; } public System.Collections.Generic.IEnumerable GetValidationMessages(Microsoft.AspNetCore.Components.Forms.FieldIdentifier fieldIdentifier) { throw null; } @@ -47,7 +47,7 @@ public FieldChangedEventArgs(in Microsoft.AspNetCore.Components.Forms.FieldIdent public object Model { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public static Microsoft.AspNetCore.Components.Forms.FieldIdentifier Create(System.Linq.Expressions.Expression> 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 diff --git a/src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.netstandard2.0.cs b/src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.netstandard2.0.cs index c1961a8a25f0..fcdbb8563b9a 100644 --- a/src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.netstandard2.0.cs +++ b/src/Components/Forms/ref/Microsoft.AspNetCore.Components.Forms.netstandard2.0.cs @@ -12,9 +12,9 @@ public sealed partial class EditContext { public EditContext(object model) { } public object Model { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } - public event System.EventHandler OnFieldChanged { add { } remove { } } - public event System.EventHandler OnValidationRequested { add { } remove { } } - public event System.EventHandler OnValidationStateChanged { add { } remove { } } + public event System.EventHandler? OnFieldChanged { add { } remove { } } + public event System.EventHandler? OnValidationRequested { add { } remove { } } + public event System.EventHandler? OnValidationStateChanged { add { } remove { } } public Microsoft.AspNetCore.Components.Forms.FieldIdentifier Field(string fieldName) { throw null; } public System.Collections.Generic.IEnumerable GetValidationMessages() { throw null; } public System.Collections.Generic.IEnumerable GetValidationMessages(Microsoft.AspNetCore.Components.Forms.FieldIdentifier fieldIdentifier) { throw null; } @@ -47,7 +47,7 @@ public FieldChangedEventArgs(in Microsoft.AspNetCore.Components.Forms.FieldIdent public object Model { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public static Microsoft.AspNetCore.Components.Forms.FieldIdentifier Create(System.Linq.Expressions.Expression> 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 diff --git a/src/Components/Forms/src/DataAnnotationsValidator.cs b/src/Components/Forms/src/DataAnnotationsValidator.cs index 63696d2c797a..65e059d178a9 100644 --- a/src/Components/Forms/src/DataAnnotationsValidator.cs +++ b/src/Components/Forms/src/DataAnnotationsValidator.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Components.Forms /// public class DataAnnotationsValidator : ComponentBase { - [CascadingParameter] EditContext CurrentEditContext { get; set; } + [CascadingParameter] EditContext? CurrentEditContext { get; set; } /// protected override void OnInitialized() diff --git a/src/Components/Forms/src/EditContext.cs b/src/Components/Forms/src/EditContext.cs index caaf677c3744..aed3b69dedaf 100644 --- a/src/Components/Forms/src/EditContext.cs +++ b/src/Components/Forms/src/EditContext.cs @@ -36,17 +36,17 @@ public EditContext(object model) /// /// An event that is raised when a field value changes. /// - public event EventHandler OnFieldChanged; + public event EventHandler? OnFieldChanged; /// /// An event that is raised when validation is requested. /// - public event EventHandler OnValidationRequested; + public event EventHandler? OnValidationRequested; /// /// An event that is raised when validation state has changed. /// - public event EventHandler OnValidationStateChanged; + public event EventHandler? OnValidationStateChanged; /// /// Supplies a corresponding to a specified field name @@ -68,7 +68,7 @@ public FieldIdentifier Field(string fieldName) /// Identifies the field whose value has been changed. 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 @@ public bool Validate() 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); diff --git a/src/Components/Forms/src/EditContextDataAnnotationsExtensions.cs b/src/Components/Forms/src/EditContextDataAnnotationsExtensions.cs index e7f9d5f15507..936d30ba1449 100644 --- a/src/Components/Forms/src/EditContextDataAnnotationsExtensions.cs +++ b/src/Components/Forms/src/EditContextDataAnnotationsExtensions.cs @@ -5,6 +5,7 @@ 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 /// 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?>(); /// /// Adds DataAnnotations validation support to the . @@ -33,7 +34,7 @@ public static EditContext AddDataAnnotationsValidation(this EditContext editCont // 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 @@ private static void ValidateField(EditContext editContext, ValidationMessageStor } } - 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)) diff --git a/src/Components/Forms/src/FieldIdentifier.cs b/src/Components/Forms/src/FieldIdentifier.cs index 41fe513a43dc..cd5e913743e9 100644 --- a/src/Components/Forms/src/FieldIdentifier.cs +++ b/src/Components/Forms/src/FieldIdentifier.cs @@ -77,7 +77,7 @@ public override int GetHashCode() } /// - public override bool Equals(object obj) + public override bool Equals(object? obj) => obj is FieldIdentifier otherIdentifier && Equals(otherIdentifier); @@ -111,20 +111,32 @@ private static void ParseAccessor(Expression> accessor, out object mo // 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 so we can cheaply map from "something" to "something.Member". - var modelLambda = Expression.Lambda(memberExpression.Expression); - var modelLambdaCompiled = (Func)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 so we can cheaply map from "something" to "something.Member". + var modelLambda = Expression.Lambda(memberExpression.Expression); + var modelLambdaCompiled = (Func)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."); } } } diff --git a/src/Components/Forms/src/FieldState.cs b/src/Components/Forms/src/FieldState.cs index 3a8d1f0eb36c..2f4a48c750cf 100644 --- a/src/Components/Forms/src/FieldState.cs +++ b/src/Components/Forms/src/FieldState.cs @@ -13,7 +13,7 @@ internal class FieldState // 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 _validationMessageStores; + private HashSet? _validationMessageStores; public FieldState(FieldIdentifier fieldIdentifier) { diff --git a/src/Components/Forms/src/Microsoft.AspNetCore.Components.Forms.csproj b/src/Components/Forms/src/Microsoft.AspNetCore.Components.Forms.csproj index 1c39c34f1d44..51d866333dc7 100644 --- a/src/Components/Forms/src/Microsoft.AspNetCore.Components.Forms.csproj +++ b/src/Components/Forms/src/Microsoft.AspNetCore.Components.Forms.csproj @@ -1,4 +1,4 @@ - + netstandard2.0;$(DefaultNetCoreTargetFramework) @@ -6,6 +6,7 @@ true Forms and validation support for Blazor applications. true + enable diff --git a/src/Components/Forms/src/ValidationMessageStore.cs b/src/Components/Forms/src/ValidationMessageStore.cs index a8b0664bec90..678765b3066f 100644 --- a/src/Components/Forms/src/ValidationMessageStore.cs +++ b/src/Components/Forms/src/ValidationMessageStore.cs @@ -120,9 +120,9 @@ private List GetOrCreateMessagesListForField(in FieldIdentifier fieldIde } 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); } } diff --git a/src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.csproj b/src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.csproj index 3973a0b3c278..3827af28f542 100644 --- a/src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.csproj +++ b/src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.csproj @@ -2,6 +2,7 @@ $(DefaultNetCoreTargetFramework) + annotations diff --git a/src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.netcoreapp.cs b/src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.netcoreapp.cs index 6265d868b9f3..9ce16ae9c6bb 100644 --- a/src/Components/Server/ref/Microsoft.AspNetCore.Components.Server.netcoreapp.cs +++ b/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 configure = null) { throw null; } + public static Microsoft.Extensions.DependencyInjection.IServerSideBlazorBuilder AddServerSideBlazor(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action? configure = null) { throw null; } } public partial interface IServerSideBlazorBuilder { diff --git a/src/Components/Server/src/DependencyInjection/ComponentServiceCollectionExtensions.cs b/src/Components/Server/src/DependencyInjection/ComponentServiceCollectionExtensions.cs index e906b7dc26fe..cd65b7fdc4f1 100644 --- a/src/Components/Server/src/DependencyInjection/ComponentServiceCollectionExtensions.cs +++ b/src/Components/Server/src/DependencyInjection/ComponentServiceCollectionExtensions.cs @@ -27,7 +27,7 @@ public static class ComponentServiceCollectionExtensions /// The . /// A callback to configure . /// An that can be used to further customize the configuration. - public static IServerSideBlazorBuilder AddServerSideBlazor(this IServiceCollection services, Action configure = null) + public static IServerSideBlazorBuilder AddServerSideBlazor(this IServiceCollection services, Action? configure = null) { var builder = new DefaultServerSideBlazorBuilder(services); diff --git a/src/Components/Server/src/DependencyInjection/ServerSideBlazorBuilderExtensions.cs b/src/Components/Server/src/DependencyInjection/ServerSideBlazorBuilderExtensions.cs index ba786d9350a8..cb2c27af084d 100644 --- a/src/Components/Server/src/DependencyInjection/ServerSideBlazorBuilderExtensions.cs +++ b/src/Components/Server/src/DependencyInjection/ServerSideBlazorBuilderExtensions.cs @@ -48,11 +48,13 @@ public static IServerSideBlazorBuilder AddHubOptions(this IServerSideBlazorBuild throw new ArgumentNullException(nameof(builder)); } - if (configure != null) + if (configure == null) { - builder.Services.Configure>(configure); + throw new ArgumentNullException(nameof(configure)); } + builder.Services.Configure>(configure); + return builder; } } diff --git a/src/Components/Server/src/Microsoft.AspNetCore.Components.Server.csproj b/src/Components/Server/src/Microsoft.AspNetCore.Components.Server.csproj index 169ef3fac694..d13c7467af32 100644 --- a/src/Components/Server/src/Microsoft.AspNetCore.Components.Server.csproj +++ b/src/Components/Server/src/Microsoft.AspNetCore.Components.Server.csproj @@ -1,4 +1,4 @@ - + $(DefaultNetCoreTargetFramework) Runtime server features for ASP.NET Core Components. @@ -10,6 +10,7 @@ $(DefineConstants);ENABLE_UNSAFE_MSGPACK;SPAN_BUILTIN;MESSAGEPACK_INTERNAL;COMPONENTS_SERVER false Microsoft.Extensions.FileProviders.Embedded.Manifest.xml + annotations diff --git a/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.csproj b/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.csproj index bb7191613346..e472ff807eb7 100644 --- a/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.csproj +++ b/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.csproj @@ -3,6 +3,7 @@ netstandard2.0;$(DefaultNetCoreTargetFramework) $(DefaultNetCoreTargetFramework) + annotations diff --git a/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netcoreapp.cs b/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netcoreapp.cs index 366df100c3ed..799d08e2f28c 100644 --- a/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netcoreapp.cs +++ b/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 @@ public partial class EditForm : Microsoft.AspNetCore.Components.ComponentBase { public EditForm() { } [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)] - public System.Collections.Generic.IReadOnlyDictionary AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Collections.Generic.IReadOnlyDictionary? 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 { } } + public Microsoft.AspNetCore.Components.RenderFragment? 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 OnInvalidSubmit { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } [Microsoft.AspNetCore.Components.ParameterAttribute] @@ -46,29 +46,33 @@ public abstract partial class InputBase : Microsoft.AspNetCore.Component { protected InputBase() { } [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)] - public System.Collections.Generic.IReadOnlyDictionary AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Collections.Generic.IReadOnlyDictionary? 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 ValueChanged { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } [Microsoft.AspNetCore.Components.ParameterAttribute] - public System.Linq.Expressions.Expression> ValueExpression { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Linq.Expressions.Expression>? 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 { 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 : Microsoft.AspNetCore.Components.Forms.InputBase { @@ -77,7 +81,7 @@ public InputDate() { } 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 : Microsoft.AspNetCore.Components.Forms.InputBase { @@ -85,36 +89,36 @@ public InputNumber() { } [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 : Microsoft.AspNetCore.Components.Forms.InputBase { 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 + public partial class InputText : Microsoft.AspNetCore.Components.Forms.InputBase { 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 + public partial class InputTextArea : Microsoft.AspNetCore.Components.Forms.InputBase { 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 : Microsoft.AspNetCore.Components.ComponentBase, System.IDisposable { public ValidationMessage() { } [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)] - public System.Collections.Generic.IReadOnlyDictionary AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Collections.Generic.IReadOnlyDictionary? AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } [Microsoft.AspNetCore.Components.ParameterAttribute] - public System.Linq.Expressions.Expression> For { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Linq.Expressions.Expression>? 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 @@ public partial class ValidationSummary : Microsoft.AspNetCore.Components.Compone { public ValidationSummary() { } [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)] - public System.Collections.Generic.IReadOnlyDictionary AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Collections.Generic.IReadOnlyDictionary? 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 @@ public sealed partial class WebEventDescriptor 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 @@ public partial class NavLink : Microsoft.AspNetCore.Components.ComponentBase, Sy { 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 AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Collections.Generic.IReadOnlyDictionary? 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 @@ public partial class DataTransfer { 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 @@ public partial class ErrorEventArgs : System.EventArgs { 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 @@ public static partial class EventHandlers 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 { diff --git a/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netstandard2.0.cs b/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netstandard2.0.cs index 366df100c3ed..287b9bfc5749 100644 --- a/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netstandard2.0.cs +++ b/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 @@ public partial class EditForm : Microsoft.AspNetCore.Components.ComponentBase { public EditForm() { } [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)] - public System.Collections.Generic.IReadOnlyDictionary AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Collections.Generic.IReadOnlyDictionary? 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 { } } + public Microsoft.AspNetCore.Components.RenderFragment? 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 OnInvalidSubmit { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } [Microsoft.AspNetCore.Components.ParameterAttribute] @@ -46,10 +46,10 @@ public abstract partial class InputBase : Microsoft.AspNetCore.Component { protected InputBase() { } [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)] - public System.Collections.Generic.IReadOnlyDictionary AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Collections.Generic.IReadOnlyDictionary? 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 @@ protected InputBase() { } [Microsoft.AspNetCore.Components.ParameterAttribute] public Microsoft.AspNetCore.Components.EventCallback ValueChanged { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } [Microsoft.AspNetCore.Components.ParameterAttribute] - public System.Linq.Expressions.Expression> ValueExpression { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Linq.Expressions.Expression>? 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 { 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 : Microsoft.AspNetCore.Components.Forms.InputBase { @@ -77,7 +77,7 @@ public InputDate() { } 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 : Microsoft.AspNetCore.Components.Forms.InputBase { @@ -85,36 +85,36 @@ public InputNumber() { } [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 : Microsoft.AspNetCore.Components.Forms.InputBase { 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 + public partial class InputText : Microsoft.AspNetCore.Components.Forms.InputBase { 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 + public partial class InputTextArea : Microsoft.AspNetCore.Components.Forms.InputBase { 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 : Microsoft.AspNetCore.Components.ComponentBase, System.IDisposable { public ValidationMessage() { } [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)] - public System.Collections.Generic.IReadOnlyDictionary AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Collections.Generic.IReadOnlyDictionary? AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } [Microsoft.AspNetCore.Components.ParameterAttribute] - public System.Linq.Expressions.Expression> For { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Linq.Expressions.Expression>? 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 @@ public partial class ValidationSummary : Microsoft.AspNetCore.Components.Compone { public ValidationSummary() { } [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)] - public System.Collections.Generic.IReadOnlyDictionary AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Collections.Generic.IReadOnlyDictionary? 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 @@ public sealed partial class WebEventDescriptor 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 @@ public partial class NavLink : Microsoft.AspNetCore.Components.ComponentBase, Sy { 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 AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Collections.Generic.IReadOnlyDictionary? 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 @@ public partial class DataTransfer { 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 @@ public partial class ErrorEventArgs : System.EventArgs { 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 @@ public static partial class EventHandlers 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 { diff --git a/src/Components/Web/src/BindInputElementAttribute.cs b/src/Components/Web/src/BindInputElementAttribute.cs index f6169c0ca562..d559667ed168 100644 --- a/src/Components/Web/src/BindInputElementAttribute.cs +++ b/src/Components/Web/src/BindInputElementAttribute.cs @@ -25,7 +25,7 @@ public sealed class BindInputElementAttribute : Attribute /// /// An optional format to use when converting values. /// - 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 @@ public BindInputElementAttribute(string type, string suffix, string valueAttribu /// /// Gets the value of the element's type attribute. /// - public string Type { get; } + public string? Type { get; } /// /// Gets the suffix value. /// - public string Suffix { get; } + public string? Suffix { get; } /// /// Gets the name of the value attribute to be bound. /// - public string ValueAttribute { get; } + public string? ValueAttribute { get; } /// /// Gets the name of an attribute that will register an associated change event. /// - public string ChangeAttribute { get; } + public string? ChangeAttribute { get; } /// /// Gets a value that determines whether binding will use or @@ -74,6 +74,6 @@ public BindInputElementAttribute(string type, string suffix, string valueAttribu /// /// Gets an optional format to use when converting values. /// - public string Format { get; } + public string? Format { get; } } } diff --git a/src/Components/Web/src/Forms/EditForm.cs b/src/Components/Web/src/Forms/EditForm.cs index d47a6377a645..e4467b532a51 100644 --- a/src/Components/Web/src/Forms/EditForm.cs +++ b/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 @@ public class EditForm : ComponentBase { private readonly Func _handleSubmitDelegate; // Cache to avoid per-render allocations - private EditContext _fixedEditContext; + private EditContext? _fixedEditContext; /// /// Constructs an instance of . @@ -28,26 +29,26 @@ public EditForm() /// /// Gets or sets a collection of additional attributes that will be applied to the created form element. /// - [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary? AdditionalAttributes { get; set; } /// /// Supplies the edit context explicitly. If using this parameter, do not /// also supply , since the model value will be taken /// from the property. /// - [Parameter] public EditContext EditContext { get; set; } + [Parameter] public EditContext? EditContext { get; set; } /// /// 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 . /// - [Parameter] public object Model { get; set; } + [Parameter] public object? Model { get; set; } /// /// Specifies the content to be rendered inside this . /// - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] public RenderFragment? ChildContent { get; set; } /// /// A callback that will be invoked when the form is submitted. @@ -92,13 +93,15 @@ protected override void OnParametersSet() // 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!); } } /// 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 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) private async Task HandleSubmitAsync() { + Debug.Assert(_fixedEditContext != null); + if (OnSubmit.HasDelegate) { // When using OnSubmit, the developer takes control of the validation lifecycle diff --git a/src/Components/Web/src/Forms/InputBase.cs b/src/Components/Web/src/Forms/InputBase.cs index 0ed81b62ec66..b414d3874c03 100644 --- a/src/Components/Web/src/Forms/InputBase.cs +++ b/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 @@ public abstract class InputBase : ComponentBase, IDisposable { private readonly EventHandler _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!; /// /// Gets or sets a collection of additional attributes that will be applied to the created element. /// - [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary? AdditionalAttributes { get; set; } /// /// Gets or sets the value of the input. This should be used with two-way binding. @@ -34,7 +35,10 @@ public abstract class InputBase : ComponentBase, IDisposable /// /// @bind-Value="model.PropertyName" /// - [Parameter] public TValue Value { get; set; } + [AllowNull] + [MaybeNull] + [Parameter] + public TValue Value { get; set; } = default; /// /// Gets or sets a callback that updates the bound value. @@ -44,12 +48,12 @@ public abstract class InputBase : ComponentBase, IDisposable /// /// Gets or sets an expression that identifies the bound value. /// - [Parameter] public Expression> ValueExpression { get; set; } + [Parameter] public Expression>? ValueExpression { get; set; } /// /// Gets the associated . /// - protected EditContext EditContext { get; set; } + protected EditContext EditContext { get; set; } = default!; /// /// Gets the for the bound value. @@ -59,16 +63,18 @@ public abstract class InputBase : ComponentBase, IDisposable /// /// Gets or sets the current value of the input. /// + [AllowNull] protected TValue CurrentValue { - get => Value; + [return: MaybeNull] + get => Value!; set { var hasChanged = !EqualityComparer.Default.Equals(value, Value); if (hasChanged) { - Value = value; - _ = ValueChanged.InvokeAsync(value); + Value = value!; + _ = ValueChanged.InvokeAsync(Value); EditContext.NotifyFieldChanged(FieldIdentifier); } } @@ -77,7 +83,7 @@ protected TValue CurrentValue /// /// Gets or sets the current value of the input, represented as a string. /// - protected string CurrentValueAsString + protected string? CurrentValueAsString { get => FormatValueAsString(CurrentValue); set @@ -92,12 +98,12 @@ protected string CurrentValueAsString // Then all subclasses get nullable support almost automatically (they just have to // not reject Nullable 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 @@ protected InputBase() /// /// The value to format. /// A string representation of the value. - protected virtual string FormatValueAsString(TValue value) + protected virtual string? FormatValueAsString(TValue value) => value?.ToString(); /// @@ -147,7 +153,7 @@ protected virtual string FormatValueAsString(TValue value) /// An instance of . /// If the value could not be parsed, provides a validation error message. /// True if the value could be parsed; otherwise false. - 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); /// /// Gets a string that indicates the status of the field being edited. This will include @@ -223,7 +229,7 @@ public override Task SetParametersAsync(ParameterView parameters) return base.SetParametersAsync(ParameterView.Empty); } - private void OnValidateStateChanged(object sender, ValidationStateChangedEventArgs eventArgs) + private void OnValidateStateChanged(object? sender, ValidationStateChangedEventArgs eventArgs) { SetAdditionalAttributesIfValidationFailed(); @@ -255,9 +261,9 @@ private void SetAdditionalAttributesIfValidationFailed() /// Returns a dictionary with the same values as the specified . /// /// true, if a new dictrionary with copied values was created. false - otherwise. - private bool ConvertToDictionary(IReadOnlyDictionary source, out Dictionary result) + private bool ConvertToDictionary(IReadOnlyDictionary? source, out Dictionary result) { - bool newDictionaryCreated = true; + var newDictionaryCreated = true; if (source == null) { result = new Dictionary(); @@ -285,11 +291,7 @@ protected virtual void Dispose(bool disposing) void IDisposable.Dispose() { - if (EditContext != null) - { - EditContext.OnValidationStateChanged -= _validationStateChangedHandler; - } - + EditContext.OnValidationStateChanged -= _validationStateChangedHandler; Dispose(disposing: true); } } diff --git a/src/Components/Web/src/Forms/InputCheckbox.cs b/src/Components/Web/src/Forms/InputCheckbox.cs index bb564dc13c3e..f1eb030a355f 100644 --- a/src/Components/Web/src/Forms/InputCheckbox.cs +++ b/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 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) } /// - 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)}'."); } } diff --git a/src/Components/Web/src/Forms/InputDate.cs b/src/Components/Web/src/Forms/InputDate.cs index 719252347145..45583a849e72 100644 --- a/src/Components/Web/src/Forms/InputDate.cs +++ b/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 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) builder.AddAttribute(2, "type", "date"); builder.AddAttribute(3, "class", CssClass); builder.AddAttribute(4, "value", BindConverter.FormatValue(CurrentValueAsString)); - builder.AddAttribute(5, "onchange", EventCallback.Factory.CreateBinder(this, __value => CurrentValueAsString = __value, CurrentValueAsString)); + builder.AddAttribute(5, "onchange", EventCallback.Factory.CreateBinder(this, __value => CurrentValueAsString = __value, CurrentValueAsString)); builder.CloseElement(); } @@ -47,7 +48,7 @@ protected override string FormatValueAsString(TValue value) } /// - 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 @@ protected override bool TryParseValueFromString(string value, out TValue result, } } - 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 @@ static bool TryParseDateTime(string value, out TValue result) } } - 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) diff --git a/src/Components/Web/src/Forms/InputNumber.cs b/src/Components/Web/src/Forms/InputNumber.cs index 22ef566e388c..9f3b75175ed0 100644 --- a/src/Components/Web/src/Forms/InputNumber.cs +++ b/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 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) builder.AddAttribute(3, "type", "number"); builder.AddAttribute(4, "class", CssClass); builder.AddAttribute(5, "value", BindConverter.FormatValue(CurrentValueAsString)); - builder.AddAttribute(6, "onchange", EventCallback.Factory.CreateBinder(this, __value => CurrentValueAsString = __value, CurrentValueAsString)); + builder.AddAttribute(6, "onchange", EventCallback.Factory.CreateBinder(this, __value => CurrentValueAsString = __value, CurrentValueAsString)); builder.CloseElement(); } /// - 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(value, CultureInfo.InvariantCulture, out result)) { @@ -73,7 +74,7 @@ protected override bool TryParseValueFromString(string value, out TValue result, /// /// The value to format. /// A string representation of the value. - protected override string FormatValueAsString(TValue value) + protected override string? FormatValueAsString(TValue value) { // Avoiding a cast to IFormattable to avoid boxing. switch (value) diff --git a/src/Components/Web/src/Forms/InputSelect.cs b/src/Components/Web/src/Forms/InputSelect.cs index e1a3ab0eae01..c5e6e54a943c 100644 --- a/src/Components/Web/src/Forms/InputSelect.cs +++ b/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 /// public class InputSelect : InputBase { + private static readonly Type? _nullableUnderlyingType = Nullable.GetUnderlyingType(typeof(TValue)); + /// /// Gets or sets the child content to be rendering inside the select element. /// - [Parameter] public RenderFragment ChildContent { get; set; } - - private readonly Type _nullableUnderlyingType = Nullable.GetUnderlyingType(typeof(TValue)); + [Parameter] public RenderFragment? ChildContent { get; set; } /// protected override void BuildRenderTree(RenderTreeBuilder builder) @@ -26,17 +27,17 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) builder.AddMultipleAttributes(1, AdditionalAttributes); builder.AddAttribute(2, "class", CssClass); builder.AddAttribute(3, "value", BindConverter.FormatValue(CurrentValueAsString)); - builder.AddAttribute(4, "onchange", EventCallback.Factory.CreateBinder(this, __value => CurrentValueAsString = __value, CurrentValueAsString)); + builder.AddAttribute(4, "onchange", EventCallback.Factory.CreateBinder(this, __value => CurrentValueAsString = __value, CurrentValueAsString)); builder.AddContent(5, ChildContent); builder.CloseElement(); } /// - 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; } diff --git a/src/Components/Web/src/Forms/InputText.cs b/src/Components/Web/src/Forms/InputText.cs index c7a0a319d760..17561eb942f8 100644 --- a/src/Components/Web/src/Forms/InputText.cs +++ b/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 /// /// An input component for editing values. /// - public class InputText : InputBase + public class InputText : InputBase { /// protected override void BuildRenderTree(RenderTreeBuilder builder) @@ -26,12 +27,12 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) builder.AddMultipleAttributes(1, AdditionalAttributes); builder.AddAttribute(2, "class", CssClass); builder.AddAttribute(3, "value", BindConverter.FormatValue(CurrentValue)); - builder.AddAttribute(4, "onchange", EventCallback.Factory.CreateBinder(this, __value => CurrentValueAsString = __value, CurrentValueAsString)); + builder.AddAttribute(4, "onchange", EventCallback.Factory.CreateBinder(this, __value => CurrentValueAsString = __value, CurrentValueAsString)); builder.CloseElement(); } /// - 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; diff --git a/src/Components/Web/src/Forms/InputTextArea.cs b/src/Components/Web/src/Forms/InputTextArea.cs index 9f82b7175985..80958270322b 100644 --- a/src/Components/Web/src/Forms/InputTextArea.cs +++ b/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 /// /// A multiline input component for editing values. /// - public class InputTextArea : InputBase + public class InputTextArea : InputBase { /// protected override void BuildRenderTree(RenderTreeBuilder builder) @@ -26,12 +27,12 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) builder.AddMultipleAttributes(1, AdditionalAttributes); builder.AddAttribute(2, "class", CssClass); builder.AddAttribute(3, "value", BindConverter.FormatValue(CurrentValue)); - builder.AddAttribute(4, "onchange", EventCallback.Factory.CreateBinder(this, __value => CurrentValueAsString = __value, CurrentValueAsString)); + builder.AddAttribute(4, "onchange", EventCallback.Factory.CreateBinder(this, __value => CurrentValueAsString = __value, CurrentValueAsString)); builder.CloseElement(); } /// - 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; diff --git a/src/Components/Web/src/Forms/ValidationMessage.cs b/src/Components/Web/src/Forms/ValidationMessage.cs index d15efd2d4cf1..6651f5da64af 100644 --- a/src/Components/Web/src/Forms/ValidationMessage.cs +++ b/src/Components/Web/src/Forms/ValidationMessage.cs @@ -13,22 +13,22 @@ namespace Microsoft.AspNetCore.Components.Forms /// public class ValidationMessage : ComponentBase, IDisposable { - private EditContext _previousEditContext; - private Expression> _previousFieldAccessor; - private readonly EventHandler _validationStateChangedHandler; + private EditContext? _previousEditContext; + private Expression>? _previousFieldAccessor; + private readonly EventHandler? _validationStateChangedHandler; private FieldIdentifier _fieldIdentifier; /// /// Gets or sets a collection of additional attributes that will be applied to the created div element. /// - [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary? AdditionalAttributes { get; set; } - [CascadingParameter] EditContext CurrentEditContext { get; set; } + [CascadingParameter] EditContext CurrentEditContext { get; set; } = default!; /// /// Specifies the field for which validation messages should be displayed. /// - [Parameter] public Expression> For { get; set; } + [Parameter] public Expression>? For { get; set; } /// ` /// Constructs an instance of . diff --git a/src/Components/Web/src/Forms/ValidationSummary.cs b/src/Components/Web/src/Forms/ValidationSummary.cs index 4e168f35baca..c24536f0ad58 100644 --- a/src/Components/Web/src/Forms/ValidationSummary.cs +++ b/src/Components/Web/src/Forms/ValidationSummary.cs @@ -16,21 +16,21 @@ namespace Microsoft.AspNetCore.Components.Forms /// public class ValidationSummary : ComponentBase, IDisposable { - private EditContext _previousEditContext; + private EditContext? _previousEditContext; private readonly EventHandler _validationStateChangedHandler; /// /// 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. /// - [Parameter] public object Model { get; set; } + [Parameter] public object? Model { get; set; } /// /// Gets or sets a collection of additional attributes that will be applied to the created ul element. /// - [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary AdditionalAttributes { get; set; } + [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary? AdditionalAttributes { get; set; } - [CascadingParameter] EditContext CurrentEditContext { get; set; } + [CascadingParameter] EditContext CurrentEditContext { get; set; } = default!; /// ` /// Constructs an instance of . diff --git a/src/Components/Web/src/Microsoft.AspNetCore.Components.Web.csproj b/src/Components/Web/src/Microsoft.AspNetCore.Components.Web.csproj index 6b0c9812e7eb..91e823376400 100644 --- a/src/Components/Web/src/Microsoft.AspNetCore.Components.Web.csproj +++ b/src/Components/Web/src/Microsoft.AspNetCore.Components.Web.csproj @@ -1,4 +1,4 @@ - + netstandard2.0;$(DefaultNetCoreTargetFramework) @@ -7,6 +7,7 @@ Support for rendering ASP.NET Core components for browsers. true Microsoft.AspNetCore.Components + enable diff --git a/src/Components/Web/src/Routing/NavLink.cs b/src/Components/Web/src/Routing/NavLink.cs index 5dda2fe014e8..bfd20b827130 100644 --- a/src/Components/Web/src/Routing/NavLink.cs +++ b/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 @@ public class NavLink : ComponentBase, IDisposable private const string DefaultActiveClass = "active"; private bool _isActive; - private string _hrefAbsolute; - private string _class; + private string? _hrefAbsolute; + private string? _class; /// /// Gets or sets the CSS class name applied to the NavLink when the /// current route matches the NavLink href. /// [Parameter] - public string ActiveClass { get; set; } + public string? ActiveClass { get; set; } /// /// Gets or sets a collection of additional attributes that will be added to the generated /// a element. /// [Parameter(CaptureUnmatchedValues = true)] - public IReadOnlyDictionary AdditionalAttributes { get; set; } + public IReadOnlyDictionary? AdditionalAttributes { get; set; } /// /// Gets or sets the computed CSS class based on whether or not the link is active. /// - protected string CssClass { get; set; } + protected string? CssClass { get; set; } /// /// Gets or sets the child content of the component. /// [Parameter] - public RenderFragment ChildContent { get; set; } + public RenderFragment? ChildContent { get; set; } /// /// Gets or sets a value representing the URL matching behavior. @@ -51,7 +51,7 @@ public class NavLink : ComponentBase, IDisposable [Parameter] public NavLinkMatch Match { get; set; } - [Inject] private NavigationManager NavigationManger { get; set; } + [Inject] private NavigationManager NavigationManger { get; set; } = default!; /// protected override void OnInitialized() @@ -64,7 +64,7 @@ protected override void OnInitialized() 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 @@ protected override void OnParametersSet() _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 @@ private void UpdateCssClass() 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 @@ private bool ShouldMatch(string currentUriAbsolute) private bool EqualsHrefExactlyOrIfTrailingSlashAdded(string currentUriAbsolute) { + Debug.Assert(_hrefAbsolute != null); + if (string.Equals(currentUriAbsolute, _hrefAbsolute, StringComparison.OrdinalIgnoreCase)) { return true; @@ -166,9 +168,8 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) 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) { diff --git a/src/Components/Web/src/Web/ClipboardEventArgs.cs b/src/Components/Web/src/Web/ClipboardEventArgs.cs index 11b8458d6112..4879875baff6 100644 --- a/src/Components/Web/src/Web/ClipboardEventArgs.cs +++ b/src/Components/Web/src/Web/ClipboardEventArgs.cs @@ -13,6 +13,6 @@ public class ClipboardEventArgs : EventArgs /// /// Gets or sets the type of the event. /// - public string Type { get; set; } + public string Type { get; set; } = default!; } } diff --git a/src/Components/Web/src/Web/DataTransfer.cs b/src/Components/Web/src/Web/DataTransfer.cs index e0fb9eb25654..48b76423a7a7 100644 --- a/src/Components/Web/src/Web/DataTransfer.cs +++ b/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 { /// @@ -14,28 +16,28 @@ public class DataTransfer /// 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. /// - public string DropEffect { get; set; } + public string DropEffect { get; set; } = default!; /// /// Provides all of the types of operations that are possible. /// Must be one of none, copy, copyLink, copyMove, link, linkMove, move, all or uninitialized. /// - public string EffectAllowed { get; set; } + public string? EffectAllowed { get; set; } /// /// 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. /// - public string[] Files { get; set; } + public string[] Files { get; set; } = Array.Empty(); /// /// Gives a array which is a list of all of the drag data. /// - public DataTransferItem[] Items { get; set; } + public DataTransferItem[] Items { get; set; } = Array.Empty(); /// /// An array of giving the formats that were set in the dragstart event. /// - public string[] Types { get; set; } + public string[] Types { get; set; } = Array.Empty(); } } diff --git a/src/Components/Web/src/Web/DataTransferItem.cs b/src/Components/Web/src/Web/DataTransferItem.cs index df4605ee691e..112e27dfd03a 100644 --- a/src/Components/Web/src/Web/DataTransferItem.cs +++ b/src/Components/Web/src/Web/DataTransferItem.cs @@ -13,11 +13,11 @@ public class DataTransferItem /// /// The kind of drag data item, string or file /// - public string Kind { get; set; } + public string Kind { get; set; } = default!; /// /// The drag data item's type, typically a MIME type /// - public string Type { get; set; } + public string Type { get; set; } = default!; } } diff --git a/src/Components/Web/src/Web/DragEventArgs.cs b/src/Components/Web/src/Web/DragEventArgs.cs index acabfa2561bb..5a92d6d6b314 100644 --- a/src/Components/Web/src/Web/DragEventArgs.cs +++ b/src/Components/Web/src/Web/DragEventArgs.cs @@ -12,6 +12,6 @@ public class DragEventArgs : MouseEventArgs /// The data that underlies a drag-and-drop operation, known as the drag data store. /// See . /// - public DataTransfer DataTransfer { get; set; } + public DataTransfer DataTransfer { get; set; } = default!; } } diff --git a/src/Components/Web/src/Web/ErrorEventArgs.cs b/src/Components/Web/src/Web/ErrorEventArgs.cs index 0b2409301eab..a2afd3c3ac6d 100644 --- a/src/Components/Web/src/Web/ErrorEventArgs.cs +++ b/src/Components/Web/src/Web/ErrorEventArgs.cs @@ -13,12 +13,12 @@ public class ErrorEventArgs : EventArgs /// /// Gets a a human-readable error message describing the problem. /// - public string Message { get; set; } + public string? Message { get; set; } /// /// Gets the name of the script file in which the error occurred. /// - public string Filename { get; set; } + public string? Filename { get; set; } /// /// Gets the line number of the script file on which the error occurred. @@ -33,6 +33,6 @@ public class ErrorEventArgs : EventArgs /// /// Gets or sets the type of the event. /// - public string Type { get; set; } + public string? Type { get; set; } } } diff --git a/src/Components/Web/src/Web/FocusEventArgs.cs b/src/Components/Web/src/Web/FocusEventArgs.cs index 1d3979c1537a..65187d32ee34 100644 --- a/src/Components/Web/src/Web/FocusEventArgs.cs +++ b/src/Components/Web/src/Web/FocusEventArgs.cs @@ -16,6 +16,6 @@ public class FocusEventArgs : EventArgs /// /// Gets or sets the type of the event. /// - public string Type { get; set; } + public string? Type { get; set; } } } diff --git a/src/Components/Web/src/Web/KeyboardEventArgs.cs b/src/Components/Web/src/Web/KeyboardEventArgs.cs index f3870b8a3131..e988bc3776f9 100644 --- a/src/Components/Web/src/Web/KeyboardEventArgs.cs +++ b/src/Components/Web/src/Web/KeyboardEventArgs.cs @@ -16,13 +16,13 @@ public class KeyboardEventArgs : EventArgs /// 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" /// - public string Key { get; set; } + public string Key { get; set; } = default!; /// /// 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. /// - public string Code { get; set; } + public string Code { get; set; } = default!; /// /// The location of the key on the device. @@ -57,6 +57,6 @@ public class KeyboardEventArgs : EventArgs /// /// Gets or sets the type of the event. /// - public string Type { get; set; } + public string Type { get; set; } = default!; } } diff --git a/src/Components/Web/src/Web/MouseEventArgs.cs b/src/Components/Web/src/Web/MouseEventArgs.cs index b0d4d67f5964..f2e87882861b 100644 --- a/src/Components/Web/src/Web/MouseEventArgs.cs +++ b/src/Components/Web/src/Web/MouseEventArgs.cs @@ -89,6 +89,6 @@ public class MouseEventArgs : EventArgs /// /// Gets or sets the type of the event. /// - public string Type { get; set; } + public string Type { get; set; } = default!; } } diff --git a/src/Components/Web/src/Web/PointerEventArgs.cs b/src/Components/Web/src/Web/PointerEventArgs.cs index 97c84bf41750..f7ad475ddaca 100644 --- a/src/Components/Web/src/Web/PointerEventArgs.cs +++ b/src/Components/Web/src/Web/PointerEventArgs.cs @@ -45,7 +45,7 @@ public class PointerEventArgs : MouseEventArgs /// Indicates the device type that caused the event. /// Must be one of the strings mouse, pen or touch, or an empty string. /// - public string PointerType { get; set; } + public string PointerType { get; set; } = default!; /// /// Indicates if the pointer represents the primary pointer of this pointer type. diff --git a/src/Components/Web/src/Web/ProgressEventArgs.cs b/src/Components/Web/src/Web/ProgressEventArgs.cs index 9c57c5d9dd54..4acda3ac062b 100644 --- a/src/Components/Web/src/Web/ProgressEventArgs.cs +++ b/src/Components/Web/src/Web/ProgressEventArgs.cs @@ -30,6 +30,6 @@ public class ProgressEventArgs : EventArgs /// /// Gets or sets the type of the event. /// - public string Type { get; set; } + public string Type { get; set; } = default!; } } diff --git a/src/Components/Web/src/Web/TouchEventArgs.cs b/src/Components/Web/src/Web/TouchEventArgs.cs index 7cf086ac2ed6..e6e3894863b7 100644 --- a/src/Components/Web/src/Web/TouchEventArgs.cs +++ b/src/Components/Web/src/Web/TouchEventArgs.cs @@ -18,12 +18,12 @@ public class TouchEventArgs : EventArgs /// /// A list of for every point of contact currently touching the surface. /// - public TouchPoint[] Touches { get; set; } + public TouchPoint[] Touches { get; set; } = Array.Empty(); /// /// A list of for every point of contact that is touching the surface and started on the element that is the target of the current event. /// - public TouchPoint[] TargetTouches { get; set; } + public TouchPoint[] TargetTouches { get; set; } = Array.Empty(); /// /// A list of Touches for every point of contact which contributed to the event. @@ -31,7 +31,7 @@ public class TouchEventArgs : EventArgs /// 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. /// - public TouchPoint[] ChangedTouches { get; set; } + public TouchPoint[] ChangedTouches { get; set; } = Array.Empty(); /// /// true if the control key was down when the event was fired. false otherwise. @@ -56,6 +56,6 @@ public class TouchEventArgs : EventArgs /// /// Gets or sets the type of the event. /// - public string Type { get; set; } + public string Type { get; set; } = default!; } } diff --git a/src/Components/Web/src/WebEventDescriptor.cs b/src/Components/Web/src/WebEventDescriptor.cs index 621f0537ec70..2e063b98f9e4 100644 --- a/src/Components/Web/src/WebEventDescriptor.cs +++ b/src/Components/Web/src/WebEventDescriptor.cs @@ -27,11 +27,11 @@ public sealed class WebEventDescriptor /// /// For framework use only. /// - public string EventArgsType { get; set; } + public string EventArgsType { get; set; } = default!; /// /// For framework use only. /// - public EventFieldInfo EventFieldInfo { get; set; } + public EventFieldInfo? EventFieldInfo { get; set; } } }