Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
5 commits merged into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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>(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; }
Expand Down Expand Up @@ -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<TArgument>(int sequence, string name, Microsoft.AspNetCore.Components.EventCallback<TArgument> value) { }
public void AddComponentReferenceCapture(int sequence, System.Action<object> componentReferenceCaptureAction) { }
public void AddComponentReferenceCapture(int sequence, System.Action<object?> componentReferenceCaptureAction) { }
public void AddContent(int sequence, Microsoft.AspNetCore.Components.MarkupString markupContent) { }
public void AddContent(int sequence, Microsoft.AspNetCore.Components.RenderFragment fragment) { }
public void AddContent(int sequence, object textContent) { }
public void AddContent(int sequence, string textContent) { }
public void AddContent<TValue>(int sequence, Microsoft.AspNetCore.Components.RenderFragment<TValue> fragment, TValue value) { }
public void AddContent(int sequence, Microsoft.AspNetCore.Components.RenderFragment? fragment) { }
public void AddContent(int sequence, object? textContent) { }
public void AddContent(int sequence, string? textContent) { }
public void AddContent<TValue>(int sequence, Microsoft.AspNetCore.Components.RenderFragment<TValue>? fragment, TValue value) { }
public void AddElementReferenceCapture(int sequence, System.Action<Microsoft.AspNetCore.Components.ElementReference> elementReferenceCaptureAction) { }
public void AddMarkupContent(int sequence, string markupContent) { }
public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>> attributes) { }
public void AddMarkupContent(int sequence, string? markupContent) { }
public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>? attributes) { }
public void Clear() { }
public void CloseComponent() { }
public void CloseElement() { }
public void CloseRegion() { }
public Microsoft.AspNetCore.Components.RenderTree.ArrayRange<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame> GetFrames() { throw null; }
public void OpenComponent(int sequence, System.Type componentType) { }
public void OpenComponent<TComponent>(int sequence) where TComponent : Microsoft.AspNetCore.Components.IComponent { }
public void OpenComponent<TComponent>(int sequence) where TComponent : notnull, Microsoft.AspNetCore.Components.IComponent { }
public void OpenElement(int sequence, string elementName) { }
public void OpenRegion(int sequence) { }
public void SetKey(object value) { }
public void SetKey(object? value) { }
public void SetUpdatesAttributeName(string updatesAttributeName) { }
void System.IDisposable.Dispose() { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>(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; }
Expand Down Expand Up @@ -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<TArgument>(int sequence, string name, Microsoft.AspNetCore.Components.EventCallback<TArgument> value) { }
public void AddComponentReferenceCapture(int sequence, System.Action<object> componentReferenceCaptureAction) { }
public void AddComponentReferenceCapture(int sequence, System.Action<object?> componentReferenceCaptureAction) { }
public void AddContent(int sequence, Microsoft.AspNetCore.Components.MarkupString markupContent) { }
public void AddContent(int sequence, Microsoft.AspNetCore.Components.RenderFragment fragment) { }
public void AddContent(int sequence, object textContent) { }
public void AddContent(int sequence, string textContent) { }
public void AddContent<TValue>(int sequence, Microsoft.AspNetCore.Components.RenderFragment<TValue> fragment, TValue value) { }
public void AddContent(int sequence, Microsoft.AspNetCore.Components.RenderFragment? fragment) { }
public void AddContent(int sequence, object? textContent) { }
public void AddContent(int sequence, string? textContent) { }
public void AddContent<TValue>(int sequence, Microsoft.AspNetCore.Components.RenderFragment<TValue>? fragment, TValue value) { }
public void AddElementReferenceCapture(int sequence, System.Action<Microsoft.AspNetCore.Components.ElementReference> elementReferenceCaptureAction) { }
public void AddMarkupContent(int sequence, string markupContent) { }
public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>> attributes) { }
public void AddMarkupContent(int sequence, string? markupContent) { }
public void AddMultipleAttributes(int sequence, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>>? attributes) { }
public void Clear() { }
public void CloseComponent() { }
public void CloseElement() { }
public void CloseRegion() { }
public Microsoft.AspNetCore.Components.RenderTree.ArrayRange<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame> GetFrames() { throw null; }
public void OpenComponent(int sequence, System.Type componentType) { }
public void OpenComponent<TComponent>(int sequence) where TComponent : Microsoft.AspNetCore.Components.IComponent { }
public void OpenComponent<TComponent>(int sequence) where TComponent : notnull, Microsoft.AspNetCore.Components.IComponent { }
public void OpenElement(int sequence, string elementName) { }
public void OpenRegion(int sequence) { }
public void SetKey(object value) { }
public void SetKey(object? value) { }
public void SetUpdatesAttributeName(string updatesAttributeName) { }
void System.IDisposable.Dispose() { }
}
Expand Down
5 changes: 2 additions & 3 deletions src/Components/Components/src/BindConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Concurrent;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection;

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

private static string FormatStringValueCore(string value, CultureInfo? culture)
private static string? FormatStringValueCore(string? value, CultureInfo? culture)
{
return value;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
31 changes: 14 additions & 17 deletions src/Components/Components/src/Rendering/RenderTreeBuilder.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -29,7 +26,7 @@ public sealed class RenderTreeBuilder : IDisposable
private readonly Stack<int> _openElementIndices = new Stack<int>();
private RenderTreeFrameType? _lastNonAttributeFrameType;
private bool _hasSeenAddMultipleAttributes;
private Dictionary<string, int> _seenAttributeNames;
private Dictionary<string, int>? _seenAttributeNames;

/// <summary>
/// The reserved parameter name used for supplying child content.
Expand Down Expand Up @@ -82,23 +79,23 @@ public void CloseElement()
/// </summary>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
/// <param name="markupContent">Content for the new markup frame.</param>
public void AddMarkupContent(int sequence, string markupContent)
public void AddMarkupContent(int sequence, string? markupContent)
=> Append(RenderTreeFrame.Markup(sequence, markupContent ?? string.Empty));

/// <summary>
/// Appends a frame representing text content.
/// </summary>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
/// <param name="textContent">Content for the new text frame.</param>
public void AddContent(int sequence, string textContent)
public void AddContent(int sequence, string? textContent)
=> Append(RenderTreeFrame.Text(sequence, textContent ?? string.Empty));

/// <summary>
/// Appends frames representing an arbitrary fragment of content.
/// </summary>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
/// <param name="fragment">Content to append.</param>
public void AddContent(int sequence, RenderFragment fragment)
public void AddContent(int sequence, RenderFragment? fragment)
{
if (fragment != null)
{
Expand All @@ -118,7 +115,7 @@ public void AddContent(int sequence, RenderFragment fragment)
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
/// <param name="fragment">Content to append.</param>
/// <param name="value">The value used by <paramref name="fragment"/>.</param>
public void AddContent<TValue>(int sequence, RenderFragment<TValue> fragment, TValue value)
public void AddContent<TValue>(int sequence, RenderFragment<TValue>? fragment, TValue value)
{
if (fragment != null)
{
Expand All @@ -139,7 +136,7 @@ public void AddContent(int sequence, MarkupString markupContent)
/// </summary>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
/// <param name="textContent">Content for the new text frame.</param>
public void AddContent(int sequence, object textContent)
public void AddContent(int sequence, object? textContent)
=> AddContent(sequence, textContent?.ToString());

/// <summary>
Expand Down Expand Up @@ -185,7 +182,7 @@ public void AddAttribute(int sequence, string name, bool value)
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
/// <param name="name">The name of the attribute.</param>
/// <param name="value">The value of the attribute.</param>
public void AddAttribute(int sequence, string name, string value)
public void AddAttribute(int sequence, string name, string? value)
{
AssertCanAddAttribute();
if (value != null || _lastNonAttributeFrameType == RenderTreeFrameType.Component)
Expand All @@ -210,7 +207,7 @@ public void AddAttribute(int sequence, string name, string value)
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
/// <param name="name">The name of the attribute.</param>
/// <param name="value">The value of the attribute.</param>
public void AddAttribute(int sequence, string name, MulticastDelegate value)
public void AddAttribute(int sequence, string name, MulticastDelegate? value)
{
AssertCanAddAttribute();
if (value != null || _lastNonAttributeFrameType == RenderTreeFrameType.Component)
Expand Down Expand Up @@ -320,7 +317,7 @@ public void AddAttribute<TArgument>(int sequence, string name, EventCallback<TAr
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
/// <param name="name">The name of the attribute.</param>
/// <param name="value">The value of the attribute.</param>
public void AddAttribute(int sequence, string name, object value)
public void AddAttribute(int sequence, string name, object? value)
{
// This looks a bit daunting because we need to handle the boxed/object version of all of the
// types that AddAttribute special cases.
Expand Down Expand Up @@ -402,7 +399,7 @@ public void AddAttribute(int sequence, in RenderTreeFrame frame)
/// </summary>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
/// <param name="attributes">A collection of key-value pairs representing attributes.</param>
public void AddMultipleAttributes(int sequence, IEnumerable<KeyValuePair<string, object>> attributes)
public void AddMultipleAttributes(int sequence, IEnumerable<KeyValuePair<string, object>>? attributes)
{
// Calling this up-front just to make sure we validate before mutating anything.
AssertCanAddAttribute();
Expand Down Expand Up @@ -455,7 +452,7 @@ public void SetUpdatesAttributeName(string updatesAttributeName)
/// </summary>
/// <typeparam name="TComponent">The type of the child component.</typeparam>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
public void OpenComponent<TComponent>(int sequence) where TComponent : IComponent
public void OpenComponent<TComponent>(int sequence) where TComponent : notnull, IComponent
=> OpenComponentUnchecked(sequence, typeof(TComponent));

/// <summary>
Expand All @@ -477,7 +474,7 @@ public void OpenComponent(int sequence, Type componentType)
/// Assigns the specified key value to the current element or component.
/// </summary>
/// <param name="value">The value for the key.</param>
public void SetKey(object value)
public void SetKey(object? value)
{
if (value == null)
{
Expand Down Expand Up @@ -560,7 +557,7 @@ public void AddElementReferenceCapture(int sequence, Action<ElementReference> el
/// </summary>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
/// <param name="componentReferenceCaptureAction">An action to be invoked whenever the reference value changes.</param>
public void AddComponentReferenceCapture(int sequence, Action<object> componentReferenceCaptureAction)
public void AddComponentReferenceCapture(int sequence, Action<object?> componentReferenceCaptureAction)
{
var parentFrameIndex = GetCurrentParentFrameIndex();
if (!parentFrameIndex.HasValue)
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;$(DefaultNetCoreTargetFramework)</TargetFrameworks>
<TargetFrameworks Condition="'$(DotNetBuildFromSource)' == 'true'">$(DefaultNetCoreTargetFramework)</TargetFrameworks>
<Nullable>annotations</Nullable>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<Compile Include="Microsoft.AspNetCore.Components.Forms.netstandard2.0.cs" />
Expand Down
Loading