#nullable enable
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+using System.Runtime.Loader;
using System.Runtime.Serialization;
using StackCrawlMark = System.Threading.StackCrawlMark;
// Locate an assembly by its name. The name can be strong or
// weak. The assembly is loaded into the domain of the caller.
- internal static Assembly Load(AssemblyName assemblyRef, ref StackCrawlMark stackMark, AssemblyLoadContext assemblyLoadContext)
+ internal static Assembly Load(AssemblyName assemblyRef, ref StackCrawlMark stackMark, AssemblyLoadContext? assemblyLoadContext)
{
AssemblyName? modifiedAssemblyRef = null;
if (assemblyRef.CodeBase != null)
throw new ArgumentException(SR.Format_StringZeroLength);
_name = assemblyName;
- nInit(out RuntimeAssembly dummy, false);
+ nInit(out RuntimeAssembly? dummy, false);
}
internal AssemblyName(string? name,
RuntimeType? type = null;
object? keepAlive = null;
- AssemblyLoadContext assemblyLoadContextStack = AssemblyLoadContext.CurrentContextualReflectionContext;
+ AssemblyLoadContext? assemblyLoadContextStack = AssemblyLoadContext.CurrentContextualReflectionContext;
GetType(GetNativeHandle(),
name,
return CustomAttributeData.GetCustomAttributesInternal(this);
}
- internal static RuntimeAssembly InternalLoad(string assemblyString, ref StackCrawlMark stackMark, AssemblyLoadContext assemblyLoadContext = null)
+ internal static RuntimeAssembly InternalLoad(string assemblyString, ref StackCrawlMark stackMark, AssemblyLoadContext? assemblyLoadContext = null)
{
RuntimeAssembly? assembly;
AssemblyName an = CreateAssemblyName(assemblyString, out assembly);
return an;
}
- internal static RuntimeAssembly InternalLoadAssemblyName(AssemblyName assemblyRef, ref StackCrawlMark stackMark, AssemblyLoadContext assemblyLoadContext = null)
+ internal static RuntimeAssembly InternalLoadAssemblyName(AssemblyName assemblyRef, ref StackCrawlMark stackMark, AssemblyLoadContext? assemblyLoadContext = null)
{
#if FEATURE_APPX
if (ApplicationModel.IsUap)
RuntimeAssembly? assemblyContext,
ref StackCrawlMark stackMark,
bool throwOnFileNotFound,
- AssemblyLoadContext assemblyLoadContext = null);
+ AssemblyLoadContext? assemblyLoadContext = null);
public override bool ReflectionOnly
{
var name = new AssemblyName
{
_name = _name,
- _publicKey = (byte[])_publicKey?.Clone(),
- _publicKeyToken = (byte[])_publicKeyToken?.Clone(),
+ _publicKey = (byte[]?)_publicKey?.Clone(),
+ _publicKeyToken = (byte[]?)_publicKeyToken?.Clone(),
_cultureInfo = _cultureInfo,
- _version = (Version)_version?.Clone(),
+ _version = (Version?)_version?.Clone(),
_flags = _flags,
_codeBase = _codeBase,
_hashAlgorithm = _hashAlgorithm,
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- (int offset, int length) = range.GetOffsetAndLength(array.Length);
+ (int offset, int length) = range.GetOffsetAndLength(array!.Length); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
- if (default(T) != null || typeof(T[]) == array.GetType())
+ if (default(T)! != null || typeof(T[]) == array.GetType()) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34757
{
// We know the type of the array to be exactly T[].
}
}
- private static AsyncLocal<AssemblyLoadContext> s_asyncLocalCurrent;
+ private static AsyncLocal<AssemblyLoadContext>? s_asyncLocalCurrent;
/// <summary>Nullable current AssemblyLoadContext used for context sensitive reflection APIs</summary>
/// <remarks>
///
/// For more details see https://github.com/dotnet/coreclr/blob/master/Documentation/design-docs/AssemblyLoadContext.ContextualReflection.md
/// </remarks>
- public static AssemblyLoadContext CurrentContextualReflectionContext
+ public static AssemblyLoadContext? CurrentContextualReflectionContext
{
get { return s_asyncLocalCurrent?.Value; }
}
- private static void SetCurrentContextualReflectionContext(AssemblyLoadContext value)
+ private static void SetCurrentContextualReflectionContext(AssemblyLoadContext? value)
{
if (s_asyncLocalCurrent == null)
{
- Interlocked.CompareExchange(ref s_asyncLocalCurrent, new AsyncLocal<AssemblyLoadContext>(), null);
+ Interlocked.CompareExchange<AsyncLocal<AssemblyLoadContext>?>(ref s_asyncLocalCurrent, new AsyncLocal<AssemblyLoadContext>(), null);
}
- s_asyncLocalCurrent.Value = value;
+ s_asyncLocalCurrent!.Value = value!; // TODO-NULLABLE-GENERIC
}
/// <summary>Enter scope using this AssemblyLoadContext for ContextualReflection</summary>
/// Returns a disposable ContextualReflectionScope for use in a using block. When the using calls the
/// Dispose() method, it restores the ContextualReflectionScope to its previous value.
/// </remarks>
- public static ContextualReflectionScope EnterContextualReflection(Assembly activating)
+ public static ContextualReflectionScope EnterContextualReflection(Assembly? activating)
{
return activating != null ?
- GetLoadContext(activating).EnterContextualReflection() :
+ GetLoadContext(activating)?.EnterContextualReflection() ?? default :
new ContextualReflectionScope(null);
}
[EditorBrowsable(EditorBrowsableState.Never)]
public struct ContextualReflectionScope : IDisposable
{
- private readonly AssemblyLoadContext _activated;
- private readonly AssemblyLoadContext _predecessor;
+ private readonly AssemblyLoadContext? _activated;
+ private readonly AssemblyLoadContext? _predecessor;
private readonly bool _initialized;
- internal ContextualReflectionScope(AssemblyLoadContext activating)
+ internal ContextualReflectionScope(AssemblyLoadContext? activating)
{
_predecessor = AssemblyLoadContext.CurrentContextualReflectionContext;
AssemblyLoadContext.SetCurrentContextualReflectionContext(activating);
bool result = Interop.Kernel32.QueryUnbiasedInterruptTime(out time100ns);
if (!result)
- Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error())!;
+ Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
// convert to 100ns to milliseconds, and truncate to 32 bits.
return (int)(uint)(time100ns / 10000);