Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
address feedback
  • Loading branch information
krwq committed Jul 5, 2021
commit b34f075643853acec532abd670b9853af90a8246

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override bool CanConvertFrom(ITypeDescriptorContext? context, Type source
/// <summary>
/// Converts the given value object to an object of Type TargetType.
/// </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 text)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override bool CanConvertFrom(ITypeDescriptorContext? context, Type source
/// Converts the given value
/// object to a Boolean object.
/// </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 text)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override bool CanConvertFrom(ITypeDescriptorContext? context, Type source
/// <summary>
/// Converts the given object to a Unicode character object.
/// </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 text)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public CollectionChangeEventArgs(CollectionChangeAction action, object? element)
/// <summary>
/// Gets the instance of the collection with the change.
/// </summary>
public virtual object? Element { get; } // TODO-NULLABLE: System.Data.Common doesn't seem to expect this to be null but we do not guard against it
public virtual object? Element { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
/// Converts the specified value object to a <see cref='System.Globalization.CultureInfo'/>
/// object.
/// </summary>
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value)
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
// Only when GetCultureName returns culture.Name, we use CultureInfoMapper
// (Since CultureInfoMapper will transfer Culture.DisplayName to Culture.Name).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
/// <summary>
/// Converts the given value object to a <see cref='System.DateTime'/> object.
/// </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 text)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
/// Converts the given value object to a <see cref='System.DateTime'/>
/// object.
/// </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 text)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ public override bool Equals([NotNullWhen(true)] object? other)
return false;
}

// TODO-NULLABLE: other should most likely be nullable but will throw NRE
public bool Equals(PropertyTabAttribute other)
{
if (other == (object)this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private static long GetEnumValue(bool isUnderlyingTypeUInt64, Enum enumVal, Cult
/// <summary>
/// Converts the specified value object to an enumeration object.
/// </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 strValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
/// <summary>
/// Converts the given object to a globally unique identifier object.
/// </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 text)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public override bool GetStandardValuesSupported(ITypeDescriptorContext? context)
/// <summary>
/// Gets a value indicating whether the given value object is valid for this type.
/// </summary>
public override bool IsValid(ITypeDescriptorContext? context, object? value)
public override bool IsValid(ITypeDescriptorContext? context, object value)
{
if (UnderlyingTypeConverter != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

// TODO-NULLABLE: This class needs more attention. Many APIs allow null properties but some other don't expect it (i.e. Find).
namespace System.ComponentModel
{
/// <summary>
Expand All @@ -21,7 +20,7 @@ public class PropertyDescriptorCollection : ICollection, IList, IDictionary

private IDictionary? _cachedFoundProperties;
private bool _cachedIgnoreCase;
private PropertyDescriptor?[] _properties;
private PropertyDescriptor[] _properties;
private readonly string[]? _namedSort;
private readonly IComparer? _comparer;
private bool _propsOwned;
Expand Down Expand Up @@ -58,7 +57,7 @@ public PropertyDescriptorCollection(PropertyDescriptor[]? properties, bool readO
_readOnly = readOnly;
}

private PropertyDescriptorCollection(PropertyDescriptor?[] properties, int propCount, string[]? namedSort, IComparer? comparer)
private PropertyDescriptorCollection(PropertyDescriptor[] properties, int propCount, string[]? namedSort, IComparer? comparer)
{
_propsOwned = false;
if (namedSort != null)
Expand Down Expand Up @@ -208,7 +207,7 @@ private void EnsureSize(int sizeNeeded)
{
if (ignoreCase)
{
if (string.Equals(_properties[i]!.Name, name, StringComparison.OrdinalIgnoreCase))
if (string.Equals(_properties[i].Name, name, StringComparison.OrdinalIgnoreCase))
{
_cachedFoundProperties[name] = _properties[i];
p = _properties[i];
Expand All @@ -217,7 +216,7 @@ private void EnsureSize(int sizeNeeded)
}
else
{
if (_properties[i]!.Name.Equals(name))
if (_properties[i].Name.Equals(name))
{
_cachedFoundProperties[name] = _properties[i];
p = _properties[i];
Expand Down Expand Up @@ -274,7 +273,7 @@ public void RemoveAt(int index)
{
Array.Copy(_properties, index + 1, _properties, index, Count - index - 1);
}
_properties[Count - 1] = null;
_properties[Count - 1] = null!;
Count--;
}

Expand All @@ -292,7 +291,7 @@ public virtual PropertyDescriptorCollection Sort()
/// Sorts the members of this PropertyDescriptorCollection. Any specified NamedSort arguments will
/// be applied first, followed by sort using the specified IComparer.
/// </summary>
public virtual PropertyDescriptorCollection Sort(string[] names)
public virtual PropertyDescriptorCollection Sort(string[]? names)
{
return new PropertyDescriptorCollection(_properties, Count, names, _comparer);
}
Expand All @@ -301,7 +300,7 @@ public virtual PropertyDescriptorCollection Sort(string[] names)
/// Sorts the members of this PropertyDescriptorCollection. Any specified NamedSort arguments will
/// be applied first, followed by sort using the specified IComparer.
/// </summary>
public virtual PropertyDescriptorCollection Sort(string[] names, IComparer comparer)
public virtual PropertyDescriptorCollection Sort(string[]? names, IComparer? comparer)
{
return new PropertyDescriptorCollection(_properties, Count, names, comparer);
}
Expand All @@ -310,7 +309,7 @@ public virtual PropertyDescriptorCollection Sort(string[] names, IComparer compa
/// Sorts the members of this PropertyDescriptorCollection, using the specified IComparer to compare,
/// the PropertyDescriptors contained in the collection.
/// </summary>
public virtual PropertyDescriptorCollection Sort(IComparer comparer)
public virtual PropertyDescriptorCollection Sort(IComparer? comparer)
{
return new PropertyDescriptorCollection(_properties, Count, _namedSort, comparer);
}
Expand Down Expand Up @@ -361,7 +360,7 @@ protected void InternalSort(string[]? names)
{
if (propList[i] != null)
{
_properties[foundCount++] = propList[i];
_properties[foundCount++] = propList[i]!;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ProvidePropertyAttribute(
}

PropertyName = propertyName;
ReceiverTypeName = receiverType.AssemblyQualifiedName!; // TODO-NULLABLE: ReceiverTypeName should be guarded against nulls
ReceiverTypeName = receiverType.AssemblyQualifiedName!;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public override bool CanConvertFrom(ITypeDescriptorContext? context, Type source
/// <summary>
/// Converts the given object to the reference 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 text)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
/// Converts the given object to a <see cref='System.TimeSpan'/>
/// object.
/// </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 text)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public virtual bool CanConvertTo(ITypeDescriptorContext? context, Type? destinat
/// <summary>
/// Converts the given value to the converter's native type.
/// </summary>
public object? ConvertFrom(object? value) => ConvertFrom(null, CultureInfo.CurrentCulture, value);
public object? ConvertFrom(object value) => ConvertFrom(null, CultureInfo.CurrentCulture, value);

/// <summary>
/// Converts the given object to the converter's native type.
/// </summary>
public virtual object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value)
public virtual object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
if (value is InstanceDescriptor instanceDescriptor)
{
Expand Down Expand Up @@ -79,7 +79,7 @@ public virtual bool CanConvertTo(ITypeDescriptorContext? context, Type? destinat
/// <summary>
/// Converts the specified text into an object.
/// </summary>
public object? ConvertFromString(string? text) => ConvertFrom(null, null, text);
public object? ConvertFromString(string text) => ConvertFrom(null, null, text);

/// <summary>
/// Converts the specified text into an object.
Expand All @@ -92,7 +92,7 @@ public virtual bool CanConvertTo(ITypeDescriptorContext? context, Type? destinat
/// <summary>
/// Converts the specified text into an object.
/// </summary>
public object? ConvertFromString(ITypeDescriptorContext? context, CultureInfo? culture, string? text)
public object? ConvertFromString(ITypeDescriptorContext? context, CultureInfo? culture, string text)
{
return ConvertFrom(context, culture, text);
}
Expand Down Expand Up @@ -307,7 +307,7 @@ protected Exception GetConvertToException(object? value, Type destinationType)
/// <summary>
/// Gets a value indicating whether the given value object is valid for this type.
/// </summary>
public virtual bool IsValid(ITypeDescriptorContext? context, object? value)
public virtual bool IsValid(ITypeDescriptorContext? context, object value)
{
bool isValid = true;
try
Expand All @@ -317,7 +317,7 @@ public virtual bool IsValid(ITypeDescriptorContext? context, object? value)
// NullableConverter would consider null value as a valid value.
if (value == null || CanConvertFrom(context, value.GetType()))
{
ConvertFrom(context, CultureInfo.InvariantCulture, value);
ConvertFrom(context, CultureInfo.InvariantCulture, value!);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,6 @@ public static EventDescriptorCollection GetEvents(
return new EventDescriptorCollection(null, true);
}

// TODO-NULLABLE: Investigate if NRE can actually happen and if we should handle it
return GetDescriptor(componentType, nameof(componentType))!.GetEvents();
}

Expand All @@ -1046,7 +1045,6 @@ public static EventDescriptorCollection GetEvents(
return new EventDescriptorCollection(null, true);
}

// TODO-NULLABLE: Investigate if NRE can actually happen and if we should handle it
EventDescriptorCollection events = GetDescriptor(componentType, nameof(componentType))!.GetEvents(attributes);

if (attributes != null && attributes.Length > 0)
Expand Down Expand Up @@ -1260,7 +1258,6 @@ public static PropertyDescriptorCollection GetProperties(
return new PropertyDescriptorCollection(null, true);
}

// TODO-NULLABLE: Investigate if NRE can actually happen and if we should handle it
return GetDescriptor(componentType, nameof(componentType))!.GetProperties();
}

Expand All @@ -1279,7 +1276,6 @@ public static PropertyDescriptorCollection GetProperties(
return new PropertyDescriptorCollection(null, true);
}

// TODO-NULLABLE: Investigate if NRE can actually happen and if we should handle it
PropertyDescriptorCollection properties = GetDescriptor(componentType, nameof(componentType))!.GetProperties(attributes);

if (attributes != null && attributes.Length > 0)
Expand Down Expand Up @@ -2694,7 +2690,6 @@ internal ComNativeDescriptionProvider(IComNativeDescriptorHandler handler)

if (instance == null)
{
// TODO-NULLABLE: If this returned new EmptyCustomTypeDescriptor() then base class's return value could likely be not null
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
/// <summary>
/// Converts the specified value object to an enumeration object.
/// </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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
/// <para>Converts the given object to a Version.</para>
/// </summary>
/// <exception cref="FormatException"><paramref name="value"/> is not a valid version string</exception>
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value)
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
if (value is string versionString)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
return destinationType == typeof(InstanceDescriptor) || base.CanConvertTo(context, destinationType);
}

public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value)
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
if (value is string strValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
return destinationType == typeof(InstanceDescriptor) || base.CanConvertTo(context, destinationType);
}

public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value)
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
if (value is string strValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
return destinationType == typeof(InstanceDescriptor) || base.CanConvertTo(context, destinationType);
}

public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value)
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
if (value is string strValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
return destinationType == typeof(InstanceDescriptor) || base.CanConvertTo(context, destinationType);
}

public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value)
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
if (value is string strValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destina
return destinationType == typeof(InstanceDescriptor) || base.CanConvertTo(context, destinationType);
}

public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object? value)
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
if (value is string strValue)
{
Expand Down
Loading