throw new ArgumentNullException(nameof(info));
}
- _dateTime = (DateTime)info.GetValue("DateTime", typeof(DateTime)); // Do not rename (binary serialization)
- _offsetMinutes = (short)info.GetValue("OffsetMinutes", typeof(short)); // Do not rename (binary serialization)
+ _dateTime = (DateTime)info.GetValue("DateTime", typeof(DateTime))!; // Do not rename (binary serialization)
+ _offsetMinutes = (short)info.GetValue("OffsetMinutes", typeof(short))!; // Do not rename (binary serialization)
}
// Returns the hash code for this DateTimeOffset.
// For Boolean, we cache all possible values.
if (typeof(TResult) == typeof(bool)) // only the relevant branches are kept for each value-type generic instantiation
{
- bool value = (bool)(object?)result;
+ bool value = (bool)(object)result!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34976
Task<bool> task = value ? AsyncTaskCache.TrueTask : AsyncTaskCache.FalseTask;
return Unsafe.As<Task<TResult>>(task); // UnsafeCast avoids type check we know will succeed
}
// Compare to constants to avoid static field access if outside of cached range.
// We compare to the upper bound first, as we're more likely to cache miss on the upper side than on the
// lower side, due to positive values being more common than negative as return values.
- int value = (int)(object?)result;
+ int value = (int)(object)result!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34976
if (value < AsyncTaskCache.EXCLUSIVE_INT32_MAX &&
value >= AsyncTaskCache.INCLUSIVE_INT32_MIN)
{
}
// For other known value types, we only special-case 0 / default(TResult).
else if (
- (typeof(TResult) == typeof(uint) && default == (uint)(object?)result) ||
- (typeof(TResult) == typeof(byte) && default(byte) == (byte)(object?)result) ||
- (typeof(TResult) == typeof(sbyte) && default(sbyte) == (sbyte)(object?)result) ||
- (typeof(TResult) == typeof(char) && default(char) == (char)(object?)result) ||
- (typeof(TResult) == typeof(long) && default == (long)(object?)result) ||
- (typeof(TResult) == typeof(ulong) && default == (ulong)(object?)result) ||
- (typeof(TResult) == typeof(short) && default(short) == (short)(object?)result) ||
- (typeof(TResult) == typeof(ushort) && default(ushort) == (ushort)(object?)result) ||
- (typeof(TResult) == typeof(IntPtr) && default == (IntPtr)(object?)result) ||
- (typeof(TResult) == typeof(UIntPtr) && default == (UIntPtr)(object?)result))
+ (typeof(TResult) == typeof(uint) && default == (uint)(object)result!) ||
+ (typeof(TResult) == typeof(byte) && default(byte) == (byte)(object)result!) ||
+ (typeof(TResult) == typeof(sbyte) && default(sbyte) == (sbyte)(object)result!) ||
+ (typeof(TResult) == typeof(char) && default(char) == (char)(object)result!) ||
+ (typeof(TResult) == typeof(long) && default == (long)(object)result!) ||
+ (typeof(TResult) == typeof(ulong) && default == (ulong)(object)result!) ||
+ (typeof(TResult) == typeof(short) && default(short) == (short)(object)result!) ||
+ (typeof(TResult) == typeof(ushort) && default(ushort) == (ushort)(object)result!) ||
+ (typeof(TResult) == typeof(IntPtr) && default == (IntPtr)(object)result!) ||
+ (typeof(TResult) == typeof(UIntPtr) && default == (UIntPtr)(object)result!)) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34976
{
return s_defaultResultTask;
}
public bool GetBoolean(string name)
{
Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(bool)) ? (bool)value : _converter.ToBoolean(value!); // if value is null To* method will either deal with it or throw
+ object value = GetElement(name, out foundType)!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34976
+ return ReferenceEquals(foundType, typeof(bool)) ? (bool)value : _converter.ToBoolean(value); // if value is null To* method will either deal with it or throw
}
public char GetChar(string name)
{
Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(char)) ? (char)value : _converter.ToChar(value!);
+ object value = GetElement(name, out foundType)!;
+ return ReferenceEquals(foundType, typeof(char)) ? (char)value : _converter.ToChar(value);
}
[CLSCompliant(false)]
public sbyte GetSByte(string name)
{
Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(sbyte)) ? (sbyte)value : _converter.ToSByte(value!);
+ object value = GetElement(name, out foundType)!;
+ return ReferenceEquals(foundType, typeof(sbyte)) ? (sbyte)value : _converter.ToSByte(value);
}
public byte GetByte(string name)
{
Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(byte)) ? (byte)value : _converter.ToByte(value!);
+ object value = GetElement(name, out foundType)!;
+ return ReferenceEquals(foundType, typeof(byte)) ? (byte)value : _converter.ToByte(value);
}
public short GetInt16(string name)
{
Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(short)) ? (short)value : _converter.ToInt16(value!);
+ object value = GetElement(name, out foundType)!;
+ return ReferenceEquals(foundType, typeof(short)) ? (short)value : _converter.ToInt16(value);
}
[CLSCompliant(false)]
public ushort GetUInt16(string name)
{
Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(ushort)) ? (ushort)value : _converter.ToUInt16(value!);
+ object value = GetElement(name, out foundType)!;
+ return ReferenceEquals(foundType, typeof(ushort)) ? (ushort)value : _converter.ToUInt16(value);
}
public int GetInt32(string name)
{
Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(int)) ? (int)value : _converter.ToInt32(value!);
+ object value = GetElement(name, out foundType)!;
+ return ReferenceEquals(foundType, typeof(int)) ? (int)value : _converter.ToInt32(value);
}
[CLSCompliant(false)]
public uint GetUInt32(string name)
{
Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(uint)) ? (uint)value : _converter.ToUInt32(value!);
+ object value = GetElement(name, out foundType)!;
+ return ReferenceEquals(foundType, typeof(uint)) ? (uint)value : _converter.ToUInt32(value);
}
public long GetInt64(string name)
{
Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(long)) ? (long)value : _converter.ToInt64(value!);
+ object value = GetElement(name, out foundType)!;
+ return ReferenceEquals(foundType, typeof(long)) ? (long)value : _converter.ToInt64(value);
}
[CLSCompliant(false)]
public ulong GetUInt64(string name)
{
Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(ulong)) ? (ulong)value : _converter.ToUInt64(value!);
+ object value = GetElement(name, out foundType)!;
+ return ReferenceEquals(foundType, typeof(ulong)) ? (ulong)value : _converter.ToUInt64(value);
}
public float GetSingle(string name)
{
Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(float)) ? (float)value : _converter.ToSingle(value!);
+ object value = GetElement(name, out foundType)!;
+ return ReferenceEquals(foundType, typeof(float)) ? (float)value : _converter.ToSingle(value);
}
public double GetDouble(string name)
{
Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(double)) ? (double)value : _converter.ToDouble(value!);
+ object value = GetElement(name, out foundType)!;
+ return ReferenceEquals(foundType, typeof(double)) ? (double)value : _converter.ToDouble(value);
}
public decimal GetDecimal(string name)
{
Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(decimal)) ? (decimal)value : _converter.ToDecimal(value!);
+ object value = GetElement(name, out foundType)!;
+ return ReferenceEquals(foundType, typeof(decimal)) ? (decimal)value : _converter.ToDecimal(value);
}
public DateTime GetDateTime(string name)
{
Type foundType;
- object? value = GetElement(name, out foundType);
- return ReferenceEquals(foundType, typeof(DateTime)) ? (DateTime)value : _converter.ToDateTime(value!);
+ object value = GetElement(name, out foundType)!;
+ return ReferenceEquals(foundType, typeof(DateTime)) ? (DateTime)value : _converter.ToDateTime(value);
}
public string? GetString(string name)
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-#nullable enable
// The worker functions in this file was optimized for performance. If you make changes
// you should use care to consider all of the interesting cases.
// The fast loops attempts to blaze through as fast as possible with optimistic range checks,
// processing multiple characters at a time, and falling back to the slow loop for all special cases.
+#nullable enable
using System;
using System.Buffers;
using System.Diagnostics;
ThrowHelper.ThrowArgumentOutOfRangeException((index < 0) ? ExceptionArgument.index : ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
}
- if (chars.Length - index < count)
+ if (chars!.Length - index < count) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.chars, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
}
fixed (char* pChars = chars)
{
- return GetByteCountCommon(pChars, chars.Length);
+ return GetByteCountCommon(pChars, chars!.Length); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
}
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)] // called directly by GetCharCountCommon
- private protected sealed override unsafe int GetByteCountFast(char* pChars, int charsLength, EncoderFallback fallback, out int charsConsumed)
+ private protected sealed override unsafe int GetByteCountFast(char* pChars, int charsLength, EncoderFallback? fallback, out int charsConsumed)
{
// The number of UTF-8 code units may exceed the number of UTF-16 code units,
// so we'll need to check for overflow before casting to Int32.
resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
}
- if (s.Length - charIndex < charCount)
+ if (s!.Length - charIndex < charCount) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.s, ExceptionResource.ArgumentOutOfRange_IndexCount);
}
- if ((uint)byteIndex > bytes.Length)
+ if ((uint)byteIndex > bytes!.Length) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_Index);
}
resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
}
- if (chars.Length - charIndex < charCount)
+ if (chars!.Length - charIndex < charCount) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.chars, ExceptionResource.ArgumentOutOfRange_IndexCount);
}
- if ((uint)byteIndex > bytes.Length)
+ if ((uint)byteIndex > bytes!.Length) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_Index);
}
ThrowHelper.ThrowArgumentOutOfRangeException((index < 0) ? ExceptionArgument.index : ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
}
- if (bytes.Length - index < count)
+ if (bytes!.Length - index < count) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
}
resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
}
- if (bytes.Length - byteIndex < byteCount)
+ if (bytes!.Length - byteIndex < byteCount) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
}
- if ((uint)charIndex > (uint)chars.Length)
+ if ((uint)charIndex > (uint)chars!.Length) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.charIndex, ExceptionResource.ArgumentOutOfRange_Index);
}
return (int)(pOutputBufferRemaining - pChars);
}
- private protected sealed override unsafe int GetCharsWithFallback(ReadOnlySpan<byte> bytes, int originalBytesLength, Span<char> chars, int originalCharsLength, DecoderNLS decoder)
+ private protected sealed override unsafe int GetCharsWithFallback(ReadOnlySpan<byte> bytes, int originalBytesLength, Span<char> chars, int originalCharsLength, DecoderNLS? decoder)
{
// We special-case DecoderReplacementFallback if it's telling us to write a single U+FFFD char,
// since we believe this to be relatively common and we can handle it more efficiently than
resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
}
- if (bytes.Length - index < count)
+ if (bytes!.Length - index < count) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)] // called directly by GetCharCountCommon
- private protected sealed override unsafe int GetCharCountFast(byte* pBytes, int bytesLength, DecoderFallback fallback, out int bytesConsumed)
+ private protected sealed override unsafe int GetCharCountFast(byte* pBytes, int bytesLength, DecoderFallback? fallback, out int bytesConsumed)
{
// The number of UTF-16 code units will never exceed the number of UTF-8 code units,
// so the addition at the end of this method will not overflow.
throw new ArgumentNullException(nameof(info));
}
- _dateStart = (DateTime)info.GetValue("DateStart", typeof(DateTime)); // Do not rename (binary serialization)
- _dateEnd = (DateTime)info.GetValue("DateEnd", typeof(DateTime)); // Do not rename (binary serialization)
- _daylightDelta = (TimeSpan)info.GetValue("DaylightDelta", typeof(TimeSpan)); // Do not rename (binary serialization)
- _daylightTransitionStart = (TransitionTime)info.GetValue("DaylightTransitionStart", typeof(TransitionTime)); // Do not rename (binary serialization)
- _daylightTransitionEnd = (TransitionTime)info.GetValue("DaylightTransitionEnd", typeof(TransitionTime)); // Do not rename (binary serialization)
+ _dateStart = (DateTime)info.GetValue("DateStart", typeof(DateTime))!; // Do not rename (binary serialization)
+ _dateEnd = (DateTime)info.GetValue("DateEnd", typeof(DateTime))!; // Do not rename (binary serialization)
+ _daylightDelta = (TimeSpan)info.GetValue("DaylightDelta", typeof(TimeSpan))!; // Do not rename (binary serialization)
+ _daylightTransitionStart = (TransitionTime)info.GetValue("DaylightTransitionStart", typeof(TransitionTime))!; // Do not rename (binary serialization)
+ _daylightTransitionEnd = (TransitionTime)info.GetValue("DaylightTransitionEnd", typeof(TransitionTime))!; // Do not rename (binary serialization)
object? o = info.GetValueNoThrow("BaseUtcOffsetDelta", typeof(TimeSpan)); // Do not rename (binary serialization)
if (o != null)
throw new ArgumentNullException(nameof(info));
}
- _timeOfDay = (DateTime)info.GetValue("TimeOfDay", typeof(DateTime)); // Do not rename (binary serialization)
- _month = (byte)info.GetValue("Month", typeof(byte)); // Do not rename (binary serialization)
- _week = (byte)info.GetValue("Week", typeof(byte)); // Do not rename (binary serialization)
- _day = (byte)info.GetValue("Day", typeof(byte)); // Do not rename (binary serialization)
- _dayOfWeek = (DayOfWeek)info.GetValue("DayOfWeek", typeof(DayOfWeek)); // Do not rename (binary serialization)
- _isFixedDateRule = (bool)info.GetValue("IsFixedDateRule", typeof(bool)); // Do not rename (binary serialization)
+ _timeOfDay = (DateTime)info.GetValue("TimeOfDay", typeof(DateTime))!; // Do not rename (binary serialization)
+ _month = (byte)info.GetValue("Month", typeof(byte))!; // Do not rename (binary serialization)
+ _week = (byte)info.GetValue("Week", typeof(byte))!; // Do not rename (binary serialization)
+ _day = (byte)info.GetValue("Day", typeof(byte))!; // Do not rename (binary serialization)
+ _dayOfWeek = (DayOfWeek)info.GetValue("DayOfWeek", typeof(DayOfWeek))!; // Do not rename (binary serialization)
+ _isFixedDateRule = (bool)info.GetValue("IsFixedDateRule", typeof(bool))!; // Do not rename (binary serialization)
}
}
}
// read LastEntry {(yearN, 1, 1) - MaxValue }\r
\r
// read the FirstEntry and LastEntry key values (ex: "1980", "2038")\r
- int first = (int)dynamicKey.GetValue(FirstEntryValue, -1);\r
- int last = (int)dynamicKey.GetValue(LastEntryValue, -1);\r
+ int first = (int)dynamicKey.GetValue(FirstEntryValue, -1)!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34976\r
+ int last = (int)dynamicKey.GetValue(LastEntryValue, -1)!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34976\r
\r
if (first == -1 || last == -1 || first > last)\r
{\r
_displayName = (string?)info.GetValue("DisplayName", typeof(string)); // Do not rename (binary serialization)\r
_standardDisplayName = (string?)info.GetValue("StandardName", typeof(string)); // Do not rename (binary serialization)\r
_daylightDisplayName = (string?)info.GetValue("DaylightName", typeof(string)); // Do not rename (binary serialization)\r
- _baseUtcOffset = (TimeSpan)info.GetValue("BaseUtcOffset", typeof(TimeSpan)); // Do not rename (binary serialization)\r
+ _baseUtcOffset = (TimeSpan)info.GetValue("BaseUtcOffset", typeof(TimeSpan))!; // Do not rename (binary serialization)\r
_adjustmentRules = (AdjustmentRule[]?)info.GetValue("AdjustmentRules", typeof(AdjustmentRule[])); // Do not rename (binary serialization)\r
- _supportsDaylightSavingTime = (bool)info.GetValue("SupportsDaylightSavingTime", typeof(bool)); // Do not rename (binary serialization)\r
+ _supportsDaylightSavingTime = (bool)info.GetValue("SupportsDaylightSavingTime", typeof(bool))!; // Do not rename (binary serialization)\r
}\r
\r
private AdjustmentRule? GetAdjustmentRuleForTime(DateTime dateTime, out int? ruleIndex)\r
m_pDocumentWriterSafeHandle = pDocumentWriterSafeHandle;
// The handle is actually a pointer to a native ISymUnmanagedDocumentWriter.
m_pDocWriter = (ISymUnmanagedDocumentWriter*)m_pDocumentWriterSafeHandle.DangerousGetHandle();
- m_vtable = (ISymUnmanagedDocumentWriterVTable)(Marshal.PtrToStructure(m_pDocWriter->m_unmanagedVTable, typeof(ISymUnmanagedDocumentWriterVTable)));
+ m_vtable = (ISymUnmanagedDocumentWriterVTable)(Marshal.PtrToStructure(m_pDocWriter->m_unmanagedVTable, typeof(ISymUnmanagedDocumentWriterVTable)))!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34976
}
//------------------------------------------------------------------------------
internal void InternalSetUnderlyingWriter(IntPtr ppUnderlyingWriter)
{
m_pWriter = *((ISymUnmanagedWriter**)ppUnderlyingWriter);
- m_vtable = (ISymUnmanagedWriterVTable)(Marshal.PtrToStructure(m_pWriter->m_unmanagedVTable, typeof(ISymUnmanagedWriterVTable)));
+ m_vtable = (ISymUnmanagedWriterVTable)(Marshal.PtrToStructure(m_pWriter->m_unmanagedVTable, typeof(ISymUnmanagedWriterVTable)))!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34976
}
//------------------------------------------------------------------------------