//
//===========================================================================*/
-using System;
-
namespace System
{
// Note: FACILITY_URT is defined as 0x13 (0x8013xxxx). Within that
// 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
using System.Resources;
using System.Runtime.CompilerServices;
[MethodImpl(MethodImplOptions.NoInlining)]
private static bool UsingResourceKeys() => false;
- internal static string GetResourceString(string resourceKey, string defaultString = null)
+ internal static string GetResourceString(string resourceKey, string? defaultString = null)
{
if (UsingResourceKeys())
{
return defaultString ?? resourceKey;
}
- string resourceString = null;
+ string? resourceString = null;
try
{
resourceString = ResourceManager.GetString(resourceKey);
return defaultString;
}
- return resourceString;
+ return resourceString!; // only null if missing resources
}
- internal static string Format(string resourceFormat, object p1)
+ internal static string Format(string resourceFormat, object? p1)
{
if (UsingResourceKeys())
{
return string.Format(resourceFormat, p1);
}
- internal static string Format(string resourceFormat, object p1, object p2)
+ internal static string Format(string resourceFormat, object? p1, object? p2)
{
if (UsingResourceKeys())
{
return string.Format(resourceFormat, p1, p2);
}
- internal static string Format(string resourceFormat, object p1, object p2, object p3)
+ internal static string Format(string resourceFormat, object? p1, object? p2, object? p3)
{
if (UsingResourceKeys())
{
return string.Format(resourceFormat, p1, p2, p3);
}
- internal static string Format(string resourceFormat, params object[] args)
+ internal static string Format(string resourceFormat, params object?[]? args)
{
if (args != null)
{
return resourceFormat;
}
- internal static string Format(IFormatProvider provider, string resourceFormat, object p1)
+ internal static string Format(IFormatProvider? provider, string resourceFormat, object? p1)
{
if (UsingResourceKeys())
{
return string.Format(provider, resourceFormat, p1);
}
- internal static string Format(IFormatProvider provider, string resourceFormat, object p1, object p2)
+ internal static string Format(IFormatProvider? provider, string resourceFormat, object? p1, object? p2)
{
if (UsingResourceKeys())
{
return string.Format(provider, resourceFormat, p1, p2);
}
- internal static string Format(IFormatProvider provider, string resourceFormat, object p1, object p2, object p3)
+ internal static string Format(IFormatProvider? provider, string resourceFormat, object? p1, object? p2, object? p3)
{
if (UsingResourceKeys())
{
return string.Format(provider, resourceFormat, p1, p2, p3);
}
- internal static string Format(IFormatProvider provider, string resourceFormat, params object[] args)
+ internal static string Format(IFormatProvider? provider, string resourceFormat, params object?[]? args)
{
if (args != null)
{
<IncludeDllSafeSearchPathAttribute>true</IncludeDllSafeSearchPathAttribute>
<GenFacadesIgnoreMissingTypes Condition="'$(TargetsAOT)'=='true' OR '$(TargetGroup)' == 'uap'">true</GenFacadesIgnoreMissingTypes>
<Configurations>netcoreapp-Unix-Debug;netcoreapp-Unix-Release;netcoreapp-Windows_NT-Debug;netcoreapp-Windows_NT-Release;uap-Windows_NT-Debug;uap-Windows_NT-Release;uapaot-Windows_NT-Debug;uapaot-Windows_NT-Release</Configurations>
+ <NullableContextOptions>enable</NullableContextOptions>
</PropertyGroup>
<ItemGroup>
<Compile Include="System\AppDomainUnloadedException.cs" />
HResult = COR_E_APPDOMAINUNLOADED;
}
- public AppDomainUnloadedException(string message)
+ public AppDomainUnloadedException(string? message)
: base(message)
{
HResult = COR_E_APPDOMAINUNLOADED;
}
- public AppDomainUnloadedException(string message, Exception innerException)
+ public AppDomainUnloadedException(string? message, Exception? innerException)
: base(message, innerException)
{
HResult = COR_E_APPDOMAINUNLOADED;
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.IO;
-using System.Reflection;
-using System.Runtime.ExceptionServices;
using System.Text;
namespace System
{
private readonly byte[] _publicKeyToken;
- public ApplicationId(byte[] publicKeyToken, string name, Version version, string processorArchitecture, string culture)
+ public ApplicationId(byte[] publicKeyToken, string name, Version version, string? processorArchitecture, string? culture)
{
if (name == null) throw new ArgumentNullException(nameof(name));
if (name.Length == 0) throw new ArgumentException(SR.Argument_EmptyApplicationName);
Culture = culture;
}
- public string Culture { get; }
+ public string? Culture { get; }
public string Name { get; }
- public string ProcessorArchitecture { get; }
+ public string? ProcessorArchitecture { get; }
public Version Version { get; }
public ApplicationId Copy() => new ApplicationId(_publicKeyToken, Name, Version, ProcessorArchitecture, Culture);
- public override string ToString ()
+#pragma warning disable CS8609 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/23268
+ public override string ToString()
+#pragma warning restore CS8609
{
Span<char> charSpan = stackalloc char[128];
var sb = new ValueStringBuilder(charSpan);
(char)((num < 10) ? (num + '0') : (num + ('A' - 10)));
}
- public override bool Equals (object o)
+ public override bool Equals(object? o)
{
- ApplicationId other = (o as ApplicationId);
+ ApplicationId? other = o as ApplicationId;
if (other == null)
return false;
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Diagnostics;
using System.IO;
using System.Text;
using System.Globalization;
public override Encoding Encoding => _writer.Encoding;
- public override string NewLine
+ public override string? NewLine // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2384
{
get { return _writer.NewLine; }
set { _writer.NewLine = value; }
}
}
- public override void Write(string s)
+ public override void Write(string? s)
{
OutputTabs();
_writer.Write(s);
_writer.Write(value);
}
- public override void Write(char[] buffer)
+ public override void Write(char[]? buffer)
{
OutputTabs();
_writer.Write(buffer);
_writer.Write(value);
}
- public override void Write(object value)
+ public override void Write(object? value)
{
OutputTabs();
_writer.Write(value);
}
- public override void Write(string format, object arg0)
+ public override void Write(string format, object? arg0)
{
OutputTabs();
_writer.Write(format, arg0);
}
- public override void Write(string format, object arg0, object arg1)
+ public override void Write(string format, object? arg0, object? arg1)
{
OutputTabs();
_writer.Write(format, arg0, arg1);
}
- public override void Write(string format, params object[] arg)
+ public override void Write(string format, params object?[] arg)
{
OutputTabs();
_writer.Write(format, arg);
}
- public void WriteLineNoTabs(string s)
+ public void WriteLineNoTabs(string? s)
{
_writer.WriteLine(s);
}
- public override void WriteLine(string s)
+ public override void WriteLine(string? s)
{
OutputTabs();
_writer.WriteLine(s);
_tabsPending = true;
}
- public override void WriteLine(char[] buffer)
+ public override void WriteLine(char[]? buffer)
{
OutputTabs();
_writer.WriteLine(buffer);
_tabsPending = true;
}
- public override void WriteLine(object value)
+ public override void WriteLine(object? value)
{
OutputTabs();
_writer.WriteLine(value);
_tabsPending = true;
}
- public override void WriteLine(string format, object arg0)
+ public override void WriteLine(string format, object? arg0)
{
OutputTabs();
_writer.WriteLine(format, arg0);
_tabsPending = true;
}
- public override void WriteLine(string format, object arg0, object arg1)
+ public override void WriteLine(string format, object? arg0, object? arg1)
{
OutputTabs();
_writer.WriteLine(format, arg0, arg1);
_tabsPending = true;
}
- public override void WriteLine(string format, params object[] arg)
+ public override void WriteLine(string format, params object?[] arg)
{
OutputTabs();
_writer.WriteLine(format, arg);
namespace System
{
- public abstract class ContextBoundObject : System.MarshalByRefObject
+ public abstract class ContextBoundObject : MarshalByRefObject
{
protected ContextBoundObject() { }
}
{
}
- public ContextMarshalException(string message) : this(message, null)
+ public ContextMarshalException(string? message) : this(message, null)
{
}
- public ContextMarshalException(string message, Exception inner) : base(message, inner)
+ public ContextMarshalException(string? message, Exception? inner) : base(message, inner)
{
HResult = HResults.COR_E_CONTEXTMARSHAL;
}
}
[AttributeUsage(AttributeTargets.Field, Inherited = false)]
- public partial class ContextStaticAttribute : System.Attribute
+ public partial class ContextStaticAttribute : Attribute
{
public ContextStaticAttribute() { }
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
private const int MaxShadowBufferSize = 81920; // Make sure not to get to the Large Object Heap.
private const int DefaultBufferSize = 4096;
- private Stream _stream; // Underlying stream. Close sets _stream to null.
- private byte[] _buffer; // Shared read/write buffer. Alloc on first use.
+ private Stream? _stream; // Underlying stream. Close sets _stream to null.
+ private byte[]? _buffer; // Shared read/write buffer. Alloc on first use.
private readonly int _bufferSize; // Length of internal buffer (not counting the shadow buffer).
private int _readPos; // Read pointer within shared buffer.
private int _readLen; // Number of bytes read in buffer from _stream.
private int _writePos; // Write pointer within shared buffer.
- private Task<int> _lastSyncCompletedReadTask; // The last successful Task returned from ReadAsync
+ private Task<int>? _lastSyncCompletedReadTask; // The last successful Task returned from ReadAsync
// (perf optimization for successive reads of the same size)
// Removing a private default constructor is a breaking change for the DataDebugSerializer.
// Because this ctor was here previously we need to keep it around.
- private SemaphoreSlim _asyncActiveSemaphore;
+ private SemaphoreSlim? _asyncActiveSemaphore;
internal SemaphoreSlim LazyEnsureAsyncActiveSemaphoreInitialized()
{
// Lazily-initialize _asyncActiveSemaphore. As we're never accessing the SemaphoreSlim's
// WaitHandle, we don't need to worry about Disposing it.
- return LazyInitializer.EnsureInitialized(ref _asyncActiveSemaphore, () => new SemaphoreSlim(1, 1));
+ return LazyInitializer.EnsureInitialized(ref _asyncActiveSemaphore, () => new SemaphoreSlim(1, 1))!;
}
public BufferedStream(Stream stream)
_buffer = new byte[_bufferSize];
}
- public Stream UnderlyingStream
+ public Stream? UnderlyingStream
{
get
{
if (_writePos > 0)
FlushWrite();
- return _stream.Length;
+ return _stream!.Length;
}
}
EnsureCanSeek();
Debug.Assert(!(_writePos > 0 && _readPos != _readLen), "Read and Write buffers cannot both have data in them at the same time.");
- return _stream.Position + (_readPos - _readLen + _writePos);
+ return _stream!.Position + (_readPos - _readLen + _writePos);
}
set
{
_readPos = 0;
_readLen = 0;
- _stream.Seek(value, SeekOrigin.Begin);
+ _stream!.Seek(value, SeekOrigin.Begin);
}
}
// If the underlying stream is not seekable AND we have something in the read buffer, then FlushRead would throw.
// We can either throw away the buffer resulting in data loss (!) or ignore the Flush.
// (We cannot throw because it would be a breaking change.) We opt into ignoring the Flush in that situation.
- if (_stream.CanSeek)
+ if (_stream!.CanSeek)
{
FlushRead();
}
}
// We had no data in the buffer, but we still need to tell the underlying stream to flush.
- if (_stream.CanWrite)
+ if (_stream!.CanWrite)
_stream.Flush();
_writePos = _readPos = _readLen = 0;
// All write functions should call this function to ensure that the buffered data is not lost.
private void FlushRead()
{
+ Debug.Assert(_stream != null);
Debug.Assert(_writePos == 0, "BufferedStream: Write buffer must be empty in FlushRead!");
if (_readPos - _readLen != 0)
/// </summary>
private void ClearReadBufferBeforeWrite()
{
+ Debug.Assert(_stream != null);
Debug.Assert(_readPos <= _readLen, "_readPos <= _readLen [" + _readPos + " <= " + _readLen + "]");
// No read data in the buffer:
private void FlushWrite()
{
+ Debug.Assert(_stream != null);
Debug.Assert(_readPos == 0 && _readLen == 0,
"BufferedStream: Read buffer must be empty in FlushWrite!");
Debug.Assert(_buffer != null && _bufferSize >= _writePos,
private async Task FlushWriteAsync(CancellationToken cancellationToken)
{
-
+ Debug.Assert(_stream != null);
Debug.Assert(_readPos == 0 && _readLen == 0,
"BufferedStream: Read buffer must be empty in FlushWrite!");
Debug.Assert(_buffer != null && _bufferSize >= _writePos,
if (readbytes > count)
readbytes = count;
- Buffer.BlockCopy(_buffer, _readPos, array, offset, readbytes);
+ Buffer.BlockCopy(_buffer!, _readPos, array, offset, readbytes);
_readPos += readbytes;
return readbytes;
return readbytes;
}
- private int ReadFromBuffer(byte[] array, int offset, int count, out Exception error)
+ private int ReadFromBuffer(byte[] array, int offset, int count, out Exception? error)
{
try
{
EnsureNotClosed();
EnsureCanRead();
+ Debug.Assert(_stream != null);
int bytesFromBuffer = ReadFromBuffer(array, offset, count);
// Ok. We can fill the buffer:
EnsureBufferAllocated();
- _readLen = _stream.Read(_buffer, 0, _bufferSize);
+ _readLen = _stream.Read(_buffer!, 0, _bufferSize);
bytesFromBuffer = ReadFromBuffer(array, offset, count);
{
EnsureNotClosed();
EnsureCanRead();
+ Debug.Assert(_stream != null);
// Try to read from the buffer.
int bytesFromBuffer = ReadFromBuffer(destination);
{
// Otherwise, fill the buffer, then read from that.
EnsureBufferAllocated();
- _readLen = _stream.Read(_buffer, 0, _bufferSize);
+ _readLen = _stream.Read(_buffer!, 0, _bufferSize);
return ReadFromBuffer(destination) + bytesFromBuffer;
}
}
private Task<int> LastSyncCompletedReadTask(int val)
{
- Task<int> t = _lastSyncCompletedReadTask;
+ Task<int>? t = _lastSyncCompletedReadTask;
Debug.Assert(t == null || t.IsCompletedSuccessfully);
if (t != null && t.Result == val)
bool completeSynchronously = true;
try
{
- Exception error;
+ Exception? error;
bytesFromBuffer = ReadFromBuffer(buffer, offset, count, out error);
// If we satisfied enough data from the buffer, we can complete synchronously.
}
}
- public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) =>
+ public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object? state) =>
TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state);
public override int EndRead(IAsyncResult asyncResult) =>
public override int ReadByte()
{
return _readPos != _readLen ?
- _buffer[_readPos++] :
+ _buffer![_readPos++] :
ReadByteSlow();
}
// the stream is closed, its read buffer is flushed, so we'll take this slow path.
EnsureNotClosed();
EnsureCanRead();
+ Debug.Assert(_stream != null);
if (_writePos > 0)
FlushWrite();
EnsureBufferAllocated();
- _readLen = _stream.Read(_buffer, 0, _bufferSize);
+ _readLen = _stream.Read(_buffer!, 0, _bufferSize);
_readPos = 0;
if (_readLen == 0)
return -1;
- return _buffer[_readPos++];
+ return _buffer![_readPos++];
}
private void WriteToBuffer(byte[] array, ref int offset, ref int count)
return;
EnsureBufferAllocated();
- Buffer.BlockCopy(array, offset, _buffer, _writePos, bytesToWrite);
+ Buffer.BlockCopy(array, offset, _buffer!, _writePos, bytesToWrite);
_writePos += bytesToWrite;
count -= bytesToWrite;
return bytesToWrite;
}
- private void WriteToBuffer(byte[] array, ref int offset, ref int count, out Exception error)
+ private void WriteToBuffer(byte[] array, ref int offset, ref int count, out Exception? error)
{
try
{
EnsureNotClosed();
EnsureCanWrite();
+ Debug.Assert(_stream != null);
if (_writePos == 0)
ClearReadBufferBeforeWrite();
{
EnsureNotClosed();
EnsureCanWrite();
+ Debug.Assert(_stream != null);
if (_writePos == 0)
{
}
}
- public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) =>
+ public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object? state) =>
TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), callback, state);
public override void EndWrite(IAsyncResult asyncResult) =>
if (_writePos >= _bufferSize - 1)
FlushWrite();
- _buffer[_writePos++] = value;
+ _buffer![_writePos++] = value;
Debug.Assert(_writePos < _bufferSize);
}
{
EnsureNotClosed();
EnsureCanSeek();
+ Debug.Assert(_stream != null);
// If we have bytes in the write buffer, flush them out, seek and be done.
if (_writePos > 0)
EnsureNotClosed();
EnsureCanSeek();
EnsureCanWrite();
+ Debug.Assert(_stream != null);
Flush();
_stream.SetLength(value);
public override void CopyTo(Stream destination, int bufferSize)
{
StreamHelpers.ValidateCopyToArgs(this, destination, bufferSize);
+ Debug.Assert(_stream != null);
int readBytes = _readLen - _readPos;
Debug.Assert(readBytes >= 0, $"Expected a non-negative number of bytes in buffer, got {readBytes}");
{
// If there's any read data in the buffer, write it all to the destination stream.
Debug.Assert(_writePos == 0, "Write buffer must be empty if there's data in the read buffer");
- destination.Write(_buffer, _readPos, readBytes);
+ destination.Write(_buffer!, _readPos, readBytes);
_readPos = _readLen = 0;
}
else if (_writePos > 0)
private async Task CopyToAsyncCore(Stream destination, int bufferSize, CancellationToken cancellationToken)
{
+ Debug.Assert(_stream != null);
+
// Synchronize async operations as does Read/WriteAsync.
await LazyEnsureAsyncActiveSemaphoreInitialized().WaitAsync().ConfigureAwait(false);
try
// Our buffer is now clear. Copy data directly from the source stream to the destination stream.
await _stream.CopyToAsync(destination, bufferSize, cancellationToken).ConfigureAwait(false);
}
- finally { _asyncActiveSemaphore.Release(); }
+ finally { _asyncActiveSemaphore!.Release(); }
}
} // class BufferedStream
} // namespace
{
}
- public InvalidDataException(string message)
+ public InvalidDataException(string? message)
: base(message)
{
}
- public InvalidDataException(string message, Exception innerException)
+ public InvalidDataException(string? message, Exception? innerException)
: base(message, innerException)
{
}
// This class implements a text reader that reads from a string.
public class StringReader : TextReader
{
- private string _s;
+ private string? _s;
private int _pos;
private int _length;
public StringReader(string s)
{
- if (s == null)
- {
- throw new ArgumentNullException(nameof(s));
- }
-
- _s = s;
+ _s = s ?? throw new ArgumentNullException(nameof(s));
_length = s.Length;
}
// contain the terminating carriage return and/or line feed. The returned
// value is null if the end of the underlying string has been reached.
//
- public override string ReadLine()
+ public override string? ReadLine()
{
if (_s == null)
{
}
#region Task based Async APIs
- public override Task<string> ReadLineAsync()
+ public override Task<string?> ReadLineAsync()
{
return Task.FromResult(ReadLine());
}
// the resulting sequence of characters to be presented as a string.
public class StringWriter : TextWriter
{
- private static volatile UnicodeEncoding s_encoding = null;
+ private static volatile UnicodeEncoding? s_encoding = null;
private StringBuilder _sb;
private bool _isOpen;
{
}
- public StringWriter(IFormatProvider formatProvider)
+ public StringWriter(IFormatProvider? formatProvider)
: this(new StringBuilder(), formatProvider)
{
}
{
}
- public StringWriter(StringBuilder sb, IFormatProvider formatProvider) : base(formatProvider)
+ public StringWriter(StringBuilder sb, IFormatProvider? formatProvider) : base(formatProvider)
{
if (sb == null)
{
// Writes a string to the underlying string buffer. If the given string is
// null, nothing is written.
//
- public override void Write(string value)
+ public override void Write(string? value)
{
if (!_isOpen)
{
}
}
- public override void Write(StringBuilder value)
+ public override void Write(StringBuilder? value)
{
if (GetType() != typeof(StringWriter))
{
WriteLine();
}
- public override void WriteLine(StringBuilder value)
+ public override void WriteLine(StringBuilder? value)
{
if (GetType() != typeof(StringWriter))
{
return Task.CompletedTask;
}
- public override Task WriteAsync(string value)
+ public override Task WriteAsync(string? value)
{
Write(value);
return Task.CompletedTask;
return Task.CompletedTask;
}
- public override Task WriteAsync(StringBuilder value, CancellationToken cancellationToken = default)
+ public override Task WriteAsync(StringBuilder? value, CancellationToken cancellationToken = default)
{
if (GetType() != typeof(StringWriter))
{
return Task.CompletedTask;
}
- public override Task WriteLineAsync(string value)
+ public override Task WriteLineAsync(string? value)
{
WriteLine(value);
return Task.CompletedTask;
}
- public override Task WriteLineAsync(StringBuilder value, CancellationToken cancellationToken = default)
+ public override Task WriteLineAsync(StringBuilder? value, CancellationToken cancellationToken = default)
{
if (GetType() != typeof(StringWriter))
{
{
return Task.CompletedTask;
}
-
+
#endregion
- // Returns a string containing the characters written to this TextWriter
- // so far.
- //
+ // Returns a string containing the characters written to this TextWriter so far.
+#pragma warning disable CS8609 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/23268
public override string ToString()
+#pragma warning restore CS8609
{
return _sb.ToString();
}
// Don't entity encode high chars (160 to 256)
#define ENTITY_ENCODE_HIGH_ASCII_CHARS
-using System;
-using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
#region HtmlEncode / HtmlDecode methods
- public static string HtmlEncode(string value)
+ public static string? HtmlEncode(string? value) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
{
if (string.IsNullOrEmpty(value))
{
return sb.ToString();
}
- public static void HtmlEncode(string value, TextWriter output)
+ public static void HtmlEncode(string? value, TextWriter output)
{
if (output == null)
{
}
}
- public static string HtmlDecode(string value)
+ public static string? HtmlDecode(string? value) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
{
if (string.IsNullOrEmpty(value))
{
return sb.ToString();
}
- public static void HtmlDecode(string value, TextWriter output)
+ public static void HtmlDecode(string? value, TextWriter output)
{
if (output == null)
{
#region UrlEncode public methods
[SuppressMessage("Microsoft.Design", "CA1055:UriReturnValuesShouldNotBeStrings", Justification = "Already shipped public API; code moved here as part of API consolidation")]
- public static string UrlEncode(string value)
+ public static string? UrlEncode(string? value) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
{
if (string.IsNullOrEmpty(value))
return value;
return Encoding.UTF8.GetString(newBytes);
}
- public static byte[] UrlEncodeToBytes(byte[] value, int offset, int count)
+ public static byte[]? UrlEncodeToBytes(byte[]? value, int offset, int count) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
{
if (!ValidateUrlEncodingParameters(value, offset, count))
{
// count them first
for (int i = 0; i < count; i++)
{
- char ch = (char)value[offset + i];
+ char ch = (char)value![offset + i];
if (ch == ' ')
foundSpaces = true;
if (!foundSpaces && unsafeCount == 0)
{
var subarray = new byte[count];
- Buffer.BlockCopy(value, offset, subarray, 0, count);
+ Buffer.BlockCopy(value!, offset, subarray, 0, count);
return subarray;
}
// expand not 'safe' characters into %XX, spaces to +s
byte[] expandedBytes = new byte[count + unsafeCount * 2];
- GetEncodedBytes(value, offset, count, expandedBytes);
+ GetEncodedBytes(value!, offset, count, expandedBytes);
return expandedBytes;
}
#region UrlDecode implementation
- private static string UrlDecodeInternal(string value, Encoding encoding)
+ private static string? UrlDecodeInternal(string? value, Encoding encoding) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
{
if (string.IsNullOrEmpty(value))
{
return helper.GetString();
}
- private static byte[] UrlDecodeInternal(byte[] bytes, int offset, int count)
+ private static byte[]? UrlDecodeInternal(byte[]? bytes, int offset, int count) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
{
if (!ValidateUrlEncodingParameters(bytes, offset, count))
{
for (int i = 0; i < count; i++)
{
int pos = offset + i;
- byte b = bytes[pos];
+ byte b = bytes![pos];
if (b == '+')
{
if (decodedBytesCount < decodedBytes.Length)
{
- Array.Resize(ref decodedBytes, decodedBytesCount);
+ Array.Resize(ref decodedBytes!, decodedBytesCount); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
}
return decodedBytes;
[SuppressMessage("Microsoft.Design", "CA1055:UriReturnValuesShouldNotBeStrings", Justification = "Already shipped public API; code moved here as part of API consolidation")]
- public static string UrlDecode(string encodedValue)
+ public static string? UrlDecode(string? encodedValue) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
{
return UrlDecodeInternal(encodedValue, Encoding.UTF8);
}
- public static byte[] UrlDecodeToBytes(byte[] encodedValue, int offset, int count)
+ public static byte[]? UrlDecodeToBytes(byte[]? encodedValue, int offset, int count) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
{
return UrlDecodeInternal(encodedValue, offset, count);
}
}
}
- private static bool ValidateUrlEncodingParameters(byte[] bytes, int offset, int count)
+ private static bool ValidateUrlEncodingParameters(byte[]? bytes, int offset, int count)
{
if (bytes == null && count == 0)
return false;
// Accumulate characters in a special array
private int _numChars;
- private char[] _charBuffer;
+ private char[]? _charBuffer;
// Accumulate bytes for decoding into characters in a special array
private int _numBytes;
- private byte[] _byteBuffer;
+ private byte[]? _byteBuffer;
// Encoding to convert chars to bytes
private Encoding _encoding;
if (_charBuffer == null)
_charBuffer = new char[_bufferSize];
- _numChars += _encoding.GetChars(_byteBuffer, 0, _numBytes, _charBuffer, _numChars);
+ _numChars += _encoding.GetChars(_byteBuffer!, 0, _numBytes, _charBuffer, _numChars);
_numBytes = 0;
}
FlushBytes();
Debug.Assert(_numChars > 0);
- return new string(_charBuffer, 0, _numChars);
+ return new string(_charBuffer!, 0, _numChars);
}
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-namespace System.Reflection {
- using System;
- using System.Runtime.Versioning;
-
+namespace System.Reflection
+{
public class AssemblyNameProxy : MarshalByRefObject
{
public AssemblyName GetAssemblyName(string assemblyFile)
public SwitchExpressionException()
: base(SR.Arg_SwitchExpressionException) { }
- public SwitchExpressionException(Exception innerException) :
+ public SwitchExpressionException(Exception? innerException) :
base(SR.Arg_SwitchExpressionException, innerException) { }
- public SwitchExpressionException(object unmatchedValue) : this()
+ public SwitchExpressionException(object? unmatchedValue) : this()
{
UnmatchedValue = unmatchedValue;
}
UnmatchedValue = info.GetValue(nameof(UnmatchedValue), typeof(object));
}
- public SwitchExpressionException(string message) : base(message) { }
+ public SwitchExpressionException(string? message) : base(message) { }
- public SwitchExpressionException(string message, Exception innerException)
+ public SwitchExpressionException(string? message, Exception? innerException)
: base(message, innerException) { }
- public object UnmatchedValue { get; }
+ public object? UnmatchedValue { get; }
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
{
return base.Message;
}
+
string valueMessage = SR.Format(SR.SwitchExpressionException_UnmatchedValue, UnmatchedValue);
return base.Message + Environment.NewLine + valueMessage;
}
namespace System.Runtime.Versioning
{
- public sealed class FrameworkName : IEquatable<FrameworkName>
+ public sealed class FrameworkName : IEquatable<FrameworkName?>
{
private readonly string _identifier;
- private readonly Version _version;
+ private readonly Version _version = null!;
private readonly string _profile;
- private string _fullName;
+ private string? _fullName;
private const char ComponentSeparator = ',';
private const char KeyValueSeparator = '=';
Profile;
}
}
+
Debug.Assert(_fullName != null);
return _fullName;
}
}
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
return Equals(obj as FrameworkName);
}
- public bool Equals(FrameworkName other)
+ public bool Equals(FrameworkName? other)
{
- if (object.ReferenceEquals(other, null))
+ if (other is null)
{
return false;
}
return Identifier.GetHashCode() ^ Version.GetHashCode() ^ Profile.GetHashCode();
}
+#pragma warning disable CS8609 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/23268
public override string ToString()
+#pragma warning restore CS8609
{
return FullName;
}
{
}
- public FrameworkName(string identifier, Version version, string profile)
+ public FrameworkName(string identifier, Version version, string? profile)
{
if (identifier == null)
{
}
}
- public static bool operator ==(FrameworkName left, FrameworkName right)
+ public static bool operator ==(FrameworkName? left, FrameworkName? right)
{
- if (object.ReferenceEquals(left, null))
+ if (left is null)
{
- return object.ReferenceEquals(right, null);
+ return right is null;
}
+
return left.Equals(right);
}
- public static bool operator !=(FrameworkName left, FrameworkName right)
+ public static bool operator !=(FrameworkName? left, FrameworkName? right)
{
return !(left == right);
}
private const ResourceScope ResTypeMask = ResourceScope.Machine | ResourceScope.Process | ResourceScope.AppDomain | ResourceScope.Library;
private const ResourceScope VisibilityMask = ResourceScope.Private | ResourceScope.Assembly;
- public static string MakeVersionSafeName(string name, ResourceScope from, ResourceScope to)
+ public static string MakeVersionSafeName(string? name, ResourceScope from, ResourceScope to)
{
- return MakeVersionSafeName(name, from, to, null);
+ return MakeVersionSafeName(name, from, to, type: null);
}
- public static string MakeVersionSafeName(string name, ResourceScope from, ResourceScope to, Type type)
+ public static string MakeVersionSafeName(string? name, ResourceScope from, ResourceScope to, Type? type)
{
ResourceScope fromResType = from & ResTypeMask;
ResourceScope toResType = to & ResTypeMask;
if ((requires & SxSRequirements.TypeName) != 0)
{
safeName.Append(separator);
- safeName.Append(type.Name);
+ safeName.Append(type!.Name);
}
if ((requires & SxSRequirements.AssemblyName) != 0)
{
safeName.Append(separator);
- safeName.Append(type.Assembly.FullName);
+ safeName.Append(type!.Assembly.FullName);
}
return safeName.ToString();
}
protected SecurityAttribute(SecurityAction action) { }
public SecurityAction Action { get; set; }
public bool Unrestricted { get; set; }
- public abstract IPermission CreatePermission();
+ public abstract IPermission? CreatePermission();
}
}
public bool SerializationFormatter { get; set; }
public bool SkipVerification { get; set; }
public bool UnmanagedCode { get; set; }
- public override IPermission CreatePermission() { return default(IPermission); }
+ public override IPermission? CreatePermission() { return null; }
}
}