// 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;
-using System.Runtime.InteropServices;
-
+#nullable enable
internal partial class Interop
{
internal partial class Advapi32
// 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;
-using System.Runtime.InteropServices;
-
+#nullable enable
internal partial class Interop
{
internal partial class Advapi32
// 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;
using System.Runtime.InteropServices;
// 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;
using System.Runtime.InteropServices;
// 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;
using System.Runtime.InteropServices;
// 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;
+#nullable enable
using System.Runtime.InteropServices;
internal partial class Interop
// 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;
+#nullable enable
using System.Runtime.InteropServices;
internal partial class Interop
// 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;
+#nullable enable
using System.Runtime.InteropServices;
internal partial class Interop
// 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;
+#nullable enable
using System.Runtime.InteropServices;
internal partial class Interop
// 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;
using System.Runtime.InteropServices;
#if ES_BUILD_STANDALONE
// 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.CompilerServices;
-using System.Runtime.InteropServices;
-
+#nullable enable
namespace System
{
public readonly partial struct DateTime
// 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.Runtime.CompilerServices;
using System.Runtime.InteropServices;
===========================================================*/
#define DEBUG // The behavior of this contract library should be consistent regardless of build type.
+#nullable enable
using System.Collections.Generic;
using System.Reflection;
private string _category;
private string _setting;
private bool _enabled;
- private string _value;
+ private string? _value;
public ContractOptionAttribute(string category, string setting, bool enabled)
{
get { return _enabled; }
}
- public string Value
+ public string? Value
{
get { return _value; }
}
[Pure]
[Conditional("DEBUG")]
[Conditional("CONTRACTS_FULL")]
- public static void Assume(bool condition, string userMessage)
+ public static void Assume(bool condition, string? userMessage)
{
if (!condition)
{
[Pure]
[Conditional("DEBUG")]
[Conditional("CONTRACTS_FULL")]
- public static void Assert(bool condition, string userMessage)
+ public static void Assert(bool condition, string? userMessage)
{
if (!condition)
ReportFailure(ContractFailureKind.Assert, userMessage, null, null);
/// </remarks>
[Pure]
[Conditional("CONTRACTS_FULL")]
- public static void Requires(bool condition, string userMessage)
+ public static void Requires(bool condition, string? userMessage)
{
AssertMustUseRewriter(ContractFailureKind.Precondition, "Requires");
}
/// Use this form when you want to throw a particular exception.
/// </remarks>
[Pure]
- public static void Requires<TException>(bool condition, string userMessage) where TException : Exception
+ public static void Requires<TException>(bool condition, string? userMessage) where TException : Exception
{
AssertMustUseRewriter(ContractFailureKind.Precondition, "Requires<TException>");
}
/// </remarks>
[Pure]
[Conditional("CONTRACTS_FULL")]
- public static void Ensures(bool condition, string userMessage)
+ public static void Ensures(bool condition, string? userMessage)
{
AssertMustUseRewriter(ContractFailureKind.Postcondition, "Ensures");
}
/// </remarks>
[Pure]
[Conditional("CONTRACTS_FULL")]
- public static void EnsuresOnThrow<TException>(bool condition, string userMessage) where TException : Exception
+ public static void EnsuresOnThrow<TException>(bool condition, string? userMessage) where TException : Exception
{
AssertMustUseRewriter(ContractFailureKind.PostconditionOnException, "EnsuresOnThrow");
}
/// This method can only be used within the argument to the <seealso cref="Ensures(bool)"/> contract.
/// </remarks>
[Pure]
- public static T Result<T>() { return default; }
+ public static T Result<T>() { return default!; }
/// <summary>
/// Represents the final (output) value of an out parameter when returning from a method.
/// This method can only be used within the argument to the <seealso cref="Ensures(bool)"/> contract.
/// </remarks>
[Pure]
- public static T ValueAtReturn<T>(out T value) { value = default; return value; }
+ public static T ValueAtReturn<T>(out T value) { value = default!; return value; }
/// <summary>
/// Represents the value of <paramref name="value"/> as it was at the start of the method or property.
/// This method can only be used within the argument to the <seealso cref="Ensures(bool)"/> contract.
/// </remarks>
[Pure]
- public static T OldValue<T>(T value) { return default; }
+ public static T OldValue<T>(T value) { return default!; }
#endregion Old, Result, and Out Parameters
/// </remarks>
[Pure]
[Conditional("CONTRACTS_FULL")]
- public static void Invariant(bool condition, string userMessage)
+ public static void Invariant(bool condition, string? userMessage)
{
AssertMustUseRewriter(ContractFailureKind.Invariant, "Invariant");
}
// find the first non-mscorlib assembly.
Assembly thisAssembly = typeof(Contract).Assembly; // In case we refactor mscorlib, use Contract class instead of Object.
StackTrace stack = new StackTrace();
- Assembly probablyNotRewritten = null;
+ Assembly? probablyNotRewritten = null;
for (int i = 0; i < stack.FrameCount; i++)
{
- Assembly caller = stack.GetFrame(i).GetMethod()?.DeclaringType.Assembly;
+ Assembly? caller = stack.GetFrame(i)!.GetMethod()?.DeclaringType.Assembly;
if (caller != null && caller != thisAssembly)
{
probablyNotRewritten = caller;
if (probablyNotRewritten == null)
probablyNotRewritten = thisAssembly;
- string simpleName = probablyNotRewritten.GetName().Name;
+ string? simpleName = probablyNotRewritten.GetName().Name;
System.Runtime.CompilerServices.ContractHelper.TriggerFailure(kind, SR.Format(SR.MustUseCCRewrite, contractKind, simpleName), null, null, null);
}
/// System.Runtime.CompilerServices.ContractHelper.TriggerFailure.
/// </summary>
[System.Diagnostics.DebuggerNonUserCode]
- private static void ReportFailure(ContractFailureKind failureKind, string userMessage, string conditionText, Exception innerException)
+ private static void ReportFailure(ContractFailureKind failureKind, string? userMessage, string? conditionText, Exception? innerException)
{
if (failureKind < ContractFailureKind.Precondition || failureKind > ContractFailureKind.Assume)
throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, failureKind), nameof(failureKind));
// 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
namespace System
{
public readonly struct GCMemoryInfo
// 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.CompilerServices;
-
+#nullable enable
#if BIT64
using nuint = System.UInt64;
#else
{
public struct ArrayWithOffset
{
- private object m_array;
+ private object? m_array;
private int m_offset;
private int m_count;
// From MAX_SIZE_FOR_INTEROP in mlinfo.h
private const int MaxSizeForInterop = 0x7ffffff0;
- public ArrayWithOffset(object array, int offset)
+ public ArrayWithOffset(object? array, int offset)
{
int totalSize = 0;
if (array != null)
m_count = totalSize - offset;
}
- public object GetArray() => m_array;
+ public object? GetArray() => m_array;
public int GetOffset() => m_offset;
public override int GetHashCode() => m_count + m_offset;
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
return obj is ArrayWithOffset && Equals((ArrayWithOffset)obj);
}
// 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
namespace System.Runtime.InteropServices
{
// Wrapper that is converted to a variant with VT_BSTR.
// 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.Runtime.InteropServices.ComTypes;
namespace System.Runtime.InteropServices
**
===========================================================*/
+#nullable enable
using System.Runtime.ConstrainedExecution;
/*
// 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
namespace System.Runtime.InteropServices
{
// Wrapper that is converted to a variant with VT_CURRENCY.
public sealed class CurrencyWrapper
{
- public CurrencyWrapper(Decimal obj)
+ public CurrencyWrapper(decimal obj)
{
WrappedObject = obj;
}
- public CurrencyWrapper(Object obj)
+ public CurrencyWrapper(object obj)
{
- if (!(obj is Decimal))
+ if (!(obj is decimal))
throw new ArgumentException(SR.Arg_MustBeDecimal, nameof(obj));
- WrappedObject = (Decimal)obj;
+ WrappedObject = (decimal)obj;
}
- public Decimal WrappedObject { get; }
+ public decimal WrappedObject { get; }
}
}
// 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
namespace System.Runtime.InteropServices
{
// Wrapper that is converted to a variant with VT_DISPATCH
public sealed class DispatchWrapper
{
- public DispatchWrapper(Object obj)
+ public DispatchWrapper(object? obj)
{
if (obj != null)
{
}
}
- public object WrappedObject { get; }
+ public object? WrappedObject { get; }
}
}
// 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
namespace System.Runtime.InteropServices
{
// Wrapper that is converted to a variant with VT_ERROR.
// 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
namespace System.Runtime.InteropServices
{
public readonly struct HandleRef
{
// ! Do not add or rearrange fields as the EE depends on this layout.
//------------------------------------------------------------------
- private readonly object _wrapper;
+ private readonly object? _wrapper;
private readonly IntPtr _handle;
//------------------------------------------------------------------
- public HandleRef(object wrapper, IntPtr handle)
+ public HandleRef(object? wrapper, IntPtr handle)
{
_wrapper = wrapper;
_handle = handle;
}
- public object Wrapper
+ public object? Wrapper
{
get
{
// 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
namespace System.Runtime.InteropServices
{
// This the base interface that custom adapters can chose to implement when they want to expose the underlying object.
// 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
namespace System.Runtime.InteropServices
{
public interface ICustomFactory
// 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
namespace System.Runtime.InteropServices
{
// This the interface that be implemented by class that want to customize the behavior of QueryInterface.
// static variable (perhaps using Interlocked.CompareExchange). Of course,
// assignments in a static class constructor are under a lock implicitly.
-using System;
-using System.Diagnostics;
+#nullable enable
using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
using Microsoft.Win32.SafeHandles;
// 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
namespace System.Runtime.InteropServices
{
// Wrapper that is converted to a variant with VT_UNKNOWN.
public sealed class UnknownWrapper
{
- public UnknownWrapper(Object obj)
+ public UnknownWrapper(object? obj)
{
WrappedObject = obj;
}
- public Object WrappedObject { get; }
+ public object? WrappedObject { get; }
}
}
// 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
namespace System.Runtime.InteropServices
{
// Wrapper that is converted to a variant with VT_BYREF | VT_VARIANT.
public sealed class VariantWrapper
{
- public VariantWrapper(Object obj)
+ public VariantWrapper(object? obj)
{
WrappedObject = obj;
}
- public Object WrappedObject { get; }
+ public object? WrappedObject { get; }
}
}
// 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 Windows.Foundation.Metadata;
using Windows.Storage;
using System.IO;
switch (folder)
{
case SpecialFolder.ApplicationData:
- return ApplicationData.Current.RoamingFolder?.Path;
+ return ApplicationData.Current.RoamingFolder?.Path ?? string.Empty;
case SpecialFolder.LocalApplicationData:
- return ApplicationData.Current.LocalFolder?.Path;
+ return ApplicationData.Current.LocalFolder?.Path ?? string.Empty;
case SpecialFolder.System:
return SystemDirectory;
case SpecialFolder.Windows:
- return Path.GetDirectoryName(SystemDirectory);
+ return Path.GetDirectoryName(SystemDirectory)!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
default:
return string.Empty;
}
// 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.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
namespace System
{