Skip to content

Commit

Permalink
Enable nullability in ListViewGroupConverter (#6373)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetrou authored Dec 22, 2021
1 parent 57b34a9 commit 5aca3ed
Showing 1 changed file with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
Expand All @@ -23,7 +21,7 @@ internal class ListViewGroupConverter : TypeConverter
/// Determines if this converter can convert an object in the given source type to
/// the native type of the converter.
/// </summary>
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
{
if (sourceType == typeof(string) && context is not null && context.Instance is ListViewItem)
{
Expand All @@ -37,7 +35,7 @@ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceT
/// Gets a value indicating whether this converter can convert an object to the given
/// destination type using the context.
/// </summary>
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)
{
if (destinationType == typeof(InstanceDescriptor))
{
Expand All @@ -55,7 +53,7 @@ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinati
/// <summary>
/// Converts the given object to the converter's native type.
/// </summary>
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
if (value is string)
{
Expand Down Expand Up @@ -90,17 +88,16 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
/// type is string. If this cannot convert to the destination type, this will
/// throw a NotSupportedException.
/// </summary>
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
{
ArgumentNullException.ThrowIfNull(destinationType);

if (destinationType == typeof(InstanceDescriptor) && value is ListViewGroup)
{
ListViewGroup group = (ListViewGroup)value;
ConstructorInfo ctor;

// Header
ctor = typeof(ListViewGroup).GetConstructor(new Type[] { typeof(string), typeof(HorizontalAlignment) });
ConstructorInfo ctor = typeof(ListViewGroup).GetConstructor(new Type[] { typeof(string), typeof(HorizontalAlignment) })!;
Debug.Assert(ctor is not null, "Expected the constructor to exist.");
return new InstanceDescriptor(ctor, new object[] { group.Header, group.HeaderAlignment }, false);
}
Expand All @@ -118,7 +115,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul
/// validator is designed for. This will return null if the data type does not support
/// a standard set of values.
/// </summary>
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
public override StandardValuesCollection? GetStandardValues(ITypeDescriptorContext? context)
{
if (context is not null && context.Instance is ListViewItem item && item.ListView is not null)
{
Expand All @@ -141,7 +138,7 @@ public override StandardValuesCollection GetStandardValues(ITypeDescriptorContex
/// in an enum data type. If the list is not exclusive, then there are other valid values
/// besides the list of standard values GetStandardValues provides.
/// </summary>
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
public override bool GetStandardValuesExclusive(ITypeDescriptorContext? context)
{
return true;
}
Expand All @@ -150,7 +147,7 @@ public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
/// Determines if this object supports a standard set of values that can be picked
/// from a list.
/// </summary>
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
public override bool GetStandardValuesSupported(ITypeDescriptorContext? context)
{
return true;
}
Expand Down

0 comments on commit 5aca3ed

Please sign in to comment.