diff --git a/src/coreclr/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs index 7fbb594a1844de..3634e8012c21fd 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs @@ -170,7 +170,7 @@ private static Attribute[] InternalGetCustomAttributes(EventInfo element, Type t { rtAdd = rtAdd.GetParentDefinition(); if (rtAdd != null) - return rtAdd.DeclaringType!.GetEvent(ev.Name!); + return rtAdd.DeclaringType!.GetEvent(ev.Name); } return null; } diff --git a/src/coreclr/System.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs b/src/coreclr/System.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs index 4e0736cb78aa4f..763259a20a257e 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs @@ -118,7 +118,7 @@ internal void InitializeSourceInfo(bool fNeedFileInfo, Exception? exception) // ENC or the source/line info was already retrieved, the method token is 0. if (rgiMethodToken![index] != 0) { - GetSourceLineInfo(s_stackTraceSymbolsCache!, rgAssembly![index], rgAssemblyPath![index]!, rgLoadedPeAddress![index], rgiLoadedPeSize![index], rgiIsFileLayout![index], + GetSourceLineInfo(s_stackTraceSymbolsCache, rgAssembly![index], rgAssemblyPath![index], rgLoadedPeAddress![index], rgiLoadedPeSize![index], rgiIsFileLayout![index], rgInMemoryPdbAddress![index], rgiInMemoryPdbSize![index], rgiMethodToken![index], rgiILOffset![index], out rgFilename![index], out rgiLineNumber![index], out rgiColumnNumber![index]); } diff --git a/src/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs index 101fbfa7c6bc45..5b05fe76d08136 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs @@ -884,7 +884,7 @@ private static unsafe void ConfigCallback(void* configurationContext, void* name ref GCConfigurationContext context = ref Unsafe.As(ref *(byte*)configurationContext); Debug.Assert(context.Configurations != null); - Dictionary configurationDictionary = context.Configurations!; + Dictionary configurationDictionary = context.Configurations; string nameAsString = Marshal.PtrToStringUTF8((IntPtr)name)!; switch (type) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeModuleBuilder.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeModuleBuilder.cs index 2aad5096f25f05..5c5bc5d0e52217 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeModuleBuilder.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeModuleBuilder.cs @@ -416,7 +416,7 @@ private static MethodBase GetGenericMethodBaseDefinition(MethodBase methodBase) { Debug.Assert(masmi != null); - methDef = masmi.GetGenericMethodDefinition()!; + methDef = masmi.GetGenericMethodDefinition(); methDef = methDef.Module.ResolveMethod( methodBase.MetadataToken, methDef.DeclaringType?.GetGenericArguments(), @@ -1070,7 +1070,7 @@ internal int GetMethodTokenInternal(MethodBase method, Type[]? optionalParameter if (!isGenericMethodDef) { - methodInfoUnbound = methodInfo.GetGenericMethodDefinition()!; + methodInfoUnbound = methodInfo.GetGenericMethodDefinition(); } if (!Equals(methodInfoUnbound.Module) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs index f92173602ebca0..6d23b3c866c6c0 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs @@ -253,10 +253,10 @@ private RuntimeCustomAttributeData(RuntimeModule scope, MetadataToken caCtorToke m_scope = scope; m_ctor = (RuntimeConstructorInfo)RuntimeType.GetMethodBase(m_scope, caCtorToken)!; - if (m_ctor!.DeclaringType!.IsGenericType) + if (m_ctor.DeclaringType!.IsGenericType) { MetadataImport metadataScope = m_scope.MetadataImport; - Type attributeType = m_scope.ResolveType(metadataScope.GetParentToken(caCtorToken), null, null)!; + Type attributeType = m_scope.ResolveType(metadataScope.GetParentToken(caCtorToken), null, null); m_ctor = (RuntimeConstructorInfo)m_scope.ResolveMethod(caCtorToken, attributeType.GenericTypeArguments, null)!.MethodHandle.GetMethodInfo(); } diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs index 51b1f84864b1a9..8666910e37318b 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs @@ -305,7 +305,7 @@ internal ReadOnlySpan GetIndexParametersSpan() Array.Empty(); for (int i = 0; i < propParams.Length; i++) - propParams[i] = new RuntimeParameterInfo((RuntimeParameterInfo)methParams![i], this); + propParams[i] = new RuntimeParameterInfo((RuntimeParameterInfo)methParams[i], this); m_parameters = propParams; } diff --git a/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs b/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs index b8ae179ff25ce5..2bc71d3dfbd59f 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs @@ -1048,7 +1048,7 @@ internal bool IsNullHandle() public IntPtr GetFunctionPointer() { - IntPtr ptr = GetFunctionPointer(EnsureNonNullMethodInfo(m_value!).Value); + IntPtr ptr = GetFunctionPointer(EnsureNonNullMethodInfo(m_value).Value); GC.KeepAlive(m_value); return ptr; } diff --git a/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs index 0f3383db329fce..303d25d16133cf 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs @@ -567,7 +567,7 @@ private void MergeWithGlobalList(T[] list) cachedMembers = cachedMembers2; } - Debug.Assert(cachedMembers![freeSlotIndex] == null); + Debug.Assert(cachedMembers[freeSlotIndex] == null); Volatile.Write(ref cachedMembers[freeSlotIndex], newMemberInfo); // value may be read outside of lock freeSlotIndex++; } @@ -1357,7 +1357,7 @@ private void PopulateProperties( for (int j = 0; j < list.Count; j++) { - if (propertyInfo.EqualsSig(list[j]!)) + if (propertyInfo.EqualsSig(list[j])) { duplicate = true; break; diff --git a/src/coreclr/System.Private.CoreLib/src/System/String.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/String.CoreCLR.cs index 248b9a91305d80..a2c9f4f6e4e98c 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/String.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/String.CoreCLR.cs @@ -40,7 +40,7 @@ public static string Intern(string str) { ArgumentNullException.ThrowIfNull(str); Intern(new StringHandleOnStack(ref str!)); - return str!; + return str; } [LibraryImport(RuntimeHelpers.QCall, EntryPoint = "String_IsInterned")] diff --git a/src/libraries/Common/src/System/IO/PathInternal.cs b/src/libraries/Common/src/System/IO/PathInternal.cs index f13819c8ea3d62..4e4145c2ec4120 100644 --- a/src/libraries/Common/src/System/IO/PathInternal.cs +++ b/src/libraries/Common/src/System/IO/PathInternal.cs @@ -218,7 +218,7 @@ internal static bool RemoveRelativeSegments(ReadOnlySpan path, int rootLen [return: NotNullIfNotNull(nameof(path))] internal static string? TrimEndingDirectorySeparator(string? path) => EndsInDirectorySeparator(path) && !IsRoot(path.AsSpan()) ? - path!.Substring(0, path.Length - 1) : + path.Substring(0, path.Length - 1) : path; /// diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs index 33d08bf108174c..df4306da1b7ec8 100644 --- a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs +++ b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs @@ -348,7 +348,7 @@ private static IntPtr InternalGetFunctionPointer(AssemblyLoadContext alc, } else { - Delegate d = Delegate.CreateDelegate(delegateType, type, methodName)!; + Delegate d = Delegate.CreateDelegate(delegateType, type, methodName); functionPtr = Marshal.GetFunctionPointerForDelegate(d); diff --git a/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs b/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs index 7c92c4e081849a..536cf55d279fb5 100644 --- a/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs @@ -439,7 +439,7 @@ private bool Init(string path, FileMode mode, FileAccess access, FileShare share // Delete the file we've created. Debug.Assert(mode == FileMode.Create || mode == FileMode.CreateNew); - Interop.Sys.Unlink(path!); + Interop.Sys.Unlink(path); throw new IOException(SR.Format(errorInfo.Error == Interop.Error.EFBIG ? SR.IO_FileTooLarge_Path_AllocationSize diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSet.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSet.cs index 026456617f8997..421d60b036639b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSet.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSet.cs @@ -499,7 +499,7 @@ public bool Add(TAlternate item) { index = set._freeList; set._freeCount--; - Debug.Assert((StartOfFreeList - entries![set._freeList].Next) >= -1, "shouldn't overflow because `next` cannot underflow"); + Debug.Assert((StartOfFreeList - entries[set._freeList].Next) >= -1, "shouldn't overflow because `next` cannot underflow"); set._freeList = StartOfFreeList - entries[set._freeList].Next; } else @@ -551,7 +551,7 @@ public bool Remove(TAlternate item) uint collisionCount = 0; int last = -1; - int hashCode = item is not null ? comparer!.GetHashCode(item) : 0; + int hashCode = item is not null ? comparer.GetHashCode(item) : 0; ref int bucket = ref set.GetBucketRef(hashCode); int i = bucket - 1; // Value in buckets is 1-based @@ -1481,7 +1481,7 @@ private bool AddIfNotPresent(T value, out int location) { index = _freeList; _freeCount--; - Debug.Assert((StartOfFreeList - entries![_freeList].Next) >= -1, "shouldn't overflow because `next` cannot underflow"); + Debug.Assert((StartOfFreeList - entries[_freeList].Next) >= -1, "shouldn't overflow because `next` cannot underflow"); _freeList = StartOfFreeList - entries[_freeList].Next; } else diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs index d9af589f8f268d..f012603ef9d755 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs @@ -80,7 +80,7 @@ public List(IEnumerable collection) else { _items = s_emptyArray; - using (IEnumerator en = collection!.GetEnumerator()) + using (IEnumerator en = collection.GetEnumerator()) { while (en.MoveNext()) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/ActivityTracker.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/ActivityTracker.cs index 0efad03362a47e..5cb9b11658ee1c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/ActivityTracker.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/ActivityTracker.cs @@ -68,7 +68,7 @@ public void OnStart(string providerName, string activityName, int task, ref Guid if (tplDebug) { log!.DebugFacilityMessage("OnStartEnter", fullActivityName); - log!.DebugFacilityMessage("OnStartEnterActivityState", ActivityInfo.LiveActivities(currentActivity)); + log.DebugFacilityMessage("OnStartEnterActivityState", ActivityInfo.LiveActivities(currentActivity)); } if (currentActivity != null) @@ -114,7 +114,7 @@ public void OnStart(string providerName, string activityName, int task, ref Guid if (tplDebug) { log!.DebugFacilityMessage("OnStartRetActivityState", ActivityInfo.LiveActivities(newActivity)); - log!.DebugFacilityMessage1("OnStartRet", activityId.ToString(), relatedActivityId.ToString()); + log.DebugFacilityMessage1("OnStartRet", activityId.ToString(), relatedActivityId.ToString()); } } @@ -136,7 +136,7 @@ public void OnStop(string providerName, string activityName, int task, ref Guid if (tplDebug) { log!.DebugFacilityMessage("OnStopEnter", fullActivityName); - log!.DebugFacilityMessage("OnStopEnterActivityState", ActivityInfo.LiveActivities(m_current.Value)); + log.DebugFacilityMessage("OnStopEnterActivityState", ActivityInfo.LiveActivities(m_current.Value)); } while (true) // This is a retry loop. @@ -195,7 +195,7 @@ public void OnStop(string providerName, string activityName, int task, ref Guid if (tplDebug) { log!.DebugFacilityMessage("OnStopRetActivityState", ActivityInfo.LiveActivities(newCurrentActivity)); - log!.DebugFacilityMessage("OnStopRet", activityId.ToString()); + log.DebugFacilityMessage("OnStopRet", activityId.ToString()); } return; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs index b68bf0403ebec7..9d04fdf60c5c11 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs @@ -4458,7 +4458,7 @@ private static void RemoveReferencesToListenerInEventSources(EventListener liste { if (cur.m_Listener == listenerToRemove) { - CallDisableEventsIfNecessary(cur!, eventSource); + CallDisableEventsIfNecessary(cur, eventSource); } cur = cur.m_Next; diff --git a/src/libraries/System.Private.CoreLib/src/System/Enum.cs b/src/libraries/System.Private.CoreLib/src/System/Enum.cs index aa17ad8a5149c3..cb345ebac766e0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Enum.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Enum.cs @@ -1002,7 +1002,7 @@ private static bool TryParseRareTypeByValueOrName( try { - result = (TUnderlying)ToObject(enumType, Convert.ChangeType(value.ToString(), underlyingType, CultureInfo.InvariantCulture)!); + result = (TUnderlying)ToObject(enumType, Convert.ChangeType(value.ToString(), underlyingType, CultureInfo.InvariantCulture)); return true; } catch (FormatException) diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs index 52b675806f94a4..d49348f4a7c1d8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs @@ -405,7 +405,7 @@ private static bool EnumEraNames(string localeName, CalendarId calendarId, Calen // So for other calendars, only return the latest era. if (calendarId != CalendarId.JAPAN && calendarId != CalendarId.JAPANESELUNISOLAR && eraNames?.Length > 0) { - eraNames = [eraNames![^1]]; + eraNames = [eraNames[^1]]; } return result; diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs index e52739208f392c..dfe2725aec7c87 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -828,7 +828,7 @@ private static string NormalizeCultureName(string name, out bool isNeutralName) private bool InitCompatibilityCultureData() { // for compatibility handle the deprecated ids: zh-chs, zh-cht - string cultureName = _sRealName!; + string cultureName = _sRealName; string fallbackCultureName; string realCultureName; @@ -931,7 +931,7 @@ internal string CultureName // Parent name (which may be a custom locale/culture) // Ask using the real name, so that we get parents of neutrals - internal string ParentName => _sParent ??= GetLocaleInfoCore(_sRealName!, LocaleStringData.ParentName); + internal string ParentName => _sParent ??= GetLocaleInfoCore(_sRealName, LocaleStringData.ParentName); // Localized pretty name for this locale (ie: Inglis (estados Unitos)) internal string DisplayName @@ -960,7 +960,7 @@ internal string DisplayName } } - return localizedDisplayName!; + return localizedDisplayName; } } @@ -1110,8 +1110,8 @@ internal string SpecificCultureName /// abbreviated windows language name (ie: enu) (non-standard, avoid this) /// internal string ThreeLetterWindowsLanguageName => _sAbbrevLang ??= GlobalizationMode.UseNls ? - NlsGetThreeLetterWindowsLanguageName(_sRealName!) : - IcuGetThreeLetterWindowsLanguageName(_sRealName!); + NlsGetThreeLetterWindowsLanguageName(_sRealName) : + IcuGetThreeLetterWindowsLanguageName(_sRealName); /// /// Localized name for this language @@ -1155,7 +1155,7 @@ internal int GeoId { if (_iGeoId == undef && !GlobalizationMode.Invariant) { - _iGeoId = GlobalizationMode.UseNls ? NlsGetLocaleInfo(LocaleNumberData.GeoId) : IcuGetGeoId(_sRealName!); + _iGeoId = GlobalizationMode.UseNls ? NlsGetLocaleInfo(LocaleNumberData.GeoId) : IcuGetGeoId(_sRealName); } return _iGeoId; } @@ -1232,8 +1232,8 @@ internal int KeyboardLayoutId /// Console fallback name (ie: locale to use for console apps for unicode-only locales) /// internal string SCONSOLEFALLBACKNAME => _sConsoleFallbackName ??= GlobalizationMode.UseNls ? - NlsGetConsoleFallbackName(_sRealName!) : - IcuGetConsoleFallbackName(_sRealName!); + NlsGetConsoleFallbackName(_sRealName) : + IcuGetConsoleFallbackName(_sRealName); /// /// grouping of digits @@ -1818,7 +1818,7 @@ internal int ANSICodePage { if (_iDefaultAnsiCodePage == undef && !GlobalizationMode.Invariant) { - _iDefaultAnsiCodePage = GetAnsiCodePage(_sRealName!); + _iDefaultAnsiCodePage = GetAnsiCodePage(_sRealName); } return _iDefaultAnsiCodePage; } @@ -1833,7 +1833,7 @@ internal int OEMCodePage { if (_iDefaultOemCodePage == undef && !GlobalizationMode.Invariant) { - _iDefaultOemCodePage = GetOemCodePage(_sRealName!); + _iDefaultOemCodePage = GetOemCodePage(_sRealName); } return _iDefaultOemCodePage; } @@ -1848,7 +1848,7 @@ internal int MacCodePage { if (_iDefaultMacCodePage == undef && !GlobalizationMode.Invariant) { - _iDefaultMacCodePage = GetMacCodePage(_sRealName!); + _iDefaultMacCodePage = GetMacCodePage(_sRealName); } return _iDefaultMacCodePage; } @@ -1863,7 +1863,7 @@ internal int EBCDICCodePage { if (_iDefaultEbcdicCodePage == undef && !GlobalizationMode.Invariant) { - _iDefaultEbcdicCodePage = GetEbcdicCodePage(_sRealName!); + _iDefaultEbcdicCodePage = GetEbcdicCodePage(_sRealName); } return _iDefaultEbcdicCodePage; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs index 07161c81575326..c146f174ff1785 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs @@ -144,13 +144,13 @@ private static void AsyncLocalSetCurrentUICulture(AsyncLocalValueChangedArgs GlobalizationMode.Invariant ? SR.Argument_CultureNotSupportedInInvariantMode : SR.Argument_CultureNotSupported; @@ -377,7 +377,7 @@ public static CultureInfo CurrentCulture { Interlocked.CompareExchange(ref s_asyncLocalCurrentCulture, new AsyncLocal(AsyncLocalSetCurrentCulture), null); } - s_asyncLocalCurrentCulture!.Value = value; + s_asyncLocalCurrentCulture.Value = value; } } @@ -401,7 +401,7 @@ public static CultureInfo CurrentUICulture } // this one will set s_currentThreadUICulture too - s_asyncLocalCurrentUICulture!.Value = value; + s_asyncLocalCurrentUICulture.Value = value; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/JapaneseLunisolarCalendar.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/JapaneseLunisolarCalendar.cs index 85d544899fe061..fc759e0cfaf760 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/JapaneseLunisolarCalendar.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/JapaneseLunisolarCalendar.cs @@ -195,7 +195,7 @@ private static EraInfo[] TrimEras(EraInfo[] baseEras) // If we didn't copy any then something was wrong, just return base if (newIndex == 0) return baseEras; - Array.Resize(ref newEras!, newIndex); + Array.Resize(ref newEras, newIndex); return newEras; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs index a1878467759b3d..ebb0093edfe219 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs @@ -341,7 +341,7 @@ public static Assembly LoadFile(string path) // Requestor assembly was loaded using loadFrom, so look for its dependencies // in the same folder as it. // Form the name of the assembly using the path of the assembly that requested its load. - AssemblyName requestedAssemblyName = new AssemblyName(args.Name!); + AssemblyName requestedAssemblyName = new AssemblyName(args.Name); string requestedAssemblyPath = Path.Combine(Path.GetDirectoryName(requestorPath)!, requestedAssemblyName.Name + ".dll"); #if CORECLR if (AssemblyLoadContext.IsTracingEnabled()) @@ -384,7 +384,7 @@ public static Assembly LoadFrom(string assemblyFile) { if (!s_loadFromHandlerSet) { - AssemblyLoadContext.AssemblyResolve += LoadFromResolveHandler!; + AssemblyLoadContext.AssemblyResolve += LoadFromResolveHandler; s_loadFromHandlerSet = true; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs index ab5f4132c23a0e..63a22060a16696 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.cs @@ -396,11 +396,11 @@ internal void CopyBack(Span dest, ReadOnlySpan copyOfParameter { Debug.Assert(copyOfParameters[i] != null); Debug.Assert(((RuntimeType)copyOfParameters[i]!.GetType()).IsNullableOfT); - dest![i] = RuntimeMethodHandle.ReboxFromNullable(copyOfParameters[i]); + dest[i] = RuntimeMethodHandle.ReboxFromNullable(copyOfParameters[i]); } else { - dest![i] = copyOfParameters[i]; + dest[i] = copyOfParameters[i]; } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs index d64ccd64a482e0..eacbebb18cdaa8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs @@ -200,7 +200,7 @@ private static Module GetDynamicMethodsModule() AssemblyBuilderAccess.Run, AssemblyLoadContext.Default, null); // this always gets the internal module. - s_anonymouslyHostedDynamicMethodsModule = assembly.ManifestModule!; + s_anonymouslyHostedDynamicMethodsModule = assembly.ManifestModule; } return s_anonymouslyHostedDynamicMethodsModule; diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs index ed2b4cd220a3dc..1a75a10a7898cb 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs @@ -331,11 +331,11 @@ internal void CopyBack(object?[] dest, Span copyOfParameters, Span dest, Span copyOfParameters, Span< { Debug.Assert(copyOfParameters[i] != null); Debug.Assert(((RuntimeType)copyOfParameters[i]!.GetType()).IsNullableOfT); - dest![i] = RuntimeMethodHandle.ReboxFromNullable(copyOfParameters[i]); + dest[i] = RuntimeMethodHandle.ReboxFromNullable(copyOfParameters[i]); } else { - dest![i] = copyOfParameters[i]; + dest[i] = copyOfParameters[i]; } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/ModifiedFunctionPointerType.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/ModifiedFunctionPointerType.cs index 6971e1642d0683..0de9f152c6b5a1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/ModifiedFunctionPointerType.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/ModifiedFunctionPointerType.cs @@ -28,7 +28,7 @@ public override Type GetFunctionPointerReturnType() Type Initialize() { Interlocked.CompareExchange(ref _returnType, GetTypeParameter(UnmodifiedType.GetFunctionPointerReturnType(), 0), null); - return _returnType!; + return _returnType; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/ModifiedHasElementType.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/ModifiedHasElementType.cs index 19df3af6f7944c..7bdc783102f7e6 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/ModifiedHasElementType.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/ModifiedHasElementType.cs @@ -26,7 +26,7 @@ internal ModifiedHasElementType(Type unmodifiedType, TypeSignature typeSignature Type Initialize() { Interlocked.CompareExchange(ref _elementType, GetTypeParameter(UnmodifiedType.GetElementType()!, 0), null); - return _elementType!; + return _elementType; } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/NullabilityInfoContext.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/NullabilityInfoContext.cs index e9b6f9e994ff3f..0f1932124201e3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/NullabilityInfoContext.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/NullabilityInfoContext.cs @@ -422,7 +422,7 @@ private void TryLoadGenericMetaTypeNullability(MemberInfo memberInfo, Nullabilit if (metaType != null) { - CheckGenericParameters(nullability, metaMember!, metaType, memberInfo.ReflectedType); + CheckGenericParameters(nullability, metaMember, metaType, memberInfo.ReflectedType); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeNameResolver.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeNameResolver.cs index 654c7ad3f08bd7..abedd32a7f8c71 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeNameResolver.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeNameResolver.cs @@ -74,7 +74,7 @@ internal partial struct TypeNameResolver do { nestingDepth++; - current = current.DeclaringType!; + current = current.DeclaringType; } while (current.IsNested); @@ -83,7 +83,7 @@ internal partial struct TypeNameResolver while (current.IsNested) { nestedTypeNames[--nestingDepth] = TypeName.Unescape(current.Name); - current = current.DeclaringType!; + current = current.DeclaringType; } return GetType(current.FullName, nestedTypeNames, typeName); diff --git a/src/libraries/System.Private.CoreLib/src/System/Resources/FastResourceComparer.cs b/src/libraries/System.Private.CoreLib/src/System/Resources/FastResourceComparer.cs index eedae239e7bf25..77341114c588ee 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Resources/FastResourceComparer.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Resources/FastResourceComparer.cs @@ -24,7 +24,7 @@ public int GetHashCode(object key) public int GetHashCode([DisallowNull] string? key) { - return HashFunction(key!); + return HashFunction(key); } // This hash function MUST be publicly documented with the resource diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastCache.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastCache.cs index c5602eff0d2824..41effcee98dbef 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastCache.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastCache.cs @@ -140,7 +140,7 @@ private static ref CastCacheEntry Element(ref int tableData, int index) internal CastResult TryGet(nuint source, nuint target) { // table is always initialized and is not null. - return TryGet(_table!, source, target); + return TryGet(_table, source, target); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/GenericCache.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/GenericCache.cs index 2b8bd8eea7a223..94d9ecdd73bf3f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/GenericCache.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/GenericCache.cs @@ -90,7 +90,7 @@ public GenericCache(int initialCacheSize, int maxCacheSize) // Initialize to the sentinel in DEBUG as if just flushed, to ensure the sentinel can be handled in Set. CreateCacheTable(initialCacheSize) ?? #endif - _sentinelTable!; + _sentinelTable; _lastFlushSize = initialCacheSize; } @@ -141,9 +141,8 @@ private static ref Entry Element(Entry[] table, int index) [MethodImpl(MethodImplOptions.AggressiveInlining)] internal bool TryGet(TKey key, out TValue? value) { - // table is always initialized and is not null. - Entry[] table = _table!; - int hash = key!.GetHashCode(); + Entry[] table = _table; + int hash = key.GetHashCode(); int index = HashToBucket(table, hash); for (int i = 0; i < BUCKET_SIZE;) { @@ -241,7 +240,7 @@ internal bool TryGet(TKey key, out TValue? value) internal void TrySet(TKey key, TValue value) { int bucket; - int hash = key!.GetHashCode(); + int hash = key.GetHashCode(); Entry[] table; do @@ -384,7 +383,7 @@ private void FlushCurrentCache() // with the writing of the table _lastFlushSize = lastSize; // flushing is just replacing the table with a sentinel. - _table = _sentinelTable!; + _table = _sentinelTable; } private bool MaybeReplaceCacheWithLarger(int size) diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs index 9380337d37f206..2945a99d9b8c44 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs @@ -785,7 +785,7 @@ public unsafe IntPtr GetOrCreateComInterfaceForObject(object instance, CreateCom ManagedObjectWrapperHolder managedObjectWrapper = _managedObjectWrapperTable.GetOrAdd(instance, static (c, state) => { - ManagedObjectWrapper* value = state.This!.CreateManagedObjectWrapper(c, state.flags); + ManagedObjectWrapper* value = state.This.CreateManagedObjectWrapper(c, state.flags); return new ManagedObjectWrapperHolder(value, c); }, new { This = this, flags }); diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/SafeHandleMarshaller.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/SafeHandleMarshaller.cs index 0e392d1535fd86..49a0e130561f74 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/SafeHandleMarshaller.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/SafeHandleMarshaller.cs @@ -73,7 +73,7 @@ public ManagedToUnmanagedRef() // but it has never required them to be public. // We construct the handle now to ensure we don't cause an exception // before we are able to capture the unmanaged handle after the call. - _newHandle = Activator.CreateInstance()!; + _newHandle = Activator.CreateInstance(); } /// @@ -162,7 +162,7 @@ public ManagedToUnmanagedOut() // but it has never required them to be public. // We construct the handle now to ensure we don't cause an exception // before we are able to capture the unmanaged handle after the call. - _newHandle = Activator.CreateInstance()!; + _newHandle = Activator.CreateInstance(); } /// @@ -191,7 +191,7 @@ public void Free() // unnecessarily. if (!_initialized) { - _newHandle!.Dispose(); + _newHandle.Dispose(); } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs index 9f9403738ebdc4..7816d79a680d6d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs @@ -530,7 +530,7 @@ private static void SetCurrentContextualReflectionContext(AssemblyLoadContext? v { Interlocked.CompareExchange?>(ref s_asyncLocalCurrent, new AsyncLocal(), null); } - s_asyncLocalCurrent!.Value = value; // Remove ! when compiler specially-recognizes CompareExchange for nullability + s_asyncLocalCurrent.Value = value; } /// Enter scope using this AssemblyLoadContext for ContextualReflection diff --git a/src/libraries/System.Private.CoreLib/src/System/RuntimeType.cs b/src/libraries/System.Private.CoreLib/src/System/RuntimeType.cs index c243053aead38f..560ac0524f366e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/RuntimeType.cs +++ b/src/libraries/System.Private.CoreLib/src/System/RuntimeType.cs @@ -667,7 +667,7 @@ public override bool IsAssignableFrom([NotNullWhen(true)] Type? c) object? state = null; MethodBase? invokeMethod = null; - try { invokeMethod = binder.BindToMethod(bindingFlags, finalists, ref providedArgs!, modifiers, culture, namedParams, out state); } + try { invokeMethod = binder.BindToMethod(bindingFlags, finalists, ref providedArgs, modifiers, culture, namedParams, out state); } catch (MissingMethodException) { } if (invokeMethod == null) diff --git a/src/libraries/System.Private.CoreLib/src/System/StartupHookProvider.cs b/src/libraries/System.Private.CoreLib/src/System/StartupHookProvider.cs index 5a5a6db49d8585..eaf92e10beb5c4 100644 --- a/src/libraries/System.Private.CoreLib/src/System/StartupHookProvider.cs +++ b/src/libraries/System.Private.CoreLib/src/System/StartupHookProvider.cs @@ -161,7 +161,7 @@ private static void CallStartupHook(StartupHookNameOrPath startupHook) catch (Exception assemblyLoadException) { throw new ArgumentException( - SR.Format(SR.Argument_StartupHookAssemblyLoadFailed, startupHook.Path ?? startupHook.AssemblyName!.ToString()), + SR.Format(SR.Argument_StartupHookAssemblyLoadFailed, startupHook.Path ?? startupHook.AssemblyName.ToString()), assemblyLoadException); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIEncoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIEncoding.cs index 3aae57e98ef6c1..c33c8fd9090514 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIEncoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/ASCIIEncoding.cs @@ -88,7 +88,7 @@ public override unsafe int GetByteCount(char[] chars, int index, int count) ThrowHelper.ThrowArgumentOutOfRangeException((index < 0) ? ExceptionArgument.index : ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - if (chars!.Length - index < count) + if (chars.Length - index < count) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.chars, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer); } @@ -113,7 +113,7 @@ public override unsafe int GetByteCount(string chars) fixed (char* pChars = chars) { - return GetByteCountCommon(pChars, chars!.Length); + return GetByteCountCommon(pChars, chars.Length); } } @@ -222,12 +222,12 @@ public override unsafe int GetBytes(string chars, int charIndex, int charCount, resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - if (chars!.Length - charIndex < charCount) + if (chars.Length - charIndex < charCount) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.chars, ExceptionResource.ArgumentOutOfRange_IndexCount); } - if ((uint)byteIndex > bytes!.Length) + if ((uint)byteIndex > bytes.Length) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } @@ -270,12 +270,12 @@ public override unsafe int GetBytes(char[] chars, int charIndex, int charCount, resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - if (chars!.Length - charIndex < charCount) + if (chars.Length - charIndex < charCount) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.chars, ExceptionResource.ArgumentOutOfRange_IndexCount); } - if ((uint)byteIndex > bytes!.Length) + if ((uint)byteIndex > bytes.Length) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } @@ -448,7 +448,7 @@ public override unsafe int GetCharCount(byte[] bytes, int index, int count) ThrowHelper.ThrowArgumentOutOfRangeException((index < 0) ? ExceptionArgument.index : ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - if (bytes!.Length - index < count) + if (bytes.Length - index < count) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer); } @@ -561,12 +561,12 @@ public override unsafe int GetChars(byte[] bytes, int byteIndex, int byteCount, resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - if (bytes!.Length - byteIndex < byteCount) + if (bytes.Length - byteIndex < byteCount) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer); } - if ((uint)charIndex > (uint)chars!.Length) + if ((uint)charIndex > (uint)chars.Length) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.charIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } @@ -738,7 +738,7 @@ public override unsafe string GetString(byte[] bytes, int byteIndex, int byteCou resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - if (bytes!.Length - byteIndex < byteCount) + if (bytes.Length - byteIndex < byteCount) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs index e60a5eca24b1c7..77e490b03c5b68 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs @@ -1110,7 +1110,7 @@ internal void ThrowBytesOverflow(EncoderNLS? encoder, bool nothingEncoded) } // If we didn't throw, we are in convert and have to remember our flushing - encoder!.ClearMustFlush(); + encoder.ClearMustFlush(); } [DoesNotReturn] @@ -1139,7 +1139,7 @@ internal void ThrowCharsOverflow(DecoderNLS? decoder, bool nothingDecoded) } // If we didn't throw, we are in convert and have to remember our flushing - decoder!.ClearMustFlush(); + decoder.ClearMustFlush(); } internal sealed class DefaultEncoder : Encoder diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs index e129b5284bcb2a..4992ce77626646 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Latin1Encoding.cs @@ -206,12 +206,12 @@ public override unsafe int GetBytes(char[] chars, int charIndex, int charCount, resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - if (chars!.Length - charIndex < charCount) + if (chars.Length - charIndex < charCount) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.chars, ExceptionResource.ArgumentOutOfRange_IndexCount); } - if ((uint)byteIndex > bytes!.Length) + if ((uint)byteIndex > bytes.Length) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } @@ -268,12 +268,12 @@ public override unsafe int GetBytes(string s, int charIndex, int charCount, byte resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - if (s!.Length - charIndex < charCount) + if (s.Length - charIndex < charCount) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.s, ExceptionResource.ArgumentOutOfRange_IndexCount); } - if ((uint)byteIndex > bytes!.Length) + if ((uint)byteIndex > bytes.Length) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.cs index 37a13598e1657f..070b4e2c99d940 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.cs @@ -348,7 +348,7 @@ internal bool NotifyWorkItemComplete(object? threadLocalCompletionCountObject, i { Debug.Assert(threadLocalCompletionCountObject != null); - NotifyWorkItemProgress(threadLocalCompletionCountObject!, currentTimeMs); + NotifyWorkItemProgress(threadLocalCompletionCountObject, currentTimeMs); return !WorkerThread.ShouldStopProcessingWorkNow(this); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Semaphore.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Semaphore.Windows.cs index 2e0d8b4eeae789..b464a5ed81e8b6 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Semaphore.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Semaphore.Windows.cs @@ -193,7 +193,7 @@ private static OpenExistingResult OpenExistingWorker( private int ReleaseCore(int releaseCount) { - if (!Interop.Kernel32.ReleaseSemaphore(SafeWaitHandle!, releaseCount, out int previousCount)) + if (!Interop.Kernel32.ReleaseSemaphore(SafeWaitHandle, releaseCount, out int previousCount)) throw new SemaphoreFullException(); return previousCount; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadLocal.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadLocal.cs index 0f0eafe3fe0683..a67c7325ae983f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadLocal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadLocal.cs @@ -349,7 +349,7 @@ private void SetValueSlow(T value, LinkedSlotVolatile[]? slotArray) // If the slot array is not big enough to hold this ID, increase the table size. if (id >= slotArray.Length) { - GrowTable(ref slotArray!, id + 1); + GrowTable(ref slotArray, id + 1); Debug.Assert(ts_finalizationHelper != null, "Should have been initialized when this thread's slot array was created."); ts_finalizationHelper.SlotArray = slotArray; ts_slotArray = slotArray; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs index fc2a36d7bf1ecf..99455d29b80c00 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs @@ -1841,8 +1841,8 @@ public static bool QueueUserWorkItem(WaitCallback callBack, object? state) ExecutionContext? context = ExecutionContext.Capture(); object tpcallBack = (context == null || context.IsDefault) ? - new QueueUserWorkItemCallbackDefaultContext(callBack!, state) : - (object)new QueueUserWorkItemCallback(callBack!, state, context); + new QueueUserWorkItemCallbackDefaultContext(callBack, state) : + (object)new QueueUserWorkItemCallback(callBack, state, context); s_workQueue.Enqueue(tpcallBack, forceGlobal: true); @@ -1859,8 +1859,8 @@ public static bool QueueUserWorkItem(Action callBack, TState sta ExecutionContext? context = ExecutionContext.Capture(); object tpcallBack = (context == null || context.IsDefault) ? - new QueueUserWorkItemCallbackDefaultContext(callBack!, state) : - (object)new QueueUserWorkItemCallback(callBack!, state, context); + new QueueUserWorkItemCallbackDefaultContext(callBack, state) : + (object)new QueueUserWorkItemCallback(callBack, state, context); s_workQueue.Enqueue(tpcallBack, forceGlobal: !preferLocal); @@ -1888,12 +1888,12 @@ public static bool UnsafeQueueUserWorkItem(Action callBack, TSta ThrowHelper.ThrowUnexpectedStateForKnownCallback(state); } - UnsafeQueueUserWorkItemInternal((object)state!, preferLocal); + UnsafeQueueUserWorkItemInternal((object)state, preferLocal); return true; } s_workQueue.Enqueue( - new QueueUserWorkItemCallbackDefaultContext(callBack!, state), forceGlobal: !preferLocal); + new QueueUserWorkItemCallbackDefaultContext(callBack, state), forceGlobal: !preferLocal); return true; } @@ -1905,7 +1905,7 @@ public static bool UnsafeQueueUserWorkItem(WaitCallback callBack, object? state) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.callBack); } - object tpcallBack = new QueueUserWorkItemCallbackDefaultContext(callBack!, state); + object tpcallBack = new QueueUserWorkItemCallbackDefaultContext(callBack, state); s_workQueue.Enqueue(tpcallBack, forceGlobal: true); @@ -1925,7 +1925,7 @@ public static bool UnsafeQueueUserWorkItem(IThreadPoolWorkItem callBack, bool pr ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.callBack); } - UnsafeQueueUserWorkItemInternal(callBack!, preferLocal); + UnsafeQueueUserWorkItemInternal(callBack, preferLocal); return true; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Win32ThreadPoolNativeOverlapped.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Win32ThreadPoolNativeOverlapped.cs index 51464f5931e28e..5200cbe6a76514 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Win32ThreadPoolNativeOverlapped.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Win32ThreadPoolNativeOverlapped.cs @@ -216,7 +216,7 @@ internal static unsafe void CompleteWithCallback(uint errorCode, uint bytesWritt private static unsafe void OnExecutionContextCallback(object? state) { Debug.Assert(state != null); - ExecutionContextCallbackArgs args = (ExecutionContextCallbackArgs)state!; + ExecutionContextCallbackArgs args = (ExecutionContextCallbackArgs)state; uint errorCode = args._errorCode; uint bytesWritten = args._bytesWritten; diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.cs b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.cs index 9963885aad5aa7..dabd4380406dd1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.cs @@ -2009,17 +2009,17 @@ private static TimeZoneInfoResult TryGetTimeZone(string id, bool dstDisabled, ou TimeZoneInfo? zone = null; if (value!._equivalentZones == null) { - zone = new TimeZoneInfo(id, value!._baseUtcOffset, value!._displayName, value!._standardDisplayName, - value!._daylightDisplayName, value!._adjustmentRules, dstDisabled && value!._supportsDaylightSavingTime, idIsIana); - value!._equivalentZones = new List(); - lock (value!._equivalentZones) + zone = new TimeZoneInfo(id, value._baseUtcOffset, value._displayName, value._standardDisplayName, + value._daylightDisplayName, value._adjustmentRules, dstDisabled && value._supportsDaylightSavingTime, idIsIana); + value._equivalentZones = new List(); + lock (value._equivalentZones) { - value!._equivalentZones.Add(zone); + value._equivalentZones.Add(zone); } } else { - foreach (TimeZoneInfo tzi in value!._equivalentZones) + foreach (TimeZoneInfo tzi in value._equivalentZones) { if (tzi.Id == id) { @@ -2029,11 +2029,11 @@ private static TimeZoneInfoResult TryGetTimeZone(string id, bool dstDisabled, ou } if (zone == null) { - zone = new TimeZoneInfo(id, value!._baseUtcOffset, value!._displayName, value!._standardDisplayName, - value!._daylightDisplayName, value!._adjustmentRules, dstDisabled && value!._supportsDaylightSavingTime, idIsIana); - lock (value!._equivalentZones) + zone = new TimeZoneInfo(id, value._baseUtcOffset, value._displayName, value._standardDisplayName, + value._daylightDisplayName, value._adjustmentRules, dstDisabled && value._supportsDaylightSavingTime, idIsIana); + lock (value._equivalentZones) { - value!._equivalentZones.Add(zone); + value._equivalentZones.Add(zone); } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Type.Helpers.cs b/src/libraries/System.Private.CoreLib/src/System/Type.Helpers.cs index e508fc1027742f..9b9fb68afc0a64 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Type.Helpers.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Type.Helpers.cs @@ -137,7 +137,7 @@ public virtual Type[] FindInterfaces(TypeFilter filter, object? filterCriteria) for (int i = 0; i < c.Length; i++) { if (c[i] is Type t) - ret[cnt++] = t!; + ret[cnt++] = t; } return ret; } diff --git a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/AssemblyNameInfo.cs b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/AssemblyNameInfo.cs index ed71d26c08a2d2..fc6047f562df02 100644 --- a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/AssemblyNameInfo.cs +++ b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/AssemblyNameInfo.cs @@ -203,7 +203,7 @@ public AssemblyName ToAssemblyName() /// Provided assembly name was invalid. public static AssemblyNameInfo Parse(ReadOnlySpan assemblyName) => TryParse(assemblyName, out AssemblyNameInfo? result) - ? result! + ? result : throw new ArgumentException(SR.InvalidAssemblyName, nameof(assemblyName)); /// diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs index 493e206e3c423e..588a2ff4407f57 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/CustomMarshallerAttributeAnalyzer.cs @@ -645,7 +645,7 @@ public void AnalyzeAttribute(OperationAnalysisContext context) if (attr.Operation is IObjectCreationOperation attrCreation && attrCreation.Type.Equals(_customMarshallerAttribute, SymbolEqualityComparer.Default)) { - INamedTypeSymbol entryType = (INamedTypeSymbol)context.ContainingSymbol!; + INamedTypeSymbol entryType = (INamedTypeSymbol)context.ContainingSymbol; IArgumentOperation? managedTypeArgument = attrCreation.GetArgumentByOrdinal(0); if (managedTypeArgument.Value.IsNullLiteralOperation()) { diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/NativeMarshallingAttributeAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/NativeMarshallingAttributeAnalyzer.cs index 4001706b8d04ed..951913fb8a4296 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/NativeMarshallingAttributeAnalyzer.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/NativeMarshallingAttributeAnalyzer.cs @@ -93,12 +93,12 @@ public void AnalyzeAttribute(OperationAnalysisContext context) DiagnosticReporter diagnosticFactory = DiagnosticReporter.CreateForLocation(marshallerEntryPointTypeArgument.Value.Syntax.GetLocation(), context.ReportDiagnostic); diagnosticFactory.CreateAndReportDiagnostic( MarshallerEntryPointTypeMustBeNonNullRule, - GetSymbolType(context.ContainingSymbol!).ToDisplayString()); + GetSymbolType(context.ContainingSymbol).ToDisplayString()); } if (marshallerEntryPointTypeArgument.Value is ITypeOfOperation typeOfOp) { AnalyzeManagedTypeMarshallingInfo( - GetSymbolType(context.ContainingSymbol!), + GetSymbolType(context.ContainingSymbol), DiagnosticReporter.CreateForLocation(((TypeOfExpressionSyntax)typeOfOp.Syntax).Type.GetLocation(), context.ReportDiagnostic), (INamedTypeSymbol?)typeOfOp.TypeOperand); } diff --git a/src/tools/illink/src/ILLink.RoslynAnalyzer/DiagnosticDescriptors.cs b/src/tools/illink/src/ILLink.RoslynAnalyzer/DiagnosticDescriptors.cs index 345805f28a6b3d..db8ad1f61ba35b 100644 --- a/src/tools/illink/src/ILLink.RoslynAnalyzer/DiagnosticDescriptors.cs +++ b/src/tools/illink/src/ILLink.RoslynAnalyzer/DiagnosticDescriptors.cs @@ -52,8 +52,8 @@ public static DiagnosticDescriptor GetDiagnosticDescriptor(DiagnosticId diagnost } return new DiagnosticDescriptor(diagnosticId.AsString(), - lrsTitle!, - lrsMessage!, + lrsTitle, + lrsMessage, diagnosticCategory ?? diagnosticId.GetDiagnosticCategory(), diagnosticSeverity, isEnabledByDefault, diff --git a/src/tools/illink/src/ILLink.RoslynAnalyzer/ISymbolExtensions.cs b/src/tools/illink/src/ILLink.RoslynAnalyzer/ISymbolExtensions.cs index 023712a7af2a2d..51f4feff43f5e9 100644 --- a/src/tools/illink/src/ILLink.RoslynAnalyzer/ISymbolExtensions.cs +++ b/src/tools/illink/src/ILLink.RoslynAnalyzer/ISymbolExtensions.cs @@ -61,7 +61,7 @@ internal static DynamicallyAccessedMemberTypes GetDynamicallyAccessedMemberTypes if (!TryGetAttribute(symbol, DynamicallyAccessedMembersAnalyzer.DynamicallyAccessedMembersAttribute, out var dynamicallyAccessedMembers)) return DynamicallyAccessedMemberTypes.None; - return (DynamicallyAccessedMemberTypes)dynamicallyAccessedMembers!.ConstructorArguments[0].Value!; + return (DynamicallyAccessedMemberTypes)dynamicallyAccessedMembers.ConstructorArguments[0].Value!; } internal static DynamicallyAccessedMemberTypes GetDynamicallyAccessedMemberTypesOnReturnType(this IMethodSymbol methodSymbol) diff --git a/src/tools/illink/src/ILLink.RoslynAnalyzer/RequiresAssemblyFilesAnalyzer.cs b/src/tools/illink/src/ILLink.RoslynAnalyzer/RequiresAssemblyFilesAnalyzer.cs index 8a831db0718dd9..90d1cedd466876 100644 --- a/src/tools/illink/src/ILLink.RoslynAnalyzer/RequiresAssemblyFilesAnalyzer.cs +++ b/src/tools/illink/src/ILLink.RoslynAnalyzer/RequiresAssemblyFilesAnalyzer.cs @@ -142,7 +142,7 @@ protected override string GetMessageFromAttribute(AttributeData requiresAttribut { message = requiresAttribute.ConstructorArguments[0].Value?.ToString() ?? ""; if (!string.IsNullOrEmpty(message)) - message = $" {message}{(message!.TrimEnd().EndsWith(".") ? "" : ".")}"; + message = $" {message}{(message.TrimEnd().EndsWith(".") ? "" : ".")}"; } return message; } diff --git a/src/tools/illink/src/ILLink.Shared/DataFlow/ForwardDataFlowAnalysis.cs b/src/tools/illink/src/ILLink.Shared/DataFlow/ForwardDataFlowAnalysis.cs index a6db2e022b945b..5c8208539aa90e 100644 --- a/src/tools/illink/src/ILLink.Shared/DataFlow/ForwardDataFlowAnalysis.cs +++ b/src/tools/illink/src/ILLink.Shared/DataFlow/ForwardDataFlowAnalysis.cs @@ -348,13 +348,13 @@ public void Fixpoint(TControlFlowGraph cfg, TTransfer transfer) // Catch/filter regions get the initial state from the exception state of the corresponding try region. // This is already accounted for in the non-exceptional control flow state of the catch block above, // so we can just use the state we already computed, for both try and catch regions. - exceptionState!.Value = lattice.Meet(exceptionState!.Value, currentState); + exceptionState!.Value = lattice.Meet(exceptionState.Value, currentState); if (isFinallyBlock) { // Exceptions could also be thrown from inside a finally that was entered due to a previous exception. // So the exception state must also include values from the exceptional finally state (computed above). - exceptionState!.Value = lattice.Meet(exceptionState!.Value, exceptionFinallyState!.Value); + exceptionState.Value = lattice.Meet(exceptionState.Value, exceptionFinallyState!.Value); } } @@ -408,7 +408,7 @@ public void Fixpoint(TControlFlowGraph cfg, TTransfer transfer) // Filters can't contain try/catch/filters. Debug.Assert(enclosingTryOrCatch.Kind != RegionKind.Filter); Box tryOrCatchExceptionState = cfgState.GetExceptionState(enclosingTryOrCatch); - tryOrCatchExceptionState.Value = lattice.Meet(tryOrCatchExceptionState!.Value, exceptionState!.Value); + tryOrCatchExceptionState.Value = lattice.Meet(tryOrCatchExceptionState.Value, exceptionState!.Value); tryOrCatchOrFilterRegion = enclosingTryOrCatch; } } diff --git a/src/tools/illink/src/linker/Linker.Dataflow/FlowAnnotations.cs b/src/tools/illink/src/linker/Linker.Dataflow/FlowAnnotations.cs index 1010982cf86d81..92347f0b8c7392 100644 --- a/src/tools/illink/src/linker/Linker.Dataflow/FlowAnnotations.cs +++ b/src/tools/illink/src/linker/Linker.Dataflow/FlowAnnotations.cs @@ -597,8 +597,8 @@ void ValidateMethodParametersHaveNoAnnotations(DynamicallyAccessedMemberTypes[] var annotation = parameterAnnotations[parameterIndex]; if (annotation != DynamicallyAccessedMemberTypes.None) LogValidationWarning( - ov.Override.GetParameter((ParameterIndex)parameterIndex).GetCustomAttributeProvider()!, - ov.Base.GetParameter((ParameterIndex)parameterIndex).GetCustomAttributeProvider()!, + ov.Override.GetParameter((ParameterIndex)parameterIndex).GetCustomAttributeProvider(), + ov.Base.GetParameter((ParameterIndex)parameterIndex).GetCustomAttributeProvider(), ov); } } diff --git a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs index 6eda4e165992f0..26768b75b2ae90 100644 --- a/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs +++ b/src/tools/illink/src/linker/Linker.Steps/MarkStep.cs @@ -1552,7 +1552,7 @@ protected override void ProcessExtra() // This can happen when the compiler emits typerefs into IL which aren't strictly necessary per ECMA 335. foreach (TypeReference typeReference in assembly.MainModule.GetTypeReferences()) { - if (!Visited!.Add(typeReference)) + if (!Visited.Add(typeReference)) continue; markingHelpers.MarkForwardedScope(typeReference, new MessageOrigin(assembly)); } @@ -1813,7 +1813,7 @@ static bool IsDeclaredWithinType(IMemberDefinition member, TypeDefinition type) Context.LogWarning(origin, id, type.GetDisplayName(), ((MemberReference)member).GetDisplayName(), // The cast is valid since it has to be a method or field MessageFormat.FormatRequiresAttributeMessageArg(requiresUnreferencedCodeAttribute!.Message), - MessageFormat.FormatRequiresAttributeMessageArg(requiresUnreferencedCodeAttribute!.Url)); + MessageFormat.FormatRequiresAttributeMessageArg(requiresUnreferencedCodeAttribute.Url)); } bool isReflectionAccessCoveredByDAM = Annotations.FlowAnnotations.ShouldWarnWhenAccessedForReflection(member); @@ -1910,7 +1910,7 @@ void ProcessAnalysisAnnotationsForField(FieldDefinition field, DependencyKind de return; if (Annotations.ShouldSuppressAnalysisWarningsForRequiresUnreferencedCode(field, out RequiresUnreferencedCodeAttribute? requiresUnreferencedCodeAttribute)) - ReportRequiresUnreferencedCode(field.GetDisplayName(), requiresUnreferencedCodeAttribute!, new DiagnosticContext(origin, diagnosticsEnabled: true, Context)); + ReportRequiresUnreferencedCode(field.GetDisplayName(), requiresUnreferencedCodeAttribute, new DiagnosticContext(origin, diagnosticsEnabled: true, Context)); switch (dependencyKind) { diff --git a/src/tools/illink/src/linker/Linker.Steps/UnreachableBlocksOptimizer.cs b/src/tools/illink/src/linker/Linker.Steps/UnreachableBlocksOptimizer.cs index 2bee7a9ead4aa0..5c97985f0e0886 100644 --- a/src/tools/illink/src/linker/Linker.Steps/UnreachableBlocksOptimizer.cs +++ b/src/tools/illink/src/linker/Linker.Steps/UnreachableBlocksOptimizer.cs @@ -530,7 +530,7 @@ public bool RewriteBody() if (!md.HasMetadataParameters() && CanInlineInstanceCall(instrs, i)) { processor.Replace(i - 1, Instruction.Create(OpCodes.Nop)); - processor.Replace(i, result.GetPrototype()!); + processor.Replace(i, result.GetPrototype()); changed = true; } diff --git a/src/tools/illink/src/linker/Linker/TypeNameResolver.cs b/src/tools/illink/src/linker/Linker/TypeNameResolver.cs index 006ad300905a20..af0e1a27c58226 100644 --- a/src/tools/illink/src/linker/Linker/TypeNameResolver.cs +++ b/src/tools/illink/src/linker/Linker/TypeNameResolver.cs @@ -99,7 +99,7 @@ public bool TryResolveTypeName( Debug.Assert(typeName.IsSimple); TypeName topLevelTypeName = typeName; while (topLevelTypeName.IsNested) - topLevelTypeName = topLevelTypeName.DeclaringType!; + topLevelTypeName = topLevelTypeName.DeclaringType; Debug.Assert(topLevelTypeName.AssemblyName == typeName.AssemblyName); TypeDefinition? resolvedType = GetSimpleTypeFromModule(typeName, assembly.MainModule); @@ -132,7 +132,7 @@ public bool TryResolveTypeName( { if (typeName.IsNested) { - TypeDefinition? type = GetSimpleTypeFromModule(typeName.DeclaringType!, module); + TypeDefinition? type = GetSimpleTypeFromModule(typeName.DeclaringType, module); if (type == null) return null; return GetNestedType(type, TypeName.Unescape(typeName.Name));