// 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
namespace System.Runtime.InteropServices.ComTypes
{
/*==========================================================================
// 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.Collections;
using System.Runtime.InteropServices.ComTypes;
}
}
- public int Next(int celt, object[] rgVar, IntPtr pceltFetched)
+ public int Next(int celt, object?[] rgVar, IntPtr pceltFetched)
{
int numElements = 0;
{
private static readonly EnumerableToDispatchMarshaler s_enumerableToDispatchMarshaler = new EnumerableToDispatchMarshaler();
- public static ICustomMarshaler GetInstance(string cookie) => s_enumerableToDispatchMarshaler;
+ public static ICustomMarshaler GetInstance(string? cookie) => s_enumerableToDispatchMarshaler;
private EnumerableToDispatchMarshaler()
{
// 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.Collections;
using System.Runtime.InteropServices.ComTypes;
-using Variant = System.Runtime.InteropServices.Variant;
-
namespace System.Runtime.InteropServices.CustomMarshalers
{
internal class EnumerableViewOfDispatch : ICustomAdapter, System.Collections.IEnumerable
IntPtr.Zero);
}
- object resultAsObject = result.ToObject();
+ object? resultAsObject = result.ToObject();
if (!(resultAsObject is IEnumVARIANT enumVariant))
{
throw new InvalidOperationException(SR.InvalidOp_InvalidNewEnumVariant);
// 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.Collections;
-using System.Collections.Generic;
using System.Runtime.InteropServices.ComTypes;
-using System.Text;
namespace System.Runtime.InteropServices.CustomMarshalers
{
{
private static readonly EnumeratorToEnumVariantMarshaler s_enumeratorToEnumVariantMarshaler = new EnumeratorToEnumVariantMarshaler();
- public static ICustomMarshaler GetInstance(string cookie) => s_enumeratorToEnumVariantMarshaler;
+ public static ICustomMarshaler GetInstance(string? cookie) => s_enumeratorToEnumVariantMarshaler;
private EnumeratorToEnumVariantMarshaler()
{
return enumVariantView.Enumerator;
}
- return comObject as IEnumerator;
+ return (comObject as IEnumerator)!;
}
return ComDataHelpers.GetOrCreateManagedViewFromComData<IEnumVARIANT, EnumeratorViewOfEnumVariant>(comObject, var => new EnumeratorViewOfEnumVariant(var));
// 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.Collections;
-using System.Collections.Generic;
using System.Runtime.InteropServices.ComTypes;
-using System.Text;
namespace System.Runtime.InteropServices.CustomMarshalers
{
private readonly IEnumVARIANT _enumVariantObject;
private bool _fetchedLastObject;
private object[] _nextArray = new object[1];
- private object _current;
+ private object? _current;
public EnumeratorViewOfEnumVariant(IEnumVARIANT enumVariantObject)
{
_current = null;
}
- public object Current => _current;
+ public object? Current => _current; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/23268
public unsafe bool MoveNext()
{
// 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.Collections;
-using System.Collections.Generic;
-using System.Runtime.InteropServices.ComTypes;
-using System.Text;
-
+#nullable enable
namespace System.Runtime.InteropServices.CustomMarshalers
{
internal class ExpandoToDispatchExMarshaler : ICustomMarshaler
{
private static readonly ExpandoToDispatchExMarshaler s_ExpandoToDispatchExMarshaler = new ExpandoToDispatchExMarshaler();
- public static ICustomMarshaler GetInstance(string cookie) => s_ExpandoToDispatchExMarshaler;
+ public static ICustomMarshaler GetInstance(string? cookie) => s_ExpandoToDispatchExMarshaler;
private ExpandoToDispatchExMarshaler()
{
// 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.Collections;
-using System.Collections.Generic;
-using System.Runtime.InteropServices.ComTypes;
-using System.Text;
-
+#nullable enable
namespace System.Runtime.InteropServices.CustomMarshalers
{
internal class TypeToTypeInfoMarshaler : ICustomMarshaler
{
private static readonly TypeToTypeInfoMarshaler s_typeToTypeInfoMarshaler = new TypeToTypeInfoMarshaler();
- public static ICustomMarshaler GetInstance(string cookie) => s_typeToTypeInfoMarshaler;
+ public static ICustomMarshaler GetInstance(string? cookie) => s_typeToTypeInfoMarshaler;
private TypeToTypeInfoMarshaler()
{
// 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;
-using System.Security;
-using System.Collections;
-using System.Collections.Generic;
+#nullable enable
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
// 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;
-using System.Security;
-using System.Collections;
-using System.Collections.Generic;
+#nullable enable
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
}
// object this[int index] { get }
- internal object Indexer_Get(int index)
+ internal object? Indexer_Get(int index)
{
if (index < 0)
throw new ArgumentOutOfRangeException(nameof(index));
// Helpers:
- private static object GetAt(IBindableVector _this, uint index)
+ private static object? GetAt(IBindableVector _this, uint index)
{
try
{
// 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.Collections.Generic;
using System.Diagnostics;
// 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.Diagnostics;
using System.Collections;
using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Diagnostics.Contracts;
-using System.Runtime.InteropServices;
-
namespace System.Runtime.InteropServices.WindowsRuntime
{
if (!found)
{
+ Debug.Assert(key != null);
Exception e = new KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
e.HResult = HResults.E_BOUNDS;
throw e;
return new IKeyValuePairEnumerator(items, firstItemIndex, lastItemIndex);
}
- public void Split(out IMapView<TKey, TValue> firstPartition, out IMapView<TKey, TValue> secondPartition)
+ public void Split(out IMapView<TKey, TValue>? firstPartition, out IMapView<TKey, TValue>? secondPartition)
{
if (Count < 2)
{
public bool TryGetValue(TKey key, out TValue value)
{
- KeyValuePair<TKey, TValue> searchKey = new KeyValuePair<TKey, TValue>(key, default);
+ KeyValuePair<TKey, TValue> searchKey = new KeyValuePair<TKey, TValue>(key, default!); // TODO-NULLABLE-GENERIC
int index = Array.BinarySearch(items, firstItemIndex, Count, searchKey, keyValuePairComparator);
if (index < 0)
{
- value = default;
+ value = default!; // TODO-NULLABLE-GENERIC
return false;
}
}
}
- object IEnumerator.Current
+ object? IEnumerator.Current // TODO-NULLABLE:
{
get
{
// 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.Security;
+#nullable enable
using System.Reflection;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-using System.Runtime.Serialization;
-using System.StubHelpers;
-using System.Globalization;
namespace System.Runtime.InteropServices.WindowsRuntime
{
InvokeInternal(target, new object[] { indexValue, value }, false);
}
- private object InvokeInternal(object target, object[] args, bool getValue)
+ private object InvokeInternal(object target, object[]? args, bool getValue)
{
// Forward to the right object if we are dealing with a proxy
if (target is IGetProxyTarget proxy)
accessor,
accessor.DeclaringType.FullName));
- RuntimeMethodInfo rtMethod = accessor as RuntimeMethodInfo;
+ RuntimeMethodInfo? rtMethod = accessor as RuntimeMethodInfo;
if (rtMethod == null)
throw new ArgumentException(SR.Argument_MustBeRuntimeMethodInfo);
// 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.Collections;
using System.Collections.Generic;
using System.Diagnostics;
return enumeration.MoveNext();
}
- object IEnumerator.Current
+ object? IEnumerator.Current
{
get { return ((IEnumerator<TKey>)this).Current; }
}
// 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.Security;
-using System.Reflection;
-using System.Collections;
+#nullable enable
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
if (!keyFound)
{
+ Debug.Assert(key != null);
Exception e = new KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
e.HResult = HResults.E_BOUNDS;
throw e;
if (!removed)
{
+ Debug.Assert(key != null);
Exception e = new KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
e.HResult = HResults.E_BOUNDS;
throw e;
// 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.Collections;
using System.Collections.Generic;
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.InteropServices.WindowsRuntime;
-
namespace System.Runtime.InteropServices.WindowsRuntime
{
return enumeration.MoveNext();
}
- object IEnumerator.Current
+ object? IEnumerator.Current
{
get { return ((IEnumerator<TValue>)this).Current; }
}
// 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.Collections;
using System.Collections.Generic;
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
Debug.Fail("This class is never instantiated");
}
- internal sealed class NonGenericToGenericEnumerator : IEnumerator<object>
+ internal sealed class NonGenericToGenericEnumerator : IEnumerator<object?>
{
private IEnumerator enumerator;
public NonGenericToGenericEnumerator(IEnumerator enumerator)
{ this.enumerator = enumerator; }
- public object Current { get { return enumerator.Current; } }
+ public object? Current { get { return enumerator.Current; } }
public bool MoveNext() { return enumerator.MoveNext(); }
public void Reset() { enumerator.Reset(); }
public void Dispose() { }
internal IBindableIterator First_Stub()
{
IEnumerable _this = Unsafe.As<IEnumerable>(this);
- return new EnumeratorToIteratorAdapter<object>(new NonGenericToGenericEnumerator(_this.GetEnumerator()));
+ return new EnumeratorToIteratorAdapter<object?>(new NonGenericToGenericEnumerator(_this.GetEnumerator()));
}
}
}
}
- object IBindableIterator.Current
+ object? IBindableIterator.Current
{
get
{
- return (object)((IIterator<T>)this).Current;
+ return ((IIterator<T>)this).Current;
}
}
if (typeof(T) == typeof(string))
{
- string[] stringItems = items as string[];
+ string[] stringItems = (items as string[])!;
// Fill the rest of the array with string.Empty to avoid marshaling failure
for (int i = index; i < items.Length; ++i)
// 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.Collections.Generic;
using System.Diagnostics;
using System.Threading;
// Cached multicast delegate which will invoke all of the currently registered delegates. This
// will be accessed frequently in common coding paterns, so we don't want to calculate it repeatedly.
- private volatile T m_invokeList;
+ private volatile T m_invokeList = null!; // TODO-NULLABLE-GENERIC
public EventRegistrationTokenTable()
{
{
// The value being set replaces any of the existing values
m_tokens.Clear();
- m_invokeList = null;
+ m_invokeList = null!; // TODO-NULLABLE-GENERIC
if (value != null)
{
m_tokens[token] = handler;
// Update the current invocation list to include the newly added delegate
- Delegate invokeList = (Delegate)(object)m_invokeList;
+ Delegate? invokeList = (Delegate?)(object?)m_invokeList;
invokeList = MulticastDelegate.Combine(invokeList, (Delegate)(object)handler);
- m_invokeList = (T)(object)invokeList;
+ m_invokeList = (T)(object?)invokeList!; // TODO-NULLABLE-GENERIC
return token;
}
m_tokens.Remove(token);
// Update the current invocation list to remove the delegate
- Delegate invokeList = (Delegate)(object)m_invokeList;
- invokeList = MulticastDelegate.Remove(invokeList, (Delegate)(object)handler);
- m_invokeList = (T)(object)invokeList;
+ Delegate? invokeList = (Delegate?)(object?)m_invokeList;
+ invokeList = MulticastDelegate.Remove(invokeList, (Delegate?)(object?)handler);
+ m_invokeList = (T)(object?)invokeList!; // TODO-NULLABLE-GENERIC
}
}
- public static EventRegistrationTokenTable<T> GetOrCreateEventRegistrationTokenTable(ref EventRegistrationTokenTable<T> refEventTable)
+ public static EventRegistrationTokenTable<T> GetOrCreateEventRegistrationTokenTable(ref EventRegistrationTokenTable<T>? refEventTable)
{
if (refEventTable == null)
{
Interlocked.CompareExchange(ref refEventTable, new EventRegistrationTokenTable<T>(), null);
}
- return refEventTable;
+ return refEventTable!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
}
}
}
// 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
namespace System.Runtime.InteropServices.WindowsRuntime
{
[ComImport]
// 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.Security;
-using System.Collections;
+#nullable enable
using System.Diagnostics;
-using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
// 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
namespace System.Runtime.InteropServices.WindowsRuntime
{
[ComImport]
// 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.StubHelpers;
using System.Reflection;
using System.Diagnostics;
-using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.Generic;
-using System.Runtime.CompilerServices;
-using System.Security;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
// Creates a ICustomProperty implementation for Jupiter
// Called from ICustomPropertyProvider_GetProperty from within runtime
//
- internal static ICustomProperty CreateProperty(object target, string propertyName)
+ internal static ICustomProperty? CreateProperty(object target, string propertyName)
{
Debug.Assert(target != null);
Debug.Assert(propertyName != null);
// Creates a ICustomProperty implementation for Jupiter
// Called from ICustomPropertyProvider_GetIndexedProperty from within runtime
//
- internal static unsafe ICustomProperty CreateIndexedProperty(object target, string propertyName, TypeNameNative* pIndexedParamType)
+ internal static unsafe ICustomProperty? CreateIndexedProperty(object target, string propertyName, TypeNameNative* pIndexedParamType)
{
Debug.Assert(target != null);
Debug.Assert(propertyName != null);
- Type indexedParamType = null;
+ Type? indexedParamType = null;
SystemTypeMarshaler.ConvertToManaged(pIndexedParamType, ref indexedParamType);
return CreateIndexedProperty(target, propertyName, indexedParamType);
}
- internal static ICustomProperty CreateIndexedProperty(object target, string propertyName, Type indexedParamType)
+ internal static ICustomProperty? CreateIndexedProperty(object target, string propertyName, Type? indexedParamType)
{
Debug.Assert(target != null);
Debug.Assert(propertyName != null);
BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public,
null, // default binder
null, // ignore return type
- new Type[] { indexedParamType }, // indexed parameter type
+ new Type?[] { indexedParamType }, // indexed parameter type
null // ignore type modifier
);
//
// override ToString() to make sure callers get correct IStringable.ToString() behavior in native code
//
- public override string ToString()
+ public override string? ToString()
{
return WindowsRuntime.IStringableHelper.ToString(_target);
}
//
// IBindableVector implementation (forwards to IBindableVector / IVector<T>)
//
- object IBindableVector.GetAt(uint index)
+ object? IBindableVector.GetAt(uint index)
{
- IBindableVector bindableVector = GetIBindableVectorNoThrow();
+ IBindableVector? bindableVector = GetIBindableVectorNoThrow();
if (bindableVector != null)
{
// IBindableVector -> IBindableVector
{
get
{
- IBindableVector bindableVector = GetIBindableVectorNoThrow();
+ IBindableVector? bindableVector = GetIBindableVectorNoThrow();
if (bindableVector != null)
{
// IBindableVector -> IBindableVector
IBindableVectorView IBindableVector.GetView()
{
- IBindableVector bindableVector = GetIBindableVectorNoThrow();
+ IBindableVector? bindableVector = GetIBindableVectorNoThrow();
if (bindableVector != null)
{
// IBindableVector -> IBindableVector
_vectorView = vectorView;
}
- object IBindableVectorView.GetAt(uint index)
+ object? IBindableVectorView.GetAt(uint index)
{
return _vectorView.GetAt(index);
}
bool IBindableVector.IndexOf(object value, out uint index)
{
- IBindableVector bindableVector = GetIBindableVectorNoThrow();
+ IBindableVector? bindableVector = GetIBindableVectorNoThrow();
if (bindableVector != null)
{
// IBindableVector -> IBindableVector
void IBindableVector.SetAt(uint index, object value)
{
- IBindableVector bindableVector = GetIBindableVectorNoThrow();
+ IBindableVector? bindableVector = GetIBindableVectorNoThrow();
if (bindableVector != null)
{
// IBindableVector -> IBindableVector
void IBindableVector.InsertAt(uint index, object value)
{
- IBindableVector bindableVector = GetIBindableVectorNoThrow();
+ IBindableVector? bindableVector = GetIBindableVectorNoThrow();
if (bindableVector != null)
{
// IBindableVector -> IBindableVector
void IBindableVector.RemoveAt(uint index)
{
- IBindableVector bindableVector = GetIBindableVectorNoThrow();
+ IBindableVector? bindableVector = GetIBindableVectorNoThrow();
if (bindableVector != null)
{
// IBindableVector -> IBindableVector
void IBindableVector.Append(object value)
{
- IBindableVector bindableVector = GetIBindableVectorNoThrow();
+ IBindableVector? bindableVector = GetIBindableVectorNoThrow();
if (bindableVector != null)
{
// IBindableVector -> IBindableVector
void IBindableVector.RemoveAtEnd()
{
- IBindableVector bindableVector = GetIBindableVectorNoThrow();
+ IBindableVector? bindableVector = GetIBindableVectorNoThrow();
if (bindableVector != null)
{
// IBindableVector -> IBindableVector
void IBindableVector.Clear()
{
- IBindableVector bindableVector = GetIBindableVectorNoThrow();
+ IBindableVector? bindableVector = GetIBindableVectorNoThrow();
if (bindableVector != null)
{
// IBindableVector -> IBindableVector
}
}
- private IBindableVector GetIBindableVectorNoThrow()
+ private IBindableVector? GetIBindableVectorNoThrow()
{
if ((_flags & InterfaceForwardingSupport.IBindableVector) != 0)
return Unsafe.As<IBindableVector>(_target);
//
// IBindableVectorView implementation (forwarding to IBindableVectorView or IVectorView<T>)
//
- object IBindableVectorView.GetAt(uint index)
+ object? IBindableVectorView.GetAt(uint index)
{
- IBindableVectorView bindableVectorView = GetIBindableVectorViewNoThrow();
+ IBindableVectorView? bindableVectorView = GetIBindableVectorViewNoThrow();
if (bindableVectorView != null)
return bindableVectorView.GetAt(index);
else
{
get
{
- IBindableVectorView bindableVectorView = GetIBindableVectorViewNoThrow();
+ IBindableVectorView? bindableVectorView = GetIBindableVectorViewNoThrow();
if (bindableVectorView != null)
return bindableVectorView.Size;
else
bool IBindableVectorView.IndexOf(object value, out uint index)
{
- IBindableVectorView bindableVectorView = GetIBindableVectorViewNoThrow();
+ IBindableVectorView? bindableVectorView = GetIBindableVectorViewNoThrow();
if (bindableVectorView != null)
return bindableVectorView.IndexOf(value, out index);
else
IBindableIterator IBindableIterable.First()
{
- IBindableVectorView bindableVectorView = GetIBindableVectorViewNoThrow();
+ IBindableVectorView? bindableVectorView = GetIBindableVectorViewNoThrow();
if (bindableVectorView != null)
return bindableVectorView.First();
else
{ _iterator = iterator; }
public bool HasCurrent { get { return _iterator.HasCurrent; } }
- public object Current { get { return (object)_iterator.Current; } }
+ public object? Current { get { return _iterator.Current; } }
public bool MoveNext() { return _iterator.MoveNext(); }
}
- private IBindableVectorView GetIBindableVectorViewNoThrow()
+ private IBindableVectorView? GetIBindableVectorViewNoThrow()
{
if ((_flags & InterfaceForwardingSupport.IBindableVectorView) != 0)
return Unsafe.As<IBindableVectorView>(_target);
// 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.Collections.Generic;
// Windows.Foundation.Collections.IIterable`1 cannot be referenced from managed code because it's hidden
// 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
namespace System.Runtime.InteropServices.WindowsRuntime
{
[ComImport]
[Guid("6a1d6c07-076d-49f2-8314-f52c9c9a8331")]
internal interface IBindableIterator
{
- object Current
+ object? Current
{
get;
}
// 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.Collections.Generic;
// Windows.Foundation.Collections.IMap`2, IMapView`2, and IKeyValuePair`2 cannot be referenced from
V Lookup(K key);
uint Size { get; }
bool HasKey(K key);
- void Split(out IMapView<K, V> first, out IMapView<K, V> second);
+ void Split(out IMapView<K, V>? first, out IMapView<K, V>? second);
}
[ComImport]
// 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.Security;
+#nullable enable
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
// throw an exception from Lookup.
if (!_this.HasKey(key))
{
- value = default;
+ value = default!; // TODO-NULLABLE-GENERIC
return false;
}
{
if (HResults.E_BOUNDS == ex.HResult)
{
- value = default;
+ value = default!; // TODO-NULLABLE-GENERIC
return false;
}
throw;
return enumeration.MoveNext();
}
- object IEnumerator.Current
+ object? IEnumerator.Current
{
get { return ((IEnumerator<TKey>)this).Current; }
}
return enumeration.MoveNext();
}
- object IEnumerator.Current
+ object? IEnumerator.Current
{
get { return ((IEnumerator<TValue>)this).Current; }
}
// 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
namespace System.Runtime.InteropServices.WindowsRuntime
{
// 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.Security;
-using System.Collections;
+#nullable enable
using System.Collections.Generic;
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
if (!keyFound)
{
+ Debug.Assert(key != null);
Exception e = new KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
e.HResult = HResults.E_BOUNDS;
throw e;
}
// void Split(out IMapView<K, V> first, out IMapView<K, V> second)
- internal void Split<K, V>(out IMapView<K, V> first, out IMapView<K, V> second)
+ internal void Split<K, V>(out IMapView<K, V>? first, out IMapView<K, V>? second)
{
IReadOnlyDictionary<K, V> _this = Unsafe.As<IReadOnlyDictionary<K, V>>(this);
// 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.Security;
-using System.Collections;
+#nullable enable
using System.Collections.Generic;
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
if (typeof(T) == typeof(string))
{
- string[] stringItems = items as string[];
+ string[] stringItems = (items as string[])!;
// Fill in the rest of the array with string.Empty to avoid marshaling failure
for (uint i = itemCount; i < items.Length; ++i)
// 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
namespace System.Runtime.InteropServices.WindowsRuntime
{
[ComImport]
// 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
namespace System.Runtime.InteropServices.WindowsRuntime
{
[ComImport]
// 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.Collections.Generic;
// Windows.Foundation.Collections.IVector`1 and IVectorView`1 cannot be referenced from managed
[WindowsRuntimeImport]
internal interface IBindableVector : IBindableIterable
{
- object GetAt(uint index);
+ object? GetAt(uint index);
uint Size { get; }
IBindableVectorView GetView();
bool IndexOf(object value, out uint index);
[WindowsRuntimeImport]
internal interface IBindableVectorView : IBindableIterable
{
- object GetAt(uint index);
+ object? GetAt(uint index);
uint Size { get; }
bool IndexOf(object value, out uint index);
}
// 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.Security;
-using System.Collections;
+#nullable enable
using System.Collections.Generic;
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
// 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.Collections;
using System.Collections.Generic;
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-using System.Security;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
Debug.Fail("This class is never instantiated");
}
- private sealed class NonGenericToGenericIterator : IIterator<object>
+ private sealed class NonGenericToGenericIterator : IIterator<object?>
{
private IBindableIterator iterator;
public NonGenericToGenericIterator(IBindableIterator iterator)
{ this.iterator = iterator; }
- public object Current { get { return iterator.Current; } }
+ public object? Current { get { return iterator.Current; } }
public bool HasCurrent { get { return iterator.HasCurrent; } }
public bool MoveNext() { return iterator.MoveNext(); }
- public int GetMany(object[] items) { throw new NotSupportedException(); }
+ public int GetMany(object?[] items) { throw new NotSupportedException(); }
}
// This method is invoked when GetEnumerator is called on a WinRT-backed implementation of IEnumerable.
internal IEnumerator GetEnumerator_Stub()
{
IBindableIterable _this = Unsafe.As<IBindableIterable>(this);
- return new IteratorToEnumeratorAdapter<object>(new NonGenericToGenericIterator(_this.First()));
+ return new IteratorToEnumeratorAdapter<object?>(new NonGenericToGenericIterator(_this.First()));
}
}
{
private IIterator<T> m_iterator;
private bool m_hadCurrent;
- private T m_current;
+ private T m_current = default!; // TODO-NULLABLE-GENERIC
private bool m_isInitialized;
internal IteratorToEnumeratorAdapter(IIterator<T> iterator)
}
}
- object IEnumerator.Current
+ object? IEnumerator.Current
{
get
{
// 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.Security;
-using System.Reflection;
+#nullable enable
using System.Collections;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
// 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.Security;
-using System.Reflection;
+#nullable enable
using System.Collections;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
{
public IBindableIterator First()
{
IEnumerator enumerator = list.GetEnumerator();
- return new EnumeratorToIteratorAdapter<object>(new EnumerableToBindableIterableAdapter.NonGenericToGenericEnumerator(enumerator));
+ return new EnumeratorToIteratorAdapter<object?>(new EnumerableToBindableIterableAdapter.NonGenericToGenericEnumerator(enumerator));
}
// IBindableVectorView implementation:
- public object GetAt(uint index)
+ public object? GetAt(uint index)
{
EnsureIndexInt32(index, list.Count);
// 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.Security;
-using System.Reflection;
-using System.Collections;
+#nullable enable
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
if (typeof(T) == typeof(string))
{
- string[] stringItems = items as string[];
+ string[] stringItems = (items as string[])!;
// Fill in rest of the array with string.Empty to avoid marshaling failure
for (uint i = itemCount; i < items.Length; ++i)
// 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.Reflection;
-using System.Runtime.InteropServices;
-using System.Security;
using System.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
{
try
{
- return Activator.CreateInstance(m_type);
+ return Activator.CreateInstance(m_type)!;
}
catch (MissingMethodException)
{
}
catch (TargetInvocationException e)
{
- throw e.InnerException;
+ throw e.InnerException!;
}
}
// 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.Security;
-using System.Collections;
+#nullable enable
using System.Collections.Generic;
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
// 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.Security;
-using System.Collections;
+#nullable enable
using System.Collections.Generic;
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
IMap<K, V> _this = Unsafe.As<IMap<K, V>>(this);
if (!_this.HasKey(key))
{
- value = default;
+ value = default!; // TODO-NULLABLE-GENERIC
return false;
}
}
catch (KeyNotFoundException)
{
- value = default;
+ value = default!; // TODO-NULLABLE-GENERIC
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;
-using System.Security;
-using System.Collections;
+#nullable enable
using System.Collections.Generic;
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
// 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;
-using System.Security;
-
+#nullable enable
namespace System.Runtime.InteropServices.WindowsRuntime
{
#if BIT64
// 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.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Security;
-
+#nullable enable
namespace System.Runtime.InteropServices.WindowsRuntime
{
// Note this is a copy of the PropertyType enumeration from Windows.Foundation.winmd
**
===========================================================*/
-using System;
-using System.Runtime.InteropServices;
-using System.Runtime.InteropServices.WindowsRuntime;
+#nullable enable
using System.Runtime.CompilerServices;
-using System.Security;
namespace System.Runtime.InteropServices.WindowsRuntime
{
internal class IStringableHelper
{
- internal static string ToString(object obj)
+ internal static string? ToString(object obj)
{
if (obj is IGetProxyTarget proxy)
obj = proxy.GetTarget();
internal extern IntPtr GetRedirectedEqualsMD();
[MethodImpl(MethodImplOptions.InternalCall)]
- internal extern bool RedirectEquals(object obj, IntPtr pMD);
+ internal extern bool RedirectEquals(object? obj, IntPtr pMD);
- public override bool Equals(object obj)
+ public override bool Equals(object? obj)
{
IntPtr pMD = GetRedirectedEqualsMD();
if (pMD == IntPtr.Zero)
// 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.Security;
-using System.Collections;
-using System.Collections.Generic;
+#nullable enable
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
// 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.Security;
-using System.Collections;
-using System.Collections.Generic;
+#nullable enable
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
// 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.Security;
-using System.Collections;
-using System.Collections.Generic;
+#nullable enable
using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
using Internal.Runtime.CompilerServices;
namespace System.Runtime.InteropServices.WindowsRuntime
// 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
namespace System.Runtime.InteropServices.WindowsRuntime
{
// WindowsFoundationEventHandler<T> a copy of the definition for the Windows.Foundation.EventHandler<T> delegate
// 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.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
using System.Threading;
-using System.Security;
namespace System.Runtime.InteropServices.WindowsRuntime
{
// They have completely different implementation because native side has its own unique problem to solve -
// there could be more than one RCW for the same COM object
// it would be more confusing and less-performant if we were to merge them together
- object target = removeMethod.Target;
+ object? target = removeMethod.Target;
if (target == null || Marshal.IsComObject(target))
NativeOrStaticEventRegistrationImpl.AddEventHandler<T>(addMethod, removeMethod, handler);
else
// They have completely different implementation because native side has its own unique problem to solve -
// there could be more than one RCW for the same COM object
// it would be more confusing and less-performant if we were to merge them together
- object target = removeMethod.Target;
+ object? target = removeMethod.Target;
if (target == null || Marshal.IsComObject(target))
NativeOrStaticEventRegistrationImpl.RemoveEventHandler<T>(removeMethod, handler);
else
// They have completely different implementation because native side has its own unique problem to solve -
// there could be more than one RCW for the same COM object
// it would be more confusing and less-performant if we were to merge them together
- object target = removeMethod.Target;
+ object? target = removeMethod.Target;
if (target == null || Marshal.IsComObject(target))
NativeOrStaticEventRegistrationImpl.RemoveAllEventHandlers(removeMethod);
else
internal struct EventRegistrationTokenList
{
private EventRegistrationToken firstToken; // Optimization for common case where there is only one token
- private List<EventRegistrationToken> restTokens; // Rest of the tokens
+ private List<EventRegistrationToken>? restTokens; // Rest of the tokens
internal EventRegistrationTokenList(EventRegistrationToken token)
{
{
Debug.Assert(addMethod != null);
Debug.Assert(removeMethod != null);
+ Debug.Assert(removeMethod.Target != null);
+ Debug.Assert(handler != null);
// Add the method, and make a note of the token -> delegate mapping.
object instance = removeMethod.Target;
lock (s_eventRegistrations)
{
- Dictionary<MethodInfo, Dictionary<object, EventRegistrationTokenList>> instanceMap = null;
+ Dictionary<MethodInfo, Dictionary<object, EventRegistrationTokenList>>? instanceMap = null;
if (!s_eventRegistrations.TryGetValue(instance, out instanceMap))
{
instanceMap = new Dictionary<MethodInfo, Dictionary<object, EventRegistrationTokenList>>();
s_eventRegistrations.Add(instance, instanceMap);
}
- Dictionary<object, EventRegistrationTokenList> tokens = null;
+ Dictionary<object, EventRegistrationTokenList>? tokens = null;
if (!instanceMap.TryGetValue(removeMethod.Method, out tokens))
{
tokens = new Dictionary<object, EventRegistrationTokenList>();
internal static void RemoveEventHandler<T>(Action<EventRegistrationToken> removeMethod, T handler)
{
Debug.Assert(removeMethod != null);
+ Debug.Assert(removeMethod.Target != null);
+ Debug.Assert(handler != null);
object instance = removeMethod.Target;
Dictionary<object, EventRegistrationTokenList> registrationTokens = GetEventRegistrationTokenTable(instance, removeMethod);
internal static void RemoveAllEventHandlers(Action<EventRegistrationToken> removeMethod)
{
Debug.Assert(removeMethod != null);
+ Debug.Assert(removeMethod.Target != null);
object instance = removeMethod.Target;
Dictionary<object, EventRegistrationTokenList> registrationTokens = GetEventRegistrationTokenTable(instance, removeMethod);
// Get InstanceKey to use in the cache
private static object GetInstanceKey(Action<EventRegistrationToken> removeMethod)
{
- object target = removeMethod.Target;
+ object? target = removeMethod.Target;
Debug.Assert(target == null || Marshal.IsComObject(target), "Must be null or a RCW");
if (target == null)
return removeMethod.Method.DeclaringType;
return (object)Marshal.GetRawIUnknownForComObjectNoAddRef(target);
}
- private static object FindEquivalentKeyUnsafe(ConditionalWeakTable<object, EventRegistrationTokenListWithCount> registrationTable, object handler, out EventRegistrationTokenListWithCount tokens)
+ private static object? FindEquivalentKeyUnsafe(ConditionalWeakTable<object, EventRegistrationTokenListWithCount> registrationTable, object handler, out EventRegistrationTokenListWithCount? tokens) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
{
foreach (KeyValuePair<object, EventRegistrationTokenListWithCount> item in registrationTable)
{
Action<EventRegistrationToken> removeMethod,
T handler)
{
+ Debug.Assert(handler != null);
+
// The instanceKey will be IUnknown * of the target object
object instanceKey = GetInstanceKey(removeMethod);
try
{
- EventRegistrationTokenListWithCount tokens;
+ EventRegistrationTokenListWithCount? tokens;
//
// The whole add/remove code has to be protected by a reader/writer lock
try
{
// Add the method, and make a note of the delegate -> token mapping.
- TokenListCount tokenListCount;
+ TokenListCount? tokenListCount;
ConditionalWeakTable<object, EventRegistrationTokenListWithCount> registrationTokens = GetOrCreateEventRegistrationTokenTable(instanceKey, removeMethod, out tokenListCount);
lock (registrationTokens)
{
// will be added into B's token list, but once we unsubscribe B, we might end up removing
// the last token in C, and that may lead to crash.
//
- object key = FindEquivalentKeyUnsafe(registrationTokens, handler, out tokens);
+ object? key = FindEquivalentKeyUnsafe(registrationTokens, handler, out tokens);
if (key == null)
{
tokens = new EventRegistrationTokenListWithCount(tokenListCount, token);
}
else
{
- tokens.Push(token);
+ tokens!.Push(token); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
}
tokenAdded = true;
}
}
- private static ConditionalWeakTable<object, EventRegistrationTokenListWithCount> GetEventRegistrationTokenTableNoCreate(object instance, Action<EventRegistrationToken> removeMethod, out TokenListCount tokenListCount)
+ private static ConditionalWeakTable<object, EventRegistrationTokenListWithCount>? GetEventRegistrationTokenTableNoCreate(object instance, Action<EventRegistrationToken> removeMethod, out TokenListCount? tokenListCount)
{
Debug.Assert(instance != null);
Debug.Assert(removeMethod != null);
Debug.Assert(instance != null);
Debug.Assert(removeMethod != null);
- return GetEventRegistrationTokenTableInternal(instance, removeMethod, out tokenListCount, /* createIfNotFound = */ true);
+ return GetEventRegistrationTokenTableInternal(instance, removeMethod, out tokenListCount!, /* createIfNotFound = */ true)!;
}
// Get the event registration token table for an event. These are indexed by the remove method of the event.
- private static ConditionalWeakTable<object, EventRegistrationTokenListWithCount> GetEventRegistrationTokenTableInternal(object instance, Action<EventRegistrationToken> removeMethod, out TokenListCount tokenListCount, bool createIfNotFound)
+ private static ConditionalWeakTable<object, EventRegistrationTokenListWithCount>? GetEventRegistrationTokenTableInternal(object instance, Action<EventRegistrationToken> removeMethod, out TokenListCount? tokenListCount, bool createIfNotFound)
{
Debug.Assert(instance != null);
Debug.Assert(removeMethod != null);
internal static void RemoveEventHandler<T>(Action<EventRegistrationToken> removeMethod, T handler)
{
+ Debug.Assert(handler != null);
+
object instanceKey = GetInstanceKey(removeMethod);
EventRegistrationToken token;
s_eventCacheRWLock.AcquireReaderLock(Timeout.Infinite);
try
{
- TokenListCount tokenListCount;
- ConditionalWeakTable<object, EventRegistrationTokenListWithCount> registrationTokens = GetEventRegistrationTokenTableNoCreate(instanceKey, removeMethod, out tokenListCount);
+ TokenListCount? tokenListCount;
+ ConditionalWeakTable<object, EventRegistrationTokenListWithCount>? registrationTokens = GetEventRegistrationTokenTableNoCreate(instanceKey, removeMethod, out tokenListCount);
if (registrationTokens == null)
{
// We have no information regarding this particular instance (IUnknown*/type) - just return
lock (registrationTokens)
{
- EventRegistrationTokenListWithCount tokens;
+ EventRegistrationTokenListWithCount? tokens;
// Note:
// When unsubscribing events, we allow subscribing the event using a different delegate
// It actually doesn't matter which delegate - as long as it matches
// Note that inside TryGetValueWithValueEquality we assumes that any delegate
// with the same value equality would have the same hash code
- object key = FindEquivalentKeyUnsafe(registrationTokens, handler, out tokens);
+ object? key = FindEquivalentKeyUnsafe(registrationTokens, handler, out tokens);
Debug.Assert((key != null && tokens != null) || (key == null && tokens == null),
"key and tokens must be both null or non-null");
if (tokens == null)
// NOTE: We should not check whether registrationTokens has 0 entries and remove it from the cache
// (just like managed event implementation), because this might have raced with the finalizer of
// EventRegistrationTokenList
- registrationTokens.Remove(key);
+ registrationTokens.Remove(key!); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2388
}
Log("[WinRT_Eventing] Event unsubscribed for managed instance = " + instanceKey + ", handler = " + handler + ", token = " + token.Value + "\n");
s_eventCacheRWLock.AcquireReaderLock(Timeout.Infinite);
try
{
- TokenListCount tokenListCount;
- ConditionalWeakTable<object, EventRegistrationTokenListWithCount> registrationTokens = GetEventRegistrationTokenTableNoCreate(instanceKey, removeMethod, out tokenListCount);
+ ConditionalWeakTable<object, EventRegistrationTokenListWithCount>? registrationTokens = GetEventRegistrationTokenTableNoCreate(instanceKey, removeMethod, out _);
if (registrationTokens == null)
{
// We have no information regarding this particular instance (IUnknown*/type) - just return
private uint numReadWaiters; // maximum number of threads that can be doing a WaitOne on the readEvent
// conditions we wait on.
- private EventWaitHandle writeEvent; // threads waiting to acquire a write lock go here.
- private EventWaitHandle readEvent; // threads waiting to acquire a read lock go here (will be released in bulk)
+ private EventWaitHandle? writeEvent; // threads waiting to acquire a write lock go here.
+ private EventWaitHandle? readEvent; // threads waiting to acquire a read lock go here (will be released in bulk)
internal MyReaderWriterLock()
{
/// while holding a spin lock). If all goes well, reenter the lock and
/// set 'waitEvent'
/// </summary>
- private void LazyCreateEvent(ref EventWaitHandle waitEvent, bool makeAutoResetEvent)
+ private void LazyCreateEvent(ref EventWaitHandle? waitEvent, bool makeAutoResetEvent)
{
Debug.Assert(myLock != 0, "Lock must be held");
Debug.Assert(waitEvent == null, "Wait event must be null");
if (owners == 0 && numWriteWaiters > 0)
{
ExitMyLock(); // Exit before signaling to improve efficiency (wakee will need the lock)
- writeEvent.Set(); // release one writer.
+ writeEvent!.Set(); // release one writer. Must be non-null if there were waiters.
}
else if (owners >= 0 && numReadWaiters != 0)
{
ExitMyLock(); // Exit before signaling to improve efficiency (wakee will need the lock)
- readEvent.Set(); // release all readers.
+ readEvent!.Set(); // release all readers. Must be non-null if there were waiters.
}
else
+ {
ExitMyLock();
+ }
}
private void EnterMyLock()
}
}
- internal static Exception GetExceptionForHR(int hresult, Exception innerException, string messageResource)
+ internal static Exception GetExceptionForHR(int hresult, Exception? innerException, string? messageResource)
{
- Exception e = null;
+ Exception? e = null;
if (innerException != null)
{
- string message = innerException.Message;
+ string? message = innerException.Message;
if (message == null && messageResource != null)
{
message = SR.GetResourceString(messageResource);
}
else
{
- string message = (messageResource != null ? SR.GetResourceString(messageResource): null);
+ string? message = (messageResource != null ? SR.GetResourceString(messageResource): null);
e = new Exception(message);
}
return e;
}
- internal static Exception GetExceptionForHR(int hresult, Exception innerException)
+ internal static Exception GetExceptionForHR(int hresult, Exception? innerException)
{
return GetExceptionForHR(hresult, innerException, null);
}
/// for the application to be invoked to process the error.
/// </summary>
/// <returns>true if the error was reported, false if not (ie running on Win8)</returns>
- internal static bool ReportUnhandledError(Exception e)
+ internal static bool ReportUnhandledError(Exception? e)
{
// Only report to the WinRT global exception handler in modern apps
if (!ApplicationModel.IsUap)
// 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.Collections.Generic;
+#nullable enable
using System.Collections.ObjectModel;
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Security;
namespace System.Runtime.InteropServices.WindowsRuntime
{
{
private static EventHandler<DesignerNamespaceResolveEventArgs> DesignerNamespaceResolve;
- internal static string[] OnDesignerNamespaceResolve(string namespaceName)
+ internal static string[]? OnDesignerNamespaceResolve(string namespaceName)
{
- EventHandler<DesignerNamespaceResolveEventArgs> eventHandler = DesignerNamespaceResolve;
+ EventHandler<DesignerNamespaceResolveEventArgs>? eventHandler = DesignerNamespaceResolve;
if (eventHandler != null)
{
foreach (EventHandler<DesignerNamespaceResolveEventArgs> handler in eventHandler.GetInvocationList())
// 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 must be implemented by all custom marshalers.