Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed May 27, 2019
1 parent a3bc28d commit 5258bb2
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public bool TryEnqueue(T item)
internal struct Slot
{
/// <summary>The item.</summary>
[AllowNull,MaybeNull] public T Item; // SOS's ThreadPool command depends on this being at the beginning of the struct when T is a reference type
[AllowNull, MaybeNull] public T Item; // SOS's ThreadPool command depends on this being at the beginning of the struct when T is a reference type
/// <summary>The sequence number for this slot, used to synchronize between enqueuers and dequeuers.</summary>
public int SequenceNumber;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,7 @@ public struct Enumerator : IEnumerator<TKey>, IEnumerator
private readonly Dictionary<TKey, TValue> _dictionary;
private int _index;
private readonly int _version;
[AllowNull,MaybeNull] private TKey _currentKey;
[AllowNull, MaybeNull] private TKey _currentKey;

internal Enumerator(Dictionary<TKey, TValue> dictionary)
{
Expand Down Expand Up @@ -1588,7 +1588,7 @@ public struct Enumerator : IEnumerator<TValue>, IEnumerator
private readonly Dictionary<TKey, TValue> _dictionary;
private int _index;
private readonly int _version;
[AllowNull,MaybeNull] private TValue _currentValue;
[AllowNull, MaybeNull] private TValue _currentValue;

internal Enumerator(Dictionary<TKey, TValue> dictionary)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ public struct Enumerator : IEnumerator<T>, IEnumerator
private readonly List<T> _list;
private int _index;
private readonly int _version;
[AllowNull,MaybeNull] private T _current;
[AllowNull, MaybeNull] private T _current;

internal Enumerator(List<T> list)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public sealed class DoesNotReturnAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
public sealed class DoesNotReturnIfAttribute : Attribute
{
/// <summary>Initializes the attribute.</summary>
/// <summary>Initializes the attribute with the specified parameter value.</summary>
/// <param name="parameterValue">
/// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to
/// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to
/// the associated parameter matches this value.
/// </param>
public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,10 @@ public static bool HasCustomAttribute(
return result;
}

[return: MaybeNull]
public static AttributeType GetCustomAttribute<AttributeType>(PropertyInfo propInfo)
where AttributeType : Attribute?
public static AttributeType? GetCustomAttribute<AttributeType>(PropertyInfo propInfo)
where AttributeType : Attribute
{
AttributeType result = null!;
AttributeType? result = null;
#if (ES_BUILD_PCL || ES_BUILD_PN)
foreach (var attrib in propInfo.GetCustomAttributes<AttributeType>(false))
{
Expand All @@ -443,11 +442,10 @@ public static AttributeType GetCustomAttribute<AttributeType>(PropertyInfo propI
return result;
}

[return: MaybeNull]
public static AttributeType GetCustomAttribute<AttributeType>(Type type)
where AttributeType : Attribute?
public static AttributeType? GetCustomAttribute<AttributeType>(Type type)
where AttributeType : Attribute
{
AttributeType result = null!;
AttributeType? result = null;
#if (ES_BUILD_PCL || ES_BUILD_PN)
foreach (var attrib in type.GetTypeInfo().GetCustomAttributes<AttributeType>(false))
{
Expand Down Expand Up @@ -540,9 +538,9 @@ public static TraceLoggingTypeInfo CreateDefaultTypeInfo(

recursionCheck.Add(dataType);

var eventAttrib = Statics.GetCustomAttribute<EventDataAttribute?>(dataType);
var eventAttrib = Statics.GetCustomAttribute<EventDataAttribute>(dataType);
if (eventAttrib != null ||
Statics.GetCustomAttribute<CompilerGeneratedAttribute?>(dataType) != null ||
Statics.GetCustomAttribute<CompilerGeneratedAttribute>(dataType) != null ||
IsGenericMatch(dataType, typeof(KeyValuePair<,>)))
{
var analysis = new TypeAnalysis(dataType, eventAttrib, recursionCheck);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public TypeAnalysis(

var propertyType = propertyInfo.PropertyType;
var propertyTypeInfo = TraceLoggingTypeInfo.GetInstance(propertyType, recursionCheck);
var fieldAttribute = Statics.GetCustomAttribute<EventFieldAttribute?>(propertyInfo);
var fieldAttribute = Statics.GetCustomAttribute<EventFieldAttribute>(propertyInfo);

string propertyName =
fieldAttribute != null && fieldAttribute.Name != null
Expand Down
3 changes: 2 additions & 1 deletion src/System.Private.CoreLib/shared/System/Enum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -645,7 +646,7 @@ private static bool TryParseUInt64Enum(RuntimeType enumType, string? originalVal
}

/// <summary>Tries to parse the value of an enum with an underlying type that can't be expressed in C# (e.g. char, bool, double, etc.)</summary>
private static bool TryParseRareEnum(RuntimeType enumType, string? originalValueString, ReadOnlySpan<char> value, bool ignoreCase, bool throwOnFailure, out object? result)
private static bool TryParseRareEnum(RuntimeType enumType, string? originalValueString, ReadOnlySpan<char> value, bool ignoreCase, bool throwOnFailure, [NotNullWhen(true)] out object? result)
{
Debug.Assert(
enumType.GetEnumUnderlyingType() != typeof(sbyte) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ private static void ExecutionContextCallback(object? s)
/// <summary>A delegate to the <see cref="MoveNext()"/> method.</summary>
private Action? _moveNextAction;
/// <summary>The state machine itself.</summary>
[AllowNull,MaybeNull] public TStateMachine StateMachine = default!; // mutable struct; do not make this readonly. SOS DumpAsync command depends on this name. // TODO-NULLABLE: Remove ! when nullable attributes are respected
[AllowNull, MaybeNull] public TStateMachine StateMachine = default!; // mutable struct; do not make this readonly. SOS DumpAsync command depends on this name. // TODO-NULLABLE: Remove ! when nullable attributes are respected
/// <summary>Captured ExecutionContext with which to invoke <see cref="MoveNextAction"/>; may be null.</summary>
public ExecutionContext? Context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ private sealed class FromAsyncTrimPromise<TInstance> : Task<TResult> where TInst
internal static readonly AsyncCallback s_completeFromAsyncResult = CompleteFromAsyncResult;

/// <summary>A reference to the object on which the begin/end methods are invoked.</summary>
[AllowNull,MaybeNull] private TInstance m_thisRef;
[AllowNull, MaybeNull] private TInstance m_thisRef;
/// <summary>The end method.</summary>
private Func<TInstance, IAsyncResult, TResult>? m_endMethod;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public struct ManualResetValueTaskSourceCore<TResult>
/// <summary>Whether the current operation has completed.</summary>
private bool _completed;
/// <summary>The result with which the operation succeeded, or the default value if it hasn't yet completed or failed.</summary>
[AllowNull,MaybeNull] private TResult _result;
[AllowNull, MaybeNull] private TResult _result;
/// <summary>The exception with which the operation failed, or null if it hasn't yet completed or completed successfully.</summary>
private ExceptionDispatchInfo? _error;
/// <summary>The current version of this value, used to help prevent misuse.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ internal LinkedSlot(LinkedSlotVolatile[]? slotArray)
internal volatile LinkedSlotVolatile[]? _slotArray;

// The value for this slot.
[AllowNull,MaybeNull] internal T _value = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
[AllowNull, MaybeNull] internal T _value = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/System.Private.CoreLib/shared/System/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public static bool TryParse(string? input, [NotNullWhen(true)] out Version? resu
return (result = ParseVersion(input.AsSpan(), throwOnFailure: false)) != null;
}

public static bool TryParse(ReadOnlySpan<char> input, out Version? result) =>
public static bool TryParse(ReadOnlySpan<char> input, [NotNullWhen(true)] out Version? result) =>
(result = ParseVersion(input, throwOnFailure: false)) != null;

private static Version? ParseVersion(ReadOnlySpan<char> input, bool throwOnFailure)
Expand Down

0 comments on commit 5258bb2

Please sign in to comment.