Skip to content
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

fixup nullability declarations #188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions Framework.Core/System/Collections/Generic/HashSetEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public bool TryGetValue(T equalValue, [MaybeNullWhen(false)] out T actualValue)

private sealed class SpyEqualityComparer : IEqualityComparer<T>
{
private readonly Threading.ThreadLocal<Action<T, T>?> _callback = new();
private readonly Threading.ThreadLocal<Action<T?, T?>?> _callback = new();
private readonly IEqualityComparer<T> _wrapped;

private SpyEqualityComparer(IEqualityComparer<T> wrapped)
Expand All @@ -207,7 +207,7 @@ public static IEqualityComparer<T> GetFrom(IEqualityComparer<T>? comparer)
return new SpyEqualityComparer(comparer);
}

public bool Equals(T x, T y)
public bool Equals(T? x, T? y)
{
GetCallback()?.Invoke(x, y);
return _wrapped.Equals(x, y);
Expand All @@ -218,12 +218,12 @@ public int GetHashCode(T obj)
return _wrapped.GetHashCode(obj);
}

public void SetCallback(Action<T, T>? callback)
public void SetCallback(Action<T?, T?>? callback)
{
_callback.Value = callback;
}

private Action<T, T>? GetCallback()
private Action<T?, T?>? GetCallback()
{
if (!_callback.IsValueCreated || _callback.Value == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ TValue IDictionary<TKey, TValue>.this[TKey key]
set => throw new NotSupportedException();
}

void IDictionary.Add(object key, object value)
void IDictionary.Add(object key, object? value)
{
throw new NotSupportedException();
}
Expand Down
4 changes: 2 additions & 2 deletions Framework.Core/System/Progress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ protected virtual void OnReport(T value)
}
}

private void Callback(object value)
private void Callback(object? value)
{
var valueT = (T)value;
var valueT = (T)value!;
var progressChanged = ProgressChanged;
progressChanged?.Invoke(this, valueT);
}
Expand Down
36 changes: 18 additions & 18 deletions Framework.Core/System/Reflection/CustomAttributeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class CustomAttributeExtensions
/// <returns>
/// A custom attribute that matches <paramref name="attributeType" />, or null if no such attribute is found.
/// </returns>
public static Attribute GetCustomAttribute(this Assembly element, Type attributeType)
public static Attribute? GetCustomAttribute(this Assembly element, Type attributeType)
{
return Attribute.GetCustomAttribute(element, attributeType);
}
Expand All @@ -35,7 +35,7 @@ public static Attribute GetCustomAttribute(this Assembly element, Type attribute
/// <returns>
/// A custom attribute that matches <paramref name="attributeType" />, or null if no such attribute is found.
/// </returns>
public static Attribute GetCustomAttribute(this Module element, Type attributeType)
public static Attribute? GetCustomAttribute(this Module element, Type attributeType)
{
return Attribute.GetCustomAttribute(element, attributeType);
}
Expand All @@ -48,7 +48,7 @@ public static Attribute GetCustomAttribute(this Module element, Type attributeTy
/// <returns>
/// A custom attribute that matches <paramref name="attributeType" />, or null if no such attribute is found.
/// </returns>
public static Attribute GetCustomAttribute(this MemberInfo element, Type attributeType)
public static Attribute? GetCustomAttribute(this MemberInfo element, Type attributeType)
{
return Attribute.GetCustomAttribute(element, attributeType);
}
Expand All @@ -61,7 +61,7 @@ public static Attribute GetCustomAttribute(this MemberInfo element, Type attribu
/// <returns>
/// A custom attribute that matches <paramref name="attributeType" />, or null if no such attribute is found.
/// </returns>
public static Attribute GetCustomAttribute(this ParameterInfo element, Type attributeType)
public static Attribute? GetCustomAttribute(this ParameterInfo element, Type attributeType)
{
return Attribute.GetCustomAttribute(element, attributeType);
}
Expand All @@ -74,9 +74,9 @@ public static Attribute GetCustomAttribute(this ParameterInfo element, Type attr
/// <returns>
/// A custom attribute that matches <typeparamref name="T" />, or null if no such attribute is found.
/// </returns>
public static T GetCustomAttribute<T>(this Assembly element) where T : Attribute
public static T? GetCustomAttribute<T>(this Assembly element) where T : Attribute
{
return (T)GetCustomAttribute(element, typeof(T));
return (T?)GetCustomAttribute(element, typeof(T));
}

/// <summary>
Expand All @@ -87,9 +87,9 @@ public static T GetCustomAttribute<T>(this Assembly element) where T : Attribute
/// <returns>
/// A custom attribute that matches <typeparamref name="T" />, or null if no such attribute is found.
/// </returns>
public static T GetCustomAttribute<T>(this Module element) where T : Attribute
public static T? GetCustomAttribute<T>(this Module element) where T : Attribute
{
return (T)GetCustomAttribute(element, typeof(T));
return (T?)GetCustomAttribute(element, typeof(T));
}

/// <summary>
Expand All @@ -100,9 +100,9 @@ public static T GetCustomAttribute<T>(this Module element) where T : Attribute
/// <returns>
/// A custom attribute that matches <typeparamref name="T" />, or null if no such attribute is found.
/// </returns>
public static T GetCustomAttribute<T>(this MemberInfo element) where T : Attribute
public static T? GetCustomAttribute<T>(this MemberInfo element) where T : Attribute
{
return (T)GetCustomAttribute(element, typeof(T));
return (T?)GetCustomAttribute(element, typeof(T));
}

/// <summary>
Expand All @@ -113,9 +113,9 @@ public static T GetCustomAttribute<T>(this MemberInfo element) where T : Attribu
/// <returns>
/// A custom attribute that matches <typeparamref name="T" />, or null if no such attribute is found.
/// </returns>
public static T GetCustomAttribute<T>(this ParameterInfo element) where T : Attribute
public static T? GetCustomAttribute<T>(this ParameterInfo element) where T : Attribute
{
return (T)GetCustomAttribute(element, typeof(T));
return (T?)GetCustomAttribute(element, typeof(T));
}

/// <summary>
Expand All @@ -127,7 +127,7 @@ public static T GetCustomAttribute<T>(this ParameterInfo element) where T : Attr
/// <returns>
/// A custom attribute that matches <paramref name="attributeType" />, or null if no such attribute is found.
/// </returns>
public static Attribute GetCustomAttribute(this MemberInfo element, Type attributeType, bool inherit)
public static Attribute? GetCustomAttribute(this MemberInfo element, Type attributeType, bool inherit)
{
return Attribute.GetCustomAttribute(element, attributeType, inherit);
}
Expand All @@ -141,7 +141,7 @@ public static Attribute GetCustomAttribute(this MemberInfo element, Type attribu
/// <returns>
/// A custom attribute that matches <paramref name="attributeType" />, or null if no such attribute is found.
/// </returns>
public static Attribute GetCustomAttribute(this ParameterInfo element, Type attributeType, bool inherit)
public static Attribute? GetCustomAttribute(this ParameterInfo element, Type attributeType, bool inherit)
{
return Attribute.GetCustomAttribute(element, attributeType, inherit);
}
Expand All @@ -155,9 +155,9 @@ public static Attribute GetCustomAttribute(this ParameterInfo element, Type attr
/// <returns>
/// A custom attribute that matches <typeparamref name="T" />, or null if no such attribute is found.
/// </returns>
public static T GetCustomAttribute<T>(this MemberInfo element, bool inherit) where T : Attribute
public static T? GetCustomAttribute<T>(this MemberInfo element, bool inherit) where T : Attribute
{
return (T)GetCustomAttribute(element, typeof(T), inherit);
return (T?)GetCustomAttribute(element, typeof(T), inherit);
}

/// <summary>
Expand All @@ -169,9 +169,9 @@ public static T GetCustomAttribute<T>(this MemberInfo element, bool inherit) whe
/// <returns>
/// A custom attribute that matches <typeparamref name="T" />, or null if no such attribute is found.
/// </returns>
public static T GetCustomAttribute<T>(this ParameterInfo element, bool inherit) where T : Attribute
public static T? GetCustomAttribute<T>(this ParameterInfo element, bool inherit) where T : Attribute
{
return (T)GetCustomAttribute(element, typeof(T), inherit);
return (T?)GetCustomAttribute(element, typeof(T), inherit);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace System.Reflection
public static class PropertyInfoTheraotExtensions
{
[MethodImpl(MethodImplOptionsEx.AggressiveInlining)]
public static object GetValue(this PropertyInfo info, object obj)
public static object? GetValue(this PropertyInfo info, object obj)
{
if (info == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static MethodInfo GetRuntimeBaseDefinition(this MethodInfo method)
return method.GetBaseDefinition();
}

public static EventInfo GetRuntimeEvent(this Type type, string name)
public static EventInfo? GetRuntimeEvent(this Type type, string name)
{
if (type == null)
{
Expand All @@ -46,7 +46,7 @@ public static IEnumerable<EventInfo> GetRuntimeEvents(this Type type)
return type.GetEvents();
}

public static FieldInfo GetRuntimeField(this Type type, string name)
public static FieldInfo? GetRuntimeField(this Type type, string name)
{
if (type == null)
{
Expand Down Expand Up @@ -76,7 +76,7 @@ public static InterfaceMapping GetRuntimeInterfaceMap(this Type typeInfo, Type i
return typeInfo.GetInterfaceMap(interfaceType);
}

public static MethodInfo GetRuntimeMethod(this Type type, string name, Type[] parameters)
public static MethodInfo? GetRuntimeMethod(this Type type, string name, Type[] parameters)
{
if (type == null)
{
Expand Down Expand Up @@ -106,7 +106,7 @@ public static IEnumerable<PropertyInfo> GetRuntimeProperties(this Type type)
return type.GetProperties();
}

public static PropertyInfo GetRuntimeProperty(this Type type, string name)
public static PropertyInfo? GetRuntimeProperty(this Type type, string name)
{
if (type == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ internal static void ThrowOnContext(Exception exception, SynchronizationContext?
{
try
{
targetContext.Post(state => throw TaskAwaiter.PrepareExceptionForRethrow((Exception)state), exception);
targetContext.Post(state => throw TaskAwaiter.PrepareExceptionForRethrow((Exception)state!), exception);
return;
}
catch (Exception ex)
Expand All @@ -79,7 +79,7 @@ internal static void ThrowOnContext(Exception exception, SynchronizationContext?
}
}

ThreadPool.QueueUserWorkItem(state => throw TaskAwaiter.PrepareExceptionForRethrow((Exception)state), exception);
ThreadPool.QueueUserWorkItem(state => throw TaskAwaiter.PrepareExceptionForRethrow((Exception)state!), exception);
}

/// <summary>
Expand Down Expand Up @@ -130,14 +130,14 @@ private sealed class MoveNextRunner
/// <summary>
/// The context with which to run MoveNext.
/// </summary>
private readonly ExecutionContext _context;
private readonly ExecutionContext? _context;

/// <summary>
/// Initializes the runner.
/// </summary>
/// <param name="context">The context with which to run MoveNext.</param>
[SecurityCritical]
internal MoveNextRunner(ExecutionContext context)
internal MoveNextRunner(ExecutionContext? context)
{
_context = context;
}
Expand Down Expand Up @@ -170,9 +170,9 @@ private static ContextCallback GetInvokeMoveNext()
_invokeMoveNext = callback;
return callback;

static void InvokeMoveNext(object stateMachine)
static void InvokeMoveNext(object? stateMachine)
{
((IAsyncStateMachine)stateMachine).MoveNext();
((IAsyncStateMachine)stateMachine!).MoveNext();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public struct AsyncVoidMethodBuilder : IAsyncMethodBuilder
/// <summary>
/// The synchronization context associated with this operation.
/// </summary>
private readonly SynchronizationContext _synchronizationContext;
private readonly SynchronizationContext? _synchronizationContext;

/// <summary>
/// State related to the IAsyncStateMachine.
Expand All @@ -43,7 +43,7 @@ static AsyncVoidMethodBuilder()
/// Initializes the <see cref="AsyncVoidMethodBuilder" />.
/// </summary>
/// <param name="synchronizationContext">The synchronizationContext associated with this operation. This may be null.</param>
private AsyncVoidMethodBuilder(SynchronizationContext synchronizationContext)
private AsyncVoidMethodBuilder(SynchronizationContext? synchronizationContext)
{
_synchronizationContext = synchronizationContext;
synchronizationContext?.OperationStarted();
Expand Down Expand Up @@ -215,7 +215,7 @@ private readonly void NotifySynchronizationContextOfCompletion()
{
try
{
_synchronizationContext.OperationCompleted();
_synchronizationContext?.OperationCompleted();
Copy link
Collaborator Author

@OwnageIsMagic OwnageIsMagic Jul 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about this one (should it be ! ?)

}
catch (Exception ex)
{
Expand Down
4 changes: 2 additions & 2 deletions Framework.Core/System/Runtime/CompilerServices/TaskAwaiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ internal static void OnCompletedInternal(Task task, Action continuation, bool co
{
try
{
syncContext.Post(state => ((Action)state)(), continuation);
syncContext.Post(state => ((Action)state!)(), continuation);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -317,7 +317,7 @@ private static void ThrowForNonSuccess(Task task)
case TaskStatus.Canceled:
throw new TaskCanceledException(task);
case TaskStatus.Faulted:
throw PrepareExceptionForRethrow(task.Exception!.InnerException);
throw PrepareExceptionForRethrow(task.Exception!.InnerException!);
default:
throw new InvalidOperationException("The task has not yet completed.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public void UnsafeOnCompleted(Action continuation)

/// <summary>Runs an Action delegate provided as state.</summary>
/// <param name="state">The Action delegate to invoke.</param>
private static void RunAction(object state)
private static void RunAction(object? state)
{
((Action)state)();
((Action)state!)();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ public sealed class ExceptionDispatchInfo
private ExceptionDispatchInfo(Exception exception)
{
SourceException = exception;
_stackTrace = SourceException.StackTrace;
if (_stackTrace != null)
if (SourceException.StackTrace is { } sourceExceptionStackTrace)
{
_stackTrace +=
_stackTrace = sourceExceptionStackTrace +
$"{Environment.NewLine}---End of stack trace from previous location where exception was thrown ---{Environment.NewLine}";
}
else
Expand Down Expand Up @@ -123,7 +122,7 @@ private static FieldInfo GetFieldInfo()
); // MS.Net

// ---
return _remoteStackTraceString;
return _remoteStackTraceString!;
}

private static void SetStackTrace(Exception exception, object value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private void SignalCompletion()
#if TARGETS_NET || TARGETS_NETCORE || GREATERTHAN_NETSTANDARD13
if (_executionContext != null)
{
ExecutionContext.Run(_executionContext, s => ((ManualResetValueTaskSourceCore<TResult>)s).InvokeContinuation(), this);
ExecutionContext.Run(_executionContext, s => ((ManualResetValueTaskSourceCore<TResult>)s!).InvokeContinuation(), this);
return;
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions Framework.Core/System/Threading/Tasks/TaskEx.whenall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private static void AddPotentiallyUnwrappedExceptions(ref List<Exception>? targe

if (exception is AggregateException aggregateException)
{
targetList.Add(aggregateException.InnerExceptions.Count == 1 ? exception.InnerException : exception);
targetList.Add(aggregateException.InnerExceptions.Count == 1 ? exception.InnerException! : exception);
}
else
{
Expand Down Expand Up @@ -180,7 +180,7 @@ private static Task<TResult> WhenAllCore<TResult>(IEnumerable<Task> tasks, Actio
{
if (task.IsFaulted)
{
AddPotentiallyUnwrappedExceptions(ref exceptions, task.Exception);
AddPotentiallyUnwrappedExceptions(ref exceptions, task.Exception!);
}
else
{
Expand Down
Loading