diff options
Diffstat (limited to 'src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime')
34 files changed, 499 insertions, 437 deletions
diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/Attributes.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/Attributes.cs index 7fa2420530..d78aae216b 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/Attributes.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/Attributes.cs @@ -90,14 +90,14 @@ namespace System.Runtime.InteropServices.WindowsRuntime [AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = false)] public sealed class ReadOnlyArrayAttribute : Attribute { - public ReadOnlyArrayAttribute() {} + public ReadOnlyArrayAttribute() { } } // Applies to write-only array parameters [AttributeUsage(AttributeTargets.Parameter, Inherited = false, AllowMultiple = false)] public sealed class WriteOnlyArrayAttribute : Attribute { - public WriteOnlyArrayAttribute() {} + public WriteOnlyArrayAttribute() { } } @@ -119,5 +119,4 @@ namespace System.Runtime.InteropServices.WindowsRuntime get { return m_Name; } } } - } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToCollectionAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToCollectionAdapter.cs index e3c6a926d3..2d0e9a799c 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToCollectionAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToCollectionAdapter.cs @@ -87,10 +87,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Array items = Array.CreateInstance(typeof(object), new int[] { 1 }, new int[] { -1 }); // list.CopyTo(items, 0); - if(srcLen > (destLen - (arrayIndex - destLB))) + if (srcLen > (destLen - (arrayIndex - destLB))) throw new ArgumentException(Environment.GetResourceString("Argument_InsufficientSpaceToCopyCollection")); - if(arrayIndex - destLB > destLen) + if (arrayIndex - destLB > destLen) throw new ArgumentException(Environment.GetResourceString("Argument_IndexOutOfArrayBounds")); // We need to verify the index as we; diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs index 3a52d12234..86321e6191 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs @@ -47,7 +47,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal static object UnboxHelper(object wrapper) { Contract.Requires(wrapper != null); - + CLRIKeyValuePairImpl<K, V> reference = (CLRIKeyValuePairImpl<K, V>)wrapper; return reference._pair; } @@ -61,6 +61,5 @@ namespace System.Runtime.InteropServices.WindowsRuntime { return _pair; } - } } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIPropertyValueImpl.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIPropertyValueImpl.cs index b7dad17a6b..8fd30438ad 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIPropertyValueImpl.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIPropertyValueImpl.cs @@ -25,9 +25,12 @@ namespace System.Runtime.InteropServices.WindowsRuntime _data = data; } - private static Tuple<Type, PropertyType>[] NumericScalarTypes { - get { - if (s_numericScalarTypes == null) { + private static Tuple<Type, PropertyType>[] NumericScalarTypes + { + get + { + if (s_numericScalarTypes == null) + { Tuple<Type, PropertyType>[] numericScalarTypes = new Tuple<Type, PropertyType>[] { new Tuple<Type, PropertyType>(typeof(Byte), PropertyType.UInt8), new Tuple<Type, PropertyType>(typeof(Int16), PropertyType.Int16), @@ -47,14 +50,17 @@ namespace System.Runtime.InteropServices.WindowsRuntime } } - public PropertyType Type { + public PropertyType Type + { [Pure] get { return _type; } } - public bool IsNumericScalar { + public bool IsNumericScalar + { [Pure] - get { + get + { return IsNumericScalarImpl(_type, _data); } } @@ -190,7 +196,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime if (this.Type != PropertyType.Size) throw new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueElement", this.Type, "Size"), __HResults.TYPE_E_TYPEMISMATCH); Contract.EndContractBlock(); - + return Unbox<Size>(IReferenceFactory.s_sizeType); } @@ -200,7 +206,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime if (this.Type != PropertyType.Rect) throw new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueElement", this.Type, "Rect"), __HResults.TYPE_E_TYPEMISMATCH); Contract.EndContractBlock(); - + return Unbox<Rect>(IReferenceFactory.s_rectType); } @@ -321,7 +327,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime if (this.Type != PropertyType.PointArray) throw new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueElement", this.Type, "Point[]"), __HResults.TYPE_E_TYPEMISMATCH); Contract.EndContractBlock(); - + return UnboxArray<Point>(IReferenceFactory.s_pointType); } @@ -346,15 +352,18 @@ namespace System.Runtime.InteropServices.WindowsRuntime return UnboxArray<Rect>(IReferenceFactory.s_rectType); } - private T[] CoerceArrayValue<T>(PropertyType unboxType) { + private T[] CoerceArrayValue<T>(PropertyType unboxType) + { // If we contain the type being looked for directly, then take the fast-path - if (Type == unboxType) { + if (Type == unboxType) + { return (T[])_data; } // Make sure we have an array to begin with Array dataArray = _data as Array; - if (dataArray == null) { + if (dataArray == null) + { throw new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueElement", this.Type, typeof(T).MakeArrayType().Name), __HResults.TYPE_E_TYPEMISMATCH); } @@ -365,10 +374,14 @@ namespace System.Runtime.InteropServices.WindowsRuntime // If we do not have the correct array type, then we need to convert the array element-by-element // to a new array of the requested type T[] coercedArray = new T[dataArray.Length]; - for (int i = 0; i < dataArray.Length; ++i) { - try { + for (int i = 0; i < dataArray.Length; ++i) + { + try + { coercedArray[i] = CoerceScalarValue<T>(scalarType, dataArray.GetValue(i)); - } catch (InvalidCastException elementCastException) { + } + catch (InvalidCastException elementCastException) + { Exception e = new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueArrayCoersion", this.Type, typeof(T).MakeArrayType().Name, i, elementCastException.Message), elementCastException); e.SetErrorCode(elementCastException._HResult); throw e; @@ -381,81 +394,104 @@ namespace System.Runtime.InteropServices.WindowsRuntime private T CoerceScalarValue<T>(PropertyType unboxType) { // If we are just a boxed version of the requested type, then take the fast path out - if (Type == unboxType) { + if (Type == unboxType) + { return (T)_data; } return CoerceScalarValue<T>(Type, _data); } - private static T CoerceScalarValue<T>(PropertyType type, object value) { + private static T CoerceScalarValue<T>(PropertyType type, object value) + { // If the property type is neither one of the coercable numeric types nor IInspectable, we // should not attempt coersion, even if the underlying value is technically convertable - if (!IsCoercable(type, value) && type != PropertyType.Inspectable) { + if (!IsCoercable(type, value) && type != PropertyType.Inspectable) + { throw new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueElement", type, typeof(T).Name), __HResults.TYPE_E_TYPEMISMATCH); } - try { + try + { // Try to coerce: // * String <--> Guid // * Numeric scalars - if (type == PropertyType.String && typeof(T) == typeof(Guid)) { + if (type == PropertyType.String && typeof(T) == typeof(Guid)) + { return (T)(object)Guid.Parse((string)value); } - else if (type == PropertyType.Guid && typeof(T) == typeof(String)) { - return (T)(object)((Guid)value).ToString("D", System.Globalization.CultureInfo.InvariantCulture); + else if (type == PropertyType.Guid && typeof(T) == typeof(String)) + { + return (T)(object)((Guid)value).ToString("D", System.Globalization.CultureInfo.InvariantCulture); } - else { + else + { // Iterate over the numeric scalars, to see if we have a match for one of the known conversions - foreach (Tuple<Type, PropertyType> numericScalar in NumericScalarTypes) { - if (numericScalar.Item1 == typeof(T)) { + foreach (Tuple<Type, PropertyType> numericScalar in NumericScalarTypes) + { + if (numericScalar.Item1 == typeof(T)) + { return (T)Convert.ChangeType(value, typeof(T), System.Globalization.CultureInfo.InvariantCulture); } } } } - catch (FormatException) { + catch (FormatException) + { throw new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueElement", type, typeof(T).Name), __HResults.TYPE_E_TYPEMISMATCH); } - catch (InvalidCastException) { + catch (InvalidCastException) + { throw new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueElement", type, typeof(T).Name), __HResults.TYPE_E_TYPEMISMATCH); } - catch (OverflowException) { + catch (OverflowException) + { throw new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueCoersion", type, value, typeof(T).Name), __HResults.DISP_E_OVERFLOW); } // If the property type is IInspectable, and we have a nested IPropertyValue, then we need // to pass along the request to coerce the value. IPropertyValue ipv = value as IPropertyValue; - if (type == PropertyType.Inspectable && ipv != null) { - if (typeof(T) == typeof(Byte)) { + if (type == PropertyType.Inspectable && ipv != null) + { + if (typeof(T) == typeof(Byte)) + { return (T)(object)ipv.GetUInt8(); } - else if (typeof(T) == typeof(Int16)) { + else if (typeof(T) == typeof(Int16)) + { return (T)(object)ipv.GetInt16(); } - else if (typeof(T) == typeof(UInt16)) { + else if (typeof(T) == typeof(UInt16)) + { return (T)(object)ipv.GetUInt16(); } - else if (typeof(T) == typeof(Int32)) { + else if (typeof(T) == typeof(Int32)) + { return (T)(object)ipv.GetUInt32(); } - else if (typeof(T) == typeof(UInt32)) { + else if (typeof(T) == typeof(UInt32)) + { return (T)(object)ipv.GetUInt32(); } - else if (typeof(T) == typeof(Int64)) { + else if (typeof(T) == typeof(Int64)) + { return (T)(object)ipv.GetInt64(); } - else if (typeof(T) == typeof(UInt64)) { + else if (typeof(T) == typeof(UInt64)) + { return (T)(object)ipv.GetUInt64(); } - else if (typeof(T) == typeof(Single)) { + else if (typeof(T) == typeof(Single)) + { return (T)(object)ipv.GetSingle(); } - else if (typeof(T) == typeof(Double)) { + else if (typeof(T) == typeof(Double)) + { return (T)(object)ipv.GetDouble(); } - else { + else + { BCLDebug.Assert(false, "T in coersion function wasn't understood as a type that can be coerced - make sure that CoerceScalarValue and NumericScalarTypes are in sync"); } } @@ -464,9 +500,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime throw new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueElement", type, typeof(T).Name), __HResults.TYPE_E_TYPEMISMATCH); } - private static bool IsCoercable(PropertyType type, object data) { + private static bool IsCoercable(PropertyType type, object data) + { // String <--> Guid is allowed - if (type == PropertyType.Guid || type == PropertyType.String) { + if (type == PropertyType.Guid || type == PropertyType.String) + { return true; } @@ -474,13 +512,17 @@ namespace System.Runtime.InteropServices.WindowsRuntime return IsNumericScalarImpl(type, data); } - private static bool IsNumericScalarImpl(PropertyType type, object data) { - if (data.GetType().IsEnum) { + private static bool IsNumericScalarImpl(PropertyType type, object data) + { + if (data.GetType().IsEnum) + { return true; } - foreach (Tuple<Type, PropertyType> numericScalar in NumericScalarTypes) { - if (numericScalar.Item2 == type) { + foreach (Tuple<Type, PropertyType> numericScalar in NumericScalarTypes) + { + if (numericScalar.Item2 == type) + { return true; } } @@ -490,42 +532,50 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Unbox the data stored in the property value to a structurally equivilent type [Pure] - private unsafe T Unbox<T>(Type expectedBoxedType) where T : struct { + private unsafe T Unbox<T>(Type expectedBoxedType) where T : struct + { Contract.Requires(expectedBoxedType != null); Contract.Requires(Marshal.SizeOf(expectedBoxedType) == Marshal.SizeOf(typeof(T))); - if (_data.GetType() != expectedBoxedType) { + if (_data.GetType() != expectedBoxedType) + { throw new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueElement", _data.GetType(), expectedBoxedType.Name), __HResults.TYPE_E_TYPEMISMATCH); } T unboxed = new T(); - fixed (byte *pData = &JitHelpers.GetPinningHelper(_data).m_data) { + fixed (byte* pData = &JitHelpers.GetPinningHelper(_data).m_data) + { byte* pUnboxed = (byte*)JitHelpers.UnsafeCastToStackPointer(ref unboxed); Buffer.Memcpy(pUnboxed, pData, Marshal.SizeOf(unboxed)); } - + return unboxed; } // Convert the array stored in the property value to a structurally equivilent array type [Pure] - private unsafe T[] UnboxArray<T>(Type expectedArrayElementType) where T : struct { + private unsafe T[] UnboxArray<T>(Type expectedArrayElementType) where T : struct + { Contract.Requires(expectedArrayElementType != null); Contract.Requires(Marshal.SizeOf(expectedArrayElementType) == Marshal.SizeOf(typeof(T))); Array dataArray = _data as Array; - if (dataArray == null || _data.GetType().GetElementType() != expectedArrayElementType) { + if (dataArray == null || _data.GetType().GetElementType() != expectedArrayElementType) + { throw new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueElement", _data.GetType(), expectedArrayElementType.MakeArrayType().Name), __HResults.TYPE_E_TYPEMISMATCH); } T[] converted = new T[dataArray.Length]; - if (converted.Length > 0) { - fixed (byte * dataPin = &JitHelpers.GetPinningHelper(dataArray).m_data) { - fixed (byte * convertedPin = &JitHelpers.GetPinningHelper(converted).m_data) { - byte *pData = (byte *)Marshal.UnsafeAddrOfPinnedArrayElement(dataArray, 0); - byte *pConverted = (byte *)Marshal.UnsafeAddrOfPinnedArrayElement(converted, 0); + if (converted.Length > 0) + { + fixed (byte* dataPin = &JitHelpers.GetPinningHelper(dataArray).m_data) + { + fixed (byte* convertedPin = &JitHelpers.GetPinningHelper(converted).m_data) + { + byte* pData = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(dataArray, 0); + byte* pConverted = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(converted, 0); Buffer.Memcpy(pConverted, pData, checked(Marshal.SizeOf(typeof(T)) * converted.Length)); } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs index 9705b61148..3afd87ab12 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs @@ -13,7 +13,7 @@ using System.Security; namespace System.Runtime.InteropServices.WindowsRuntime { - internal sealed class CLRIReferenceImpl<T> : CLRIPropertyValueImpl, IReference<T>, IGetProxyTarget + internal sealed class CLRIReferenceImpl<T> : CLRIPropertyValueImpl, IReference<T>, IGetProxyTarget { private T _value; @@ -24,7 +24,8 @@ namespace System.Runtime.InteropServices.WindowsRuntime _value = obj; } - public T Value { + public T Value + { get { return _value; } } @@ -55,16 +56,16 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal static Object UnboxHelper(Object wrapper) { Contract.Requires(wrapper != null); - IReference<T> reference = (IReference<T>) wrapper; - Debug.Assert(reference != null, "CLRIReferenceImpl::UnboxHelper - QI'ed for IReference<"+typeof(T)+">, but that failed."); + IReference<T> reference = (IReference<T>)wrapper; + Debug.Assert(reference != null, "CLRIReferenceImpl::UnboxHelper - QI'ed for IReference<" + typeof(T) + ">, but that failed."); return reference.Value; } } // T can be any WinRT-compatible type internal sealed class CLRIReferenceArrayImpl<T> : CLRIPropertyValueImpl, - IGetProxyTarget, - IReferenceArray<T>, + IGetProxyTarget, + IReferenceArray<T>, IList // Jupiter data binding needs IList/IEnumerable { private T[] _value; @@ -77,10 +78,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime _value = obj; - _list = (IList) _value; + _list = (IList)_value; } - public T[] Value { + public T[] Value + { get { return _value; } } @@ -109,7 +111,8 @@ namespace System.Runtime.InteropServices.WindowsRuntime // IList & ICollection methods. // This enables two-way data binding and index access in Jupiter // - Object IList.this[int index] { + Object IList.this[int index] + { get { return _list[index]; @@ -120,30 +123,30 @@ namespace System.Runtime.InteropServices.WindowsRuntime _list[index] = value; } } - + int IList.Add(Object value) { return _list.Add(value); } - + bool IList.Contains(Object value) { return _list.Contains(value); } - + void IList.Clear() { _list.Clear(); } - bool IList.IsReadOnly - { + bool IList.IsReadOnly + { get { return _list.IsReadOnly; } } - + bool IList.IsFixedSize { get @@ -156,17 +159,17 @@ namespace System.Runtime.InteropServices.WindowsRuntime { return _list.IndexOf(value); } - + void IList.Insert(int index, Object value) { _list.Insert(index, value); } - + void IList.Remove(Object value) { _list.Remove(value); } - + void IList.RemoveAt(int index) { _list.RemoveAt(index); @@ -176,9 +179,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime { _list.CopyTo(array, index); } - + int ICollection.Count - { + { get { return _list.Count; @@ -186,15 +189,15 @@ namespace System.Runtime.InteropServices.WindowsRuntime } Object ICollection.SyncRoot - { + { get { return _list.SyncRoot; } } - + bool ICollection.IsSynchronized - { + { get { return _list.IsSynchronized; @@ -205,7 +208,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime { return (object)_value; } - + // We have T in an IReferenceArray<T>. Need to QI for IReferenceArray<T> with the appropriate GUID, call // the get_Value property, allocate an appropriately-sized managed object, marshal the native object // to the managed object, and free the native method. @@ -238,7 +241,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime Type type = obj.GetType(); if (type.IsArray) - return CreateIReferenceArray((Array) obj); + return CreateIReferenceArray((Array)obj); if (type == typeof(int)) return new CLRIReferenceImpl<int>(PropertyType.Int32, (int)obj); @@ -313,7 +316,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime Contract.Ensures(Contract.Result<Object>() != null); Type type = obj.GetType().GetElementType(); - + Debug.Assert(obj.Rank == 1 && obj.GetLowerBound(0) == 0 && !type.IsArray); if (type == typeof(int)) diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs index 3a896ecbe3..0e9140f41b 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs @@ -48,9 +48,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime throw new ArgumentNullException(nameof(data)); Contract.EndContractBlock(); - this.firstItemIndex = 0; - this.lastItemIndex = data.Count - 1; - this.items = CreateKeyValueArray(data.Count, data.GetEnumerator()); + firstItemIndex = 0; + lastItemIndex = data.Count - 1; + items = CreateKeyValueArray(data.Count, data.GetEnumerator()); } @@ -61,7 +61,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime this.lastItemIndex = lastItemIndex; } - + private KeyValuePair<TKey, TValue>[] CreateKeyValueArray(Int32 count, IEnumerator<KeyValuePair<TKey, TValue>> data) { KeyValuePair<TKey, TValue>[] kvArray = new KeyValuePair<TKey, TValue>[count]; @@ -76,16 +76,20 @@ namespace System.Runtime.InteropServices.WindowsRuntime } - public int Count { - get { + public int Count + { + get + { return lastItemIndex - firstItemIndex + 1; } } // [CLSCompliant(false)] - public UInt32 Size { - get { + public UInt32 Size + { + get + { return (UInt32)(lastItemIndex - firstItemIndex + 1); } } @@ -118,17 +122,17 @@ namespace System.Runtime.InteropServices.WindowsRuntime { return ((IEnumerable<IKeyValuePair<TKey, TValue>>)this).GetEnumerator(); } - + public IIterator<IKeyValuePair<TKey, TValue>> First() { return new EnumeratorToIteratorAdapter<IKeyValuePair<TKey, TValue>>(GetEnumerator()); } - + public IEnumerator<IKeyValuePair<TKey, TValue>> GetEnumerator() { return new IKeyValuePairEnumerator(items, firstItemIndex, lastItemIndex); } - + public void Split(out IMapView<TKey, TValue> firstPartition, out IMapView<TKey, TValue> secondPartition) { if (Count < 2) @@ -144,7 +148,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime secondPartition = new ConstantSplittableMap<TKey, TValue>(items, pivot + 1, lastItemIndex); } -#region IReadOnlyDictionary members + #region IReadOnlyDictionary members public bool TryGetValue(TKey key, out TValue value) { @@ -197,16 +201,20 @@ namespace System.Runtime.InteropServices.WindowsRuntime return false; } - public IKeyValuePair<TKey, TValue> Current { - get { + public IKeyValuePair<TKey, TValue> Current + { + get + { if (_current < _start) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted)); if (_current > _end) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded)); return new CLRIKeyValuePairImpl<TKey, TValue>(ref _array[_current]); } } - Object IEnumerator.Current { - get { + Object IEnumerator.Current + { + get + { return Current; } } @@ -222,7 +230,5 @@ namespace System.Runtime.InteropServices.WindowsRuntime } #endregion IKeyValuePair Enumerator - } // internal ConstantSplittableMap<TKey, TValue> - } // namespace System.Runtime.InteropServices.WindowsRuntime diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CustomPropertyImpl.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CustomPropertyImpl.cs index 9f822d5ced..fe1ecff161 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CustomPropertyImpl.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CustomPropertyImpl.cs @@ -21,8 +21,8 @@ namespace System.Runtime.InteropServices.WindowsRuntime // ICustomProperty implementation - basically a wrapper of PropertyInfo // internal sealed class CustomPropertyImpl : ICustomProperty - { - private PropertyInfo m_property; + { + private PropertyInfo m_property; // // Constructor @@ -46,11 +46,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime return m_property.Name; } } - + public bool CanRead { - get - { + get + { // Return false if the getter is not public return m_property.GetGetMethod() != null; } @@ -58,7 +58,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public bool CanWrite { - get + get { // Return false if the setter is not public return m_property.GetSetMethod() != null; @@ -105,7 +105,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // We get non-public accessors just so that we can throw the correct exception. MethodInfo accessor = getValue ? m_property.GetGetMethod(true) : m_property.GetSetMethod(true); - + if (accessor == null) throw new ArgumentException(System.Environment.GetResourceString(getValue ? "Arg_GetMethNotFnd" : "Arg_SetMethNotFnd")); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs index c33e002e0e..9f33b2f946 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs @@ -41,11 +41,13 @@ namespace System.Runtime.InteropServices.WindowsRuntime } } - public int Count { + public int Count + { get { return dictionary.Count; } } - bool ICollection<TKey>.IsReadOnly { + bool ICollection<TKey>.IsReadOnly + { get { return true; } } @@ -93,7 +95,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; - this.enumeration = dictionary.GetEnumerator(); + enumeration = dictionary.GetEnumerator(); } void IDisposable.Dispose() @@ -106,11 +108,13 @@ namespace System.Runtime.InteropServices.WindowsRuntime return enumeration.MoveNext(); } - Object IEnumerator.Current { + Object IEnumerator.Current + { get { return ((IEnumerator<TKey>)this).Current; } } - public TKey Current { + public TKey Current + { get { return enumeration.Current.Key; } } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryToMapAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryToMapAdapter.cs index 24e5777768..b1a4042419 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryToMapAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryToMapAdapter.cs @@ -55,7 +55,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime IDictionary<K, V> _this = JitHelpers.UnsafeCast<IDictionary<K, V>>(this); return (uint)_this.Count; } - + // bool HasKey(K key) internal bool HasKey<K, V>(K key) { diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs index fcc7755d67..d599d24aa3 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs @@ -11,7 +11,8 @@ using System.Runtime.InteropServices; using System.Runtime.InteropServices.WindowsRuntime; -namespace System.Runtime.InteropServices.WindowsRuntime { +namespace System.Runtime.InteropServices.WindowsRuntime +{ [Serializable] [DebuggerDisplay("Count = {Count}")] internal sealed class DictionaryValueCollection<TKey, TValue> : ICollection<TValue> @@ -44,11 +45,13 @@ namespace System.Runtime.InteropServices.WindowsRuntime { } } - public int Count { + public int Count + { get { return dictionary.Count; } } - bool ICollection<TValue>.IsReadOnly { + bool ICollection<TValue>.IsReadOnly + { get { return true; } } @@ -100,7 +103,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime { throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; - this.enumeration = dictionary.GetEnumerator(); + enumeration = dictionary.GetEnumerator(); } void IDisposable.Dispose() @@ -113,11 +116,13 @@ namespace System.Runtime.InteropServices.WindowsRuntime { return enumeration.MoveNext(); } - Object IEnumerator.Current { + Object IEnumerator.Current + { get { return ((IEnumerator<TValue>)this).Current; } } - public TValue Current { + public TValue Current + { get { return enumeration.Current.Value; } } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/EnumeratorToIteratorAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/EnumeratorToIteratorAdapter.cs index 3f9d516162..75b8480eeb 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/EnumeratorToIteratorAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/EnumeratorToIteratorAdapter.cs @@ -51,20 +51,20 @@ namespace System.Runtime.InteropServices.WindowsRuntime 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() { } + public void Reset() { enumerator.Reset(); } + public void Dispose() { } } // This method is invoked when First is called on a managed implementation of IBindableIterable. internal IBindableIterator First_Stub() { IEnumerable _this = JitHelpers.UnsafeCast<IEnumerable>(this); - return new EnumeratorToIteratorAdapter<object>(new NonGenericToGenericEnumerator(_this.GetEnumerator()) ); + return new EnumeratorToIteratorAdapter<object>(new NonGenericToGenericEnumerator(_this.GetEnumerator())); } } - + // Adapter class which holds a managed IEnumerator<T>, exposing it as a Windows Runtime IIterator<T> internal sealed class EnumeratorToIteratorAdapter<T> : IIterator<T>, IBindableIterator { diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IClosable.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IClosable.cs index 4c6169a4e8..d62649e7a7 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IClosable.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IClosable.cs @@ -13,7 +13,6 @@ using System.Runtime.CompilerServices; namespace System.Runtime.InteropServices.WindowsRuntime { - // Local definition of Windows.Foundation.IClosable [ComImport] [Guid("30d5a829-7fa4-4026-83bb-d75bae4ea99e")] diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomProperty.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomProperty.cs index 88472a46b8..3ff4ffd098 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomProperty.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomProperty.cs @@ -19,34 +19,34 @@ namespace System.Runtime.InteropServices.WindowsRuntime [Pure] get; } - - string Name - { + + string Name + { [Pure] - get; + get; } [Pure] object GetValue(object target); void SetValue(object target, object value); - + [Pure] object GetValue(object target, object indexValue); - + void SetValue(object target, object value, object indexValue); - - bool CanWrite - { + + bool CanWrite + { [Pure] - get; + get; } - bool CanRead - { + bool CanRead + { [Pure] - get; - } + get; + } } } - + diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomPropertyProvider.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomPropertyProvider.cs index 3bbde35a3c..f461327712 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomPropertyProvider.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomPropertyProvider.cs @@ -16,7 +16,6 @@ using System.Security; namespace System.Runtime.InteropServices.WindowsRuntime { - // // ICustomProperty Implementation helpers // @@ -32,7 +31,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime Contract.Requires(propertyName != null); IGetProxyTarget proxy = target as IGetProxyTarget; - if (proxy != null) + if (proxy != null) target = proxy.GetTarget(); // Only return public instance/static properties @@ -50,7 +49,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Creates a ICustomProperty implementation for Jupiter // Called from ICustomPropertyProvider_GetIndexedProperty from within runtime // - static internal unsafe ICustomProperty CreateIndexedProperty(object target, string propertyName, TypeNameNative *pIndexedParamType) + static internal unsafe ICustomProperty CreateIndexedProperty(object target, string propertyName, TypeNameNative* pIndexedParamType) { Contract.Requires(target != null); Contract.Requires(propertyName != null); @@ -58,7 +57,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime Type indexedParamType = null; SystemTypeMarshaler.ConvertToManaged(pIndexedParamType, ref indexedParamType); - return CreateIndexedProperty(target, propertyName, indexedParamType); + return CreateIndexedProperty(target, propertyName, indexedParamType); } static internal ICustomProperty CreateIndexedProperty(object target, string propertyName, Type indexedParamType) @@ -67,7 +66,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime Contract.Requires(propertyName != null); IGetProxyTarget proxy = target as IGetProxyTarget; - if (proxy != null) + if (proxy != null) target = proxy.GetTarget(); // Only return public instance/static properties @@ -86,25 +85,25 @@ namespace System.Runtime.InteropServices.WindowsRuntime return new CustomPropertyImpl(propertyInfo); } - static internal unsafe void GetType(object target, TypeNameNative *pIndexedParamType) - { + static internal unsafe void GetType(object target, TypeNameNative* pIndexedParamType) + { IGetProxyTarget proxy = target as IGetProxyTarget; - if (proxy != null) + if (proxy != null) target = proxy.GetTarget(); SystemTypeMarshaler.ConvertToNative(target.GetType(), pIndexedParamType); - } + } } [Flags] - enum InterfaceForwardingSupport + internal enum InterfaceForwardingSupport { - None = 0, - IBindableVector = 0x1, // IBindableVector -> IBindableVector - IVector = 0x2, // IBindableVector -> IVector<T> - IBindableVectorView = 0x4, // IBindableVectorView -> IBindableVectorView - IVectorView = 0x8, // IBindableVectorView -> IVectorView<T> - IBindableIterableOrIIterable= 0x10 // IBindableIterable -> IBindableIterable/IIterable<T> + None = 0, + IBindableVector = 0x1, // IBindableVector -> IBindableVector + IVector = 0x2, // IBindableVector -> IVector<T> + IBindableVectorView = 0x4, // IBindableVectorView -> IBindableVectorView + IVectorView = 0x8, // IBindableVectorView -> IVectorView<T> + IBindableIterableOrIIterable = 0x10 // IBindableIterable -> IBindableIterable/IIterable<T> } // @@ -113,9 +112,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime // internal interface IGetProxyTarget { - object GetTarget(); + object GetTarget(); } - + // // Proxy that supports data binding on another object // @@ -164,7 +163,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // doesn't recognize, and therefore IEnumerable cast won't be able to take advantage of this QI if (target as IList<T1> != null) supportFlags |= InterfaceForwardingSupport.IVector; - + if (target as IBindableVectorView != null) supportFlags |= InterfaceForwardingSupport.IBindableVectorView; @@ -181,8 +180,8 @@ namespace System.Runtime.InteropServices.WindowsRuntime // succeeded, IEnumerable needs to know that if (target as IEnumerable != null) supportFlags |= InterfaceForwardingSupport.IBindableIterableOrIIterable; - - return new ICustomPropertyProviderProxy<T1, T2>(target, supportFlags); + + return new ICustomPropertyProviderProxy<T1, T2>(target, supportFlags); } @@ -213,26 +212,26 @@ namespace System.Runtime.InteropServices.WindowsRuntime { // Reject the QI if target doesn't implement IEnumerable if ((_flags & (InterfaceForwardingSupport.IBindableIterableOrIIterable)) == 0) - return CustomQueryInterfaceResult.Failed; + return CustomQueryInterfaceResult.Failed; } if (iid == typeof(IBindableVector).GUID) { // Reject the QI if target doesn't implement IBindableVector/IVector if ((_flags & (InterfaceForwardingSupport.IBindableVector | InterfaceForwardingSupport.IVector)) == 0) - return CustomQueryInterfaceResult.Failed; + return CustomQueryInterfaceResult.Failed; } if (iid == typeof(IBindableVectorView).GUID) { // Reject the QI if target doesn't implement IBindableVectorView/IVectorView if ((_flags & (InterfaceForwardingSupport.IBindableVectorView | InterfaceForwardingSupport.IVectorView)) == 0) - return CustomQueryInterfaceResult.Failed; + return CustomQueryInterfaceResult.Failed; } - + return CustomQueryInterfaceResult.NotHandled; } - + // // IEnumerable methods // @@ -257,14 +256,14 @@ namespace System.Runtime.InteropServices.WindowsRuntime { // IBindableVector -> IVector<T> return GetVectorOfT().GetAt(index); - } + } } - + [Pure] - uint IBindableVector.Size - { + uint IBindableVector.Size + { get - { + { IBindableVector bindableVector = GetIBindableVectorNoThrow(); if (bindableVector != null) { @@ -275,10 +274,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime { // IBindableVector -> IVector<T> return GetVectorOfT().Size; - } + } } } - + [Pure] IBindableVectorView IBindableVector.GetView() { @@ -292,7 +291,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime { // IBindableVector -> IVector<T> return new IVectorViewToIBindableVectorViewAdapter<T1>(GetVectorOfT().GetView()); - } + } } private sealed class IVectorViewToIBindableVectorViewAdapter<T> : IBindableVectorView @@ -300,8 +299,8 @@ namespace System.Runtime.InteropServices.WindowsRuntime private IVectorView<T> _vectorView; public IVectorViewToIBindableVectorViewAdapter(IVectorView<T> vectorView) - { - this._vectorView = vectorView; + { + _vectorView = vectorView; } [Pure] @@ -309,16 +308,16 @@ namespace System.Runtime.InteropServices.WindowsRuntime { return _vectorView.GetAt(index); } - + [Pure] uint IBindableVectorView.Size - { + { get { return _vectorView.Size; } } - + [Pure] bool IBindableVectorView.IndexOf(object value, out uint index) { @@ -329,9 +328,8 @@ namespace System.Runtime.InteropServices.WindowsRuntime { return new IteratorOfTToIteratorAdapter<T>(_vectorView.First()); } + } - } - [Pure] bool IBindableVector.IndexOf(object value, out uint index) { @@ -345,9 +343,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime { // IBindableVector -> IVector<T> return GetVectorOfT().IndexOf(ConvertTo<T1>(value), out index); - } + } } - + void IBindableVector.SetAt(uint index, object value) { IBindableVector bindableVector = GetIBindableVectorNoThrow(); @@ -360,9 +358,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime { // IBindableVector -> IVector<T> GetVectorOfT().SetAt(index, ConvertTo<T1>(value)); - } + } } - + void IBindableVector.InsertAt(uint index, object value) { IBindableVector bindableVector = GetIBindableVectorNoThrow(); @@ -375,9 +373,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime { // IBindableVector -> IVector<T> GetVectorOfT().InsertAt(index, ConvertTo<T1>(value)); - } + } } - + void IBindableVector.RemoveAt(uint index) { IBindableVector bindableVector = GetIBindableVectorNoThrow(); @@ -390,9 +388,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime { // IBindableVector -> IVector<T> GetVectorOfT().RemoveAt(index); - } + } } - + void IBindableVector.Append(object value) { IBindableVector bindableVector = GetIBindableVectorNoThrow(); @@ -405,9 +403,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime { // IBindableVector -> IVector<T> GetVectorOfT().Append(ConvertTo<T1>(value)); - } - } - + } + } + void IBindableVector.RemoveAtEnd() { IBindableVector bindableVector = GetIBindableVectorNoThrow(); @@ -420,9 +418,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime { // IBindableVector -> IVector<T> GetVectorOfT().RemoveAtEnd(); - } + } } - + void IBindableVector.Clear() { IBindableVector bindableVector = GetIBindableVectorNoThrow(); @@ -435,7 +433,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime { // IBindableVector -> IVector<T> GetVectorOfT().Clear(); - } + } } private IBindableVector GetIBindableVectorNoThrow() @@ -454,7 +452,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime throw new InvalidOperationException(); // We should not go down this path, unless Jupiter pass this out to managed code // and managed code use reflection to do the cast } - + // // IBindableVectorView implementation (forwarding to IBindableVectorView or IVectorView<T>) // @@ -467,10 +465,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime else return GetVectorViewOfT().GetAt(index); } - + [Pure] uint IBindableVectorView.Size - { + { get { IBindableVectorView bindableVectorView = GetIBindableVectorViewNoThrow(); @@ -480,7 +478,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime return GetVectorViewOfT().Size; } } - + [Pure] bool IBindableVectorView.IndexOf(object value, out uint index) { @@ -505,12 +503,12 @@ namespace System.Runtime.InteropServices.WindowsRuntime private IIterator<T> _iterator; public IteratorOfTToIteratorAdapter(IIterator<T> iterator) - { this._iterator = iterator; } + { _iterator = iterator; } public bool HasCurrent { get { return _iterator.HasCurrent; } } - public object Current { get { return (object)_iterator.Current; } } + public object Current { get { return (object)_iterator.Current; } } public bool MoveNext() { return _iterator.MoveNext(); } - } + } private IBindableVectorView GetIBindableVectorViewNoThrow() { @@ -537,9 +535,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Throw ArgumentNullException if value is null (otherwise we'll throw NullReferenceException // when casting value to T) ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(value, ExceptionArgument.value); - + // No coersion support needed. If we need coersion later, this is the place - return (T) value; + return (T)value; } } } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IIterable.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IIterable.cs index dbf4771cf6..30ce895423 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IIterable.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IIterable.cs @@ -10,6 +10,7 @@ using System.Diagnostics.Contracts; // Windows.Foundation.Collections.IIterable`1 cannot be referenced from managed code because it's hidden // by the metadata adapter. We redeclare the interface manually to be able to talk to native WinRT objects. + namespace System.Runtime.InteropServices.WindowsRuntime { [ComImport] diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IMap.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IMap.cs index 8160e6afc9..1f954a66b0 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IMap.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IMap.cs @@ -11,6 +11,7 @@ using System.Diagnostics.Contracts; // Windows.Foundation.Collections.IMap`2, IMapView`2, and IKeyValuePair`2 cannot be referenced from // managed code because they're hidden by the metadata adapter. We redeclare the interfaces manually // to be able to talk to native WinRT objects. + namespace System.Runtime.InteropServices.WindowsRuntime { [ComImport] diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs index a7424da3fb..55f8a1e862 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs @@ -190,7 +190,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; - this.enumeration = dictionary.GetEnumerator(); + enumeration = dictionary.GetEnumerator(); } void IDisposable.Dispose() @@ -203,11 +203,13 @@ namespace System.Runtime.InteropServices.WindowsRuntime return enumeration.MoveNext(); } - Object IEnumerator.Current { + Object IEnumerator.Current + { get { return ((IEnumerator<TKey>)this).Current; } } - public TKey Current { + public TKey Current + { get { return enumeration.Current.Key; } } @@ -289,7 +291,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; - this.enumeration = dictionary.GetEnumerator(); + enumeration = dictionary.GetEnumerator(); } void IDisposable.Dispose() @@ -302,11 +304,13 @@ namespace System.Runtime.InteropServices.WindowsRuntime return enumeration.MoveNext(); } - Object IEnumerator.Current { + Object IEnumerator.Current + { get { return ((IEnumerator<TValue>)this).Current; } } - public TValue Current { + public TValue Current + { get { return enumeration.Current.Value; } } @@ -315,5 +319,4 @@ namespace System.Runtime.InteropServices.WindowsRuntime enumeration = dictionary.GetEnumerator(); } } // class ReadOnlyDictionaryValueEnumerator<TKey, TValue> - } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IPropertyValue.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IPropertyValue.cs index 4065406dfa..a2b07b2ea7 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IPropertyValue.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IPropertyValue.cs @@ -139,27 +139,25 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // Specify size directly instead of fields to avoid warnings - [StructLayoutAttribute(LayoutKind.Sequential, Size=8)] + [StructLayoutAttribute(LayoutKind.Sequential, Size = 8)] [WindowsRuntimeImport] internal struct Point { - // float X; // float Y; } // Specify size directly instead of fields to avoid warnings - [StructLayoutAttribute(LayoutKind.Sequential, Size=8)] + [StructLayoutAttribute(LayoutKind.Sequential, Size = 8)] [WindowsRuntimeImport] internal struct Size { - // float Width; // float Height; } // Specify size directly instead of fields to avoid warnings - [StructLayoutAttribute(LayoutKind.Sequential, Size=16)] + [StructLayoutAttribute(LayoutKind.Sequential, Size = 16)] [WindowsRuntimeImport] internal struct Rect { @@ -167,5 +165,5 @@ namespace System.Runtime.InteropServices.WindowsRuntime // float Y; // float Width; // float Height; - } + } } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyDictionaryToIMapViewAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyDictionaryToIMapViewAdapter.cs index b185b41be0..2fac36b23f 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyDictionaryToIMapViewAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyDictionaryToIMapViewAdapter.cs @@ -54,7 +54,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime IReadOnlyDictionary<K, V> _this = JitHelpers.UnsafeCast<IReadOnlyDictionary<K, V>>(this); return (uint)_this.Count; } - + // bool HasKey(K key) internal bool HasKey<K, V>(K key) { @@ -67,7 +67,8 @@ namespace System.Runtime.InteropServices.WindowsRuntime { IReadOnlyDictionary<K, V> _this = JitHelpers.UnsafeCast<IReadOnlyDictionary<K, V>>(this); - if (_this.Count < 2) { + if (_this.Count < 2) + { first = null; second = null; return; diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyListToIVectorViewAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyListToIVectorViewAdapter.cs index 431d16256e..b902ded9c0 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyListToIVectorViewAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyListToIVectorViewAdapter.cs @@ -35,11 +35,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal T GetAt<T>(uint index) { IReadOnlyList<T> _this = JitHelpers.UnsafeCast<IReadOnlyList<T>>(this); - EnsureIndexInt32(index, _this.Count); + EnsureIndexInt32(index, _this.Count); try { - return _this[(int) index]; + return _this[(int)index]; } catch (ArgumentOutOfRangeException ex) { diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IVector.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IVector.cs index 6982911a13..e88f4f3b9f 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IVector.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IVector.cs @@ -11,6 +11,7 @@ using System.Diagnostics.Contracts; // Windows.Foundation.Collections.IVector`1 and IVectorView`1 cannot be referenced from managed // code because they're hidden by the metadata adapter. We redeclare the interfaces manually // to be able to talk to native WinRT objects. + namespace System.Runtime.InteropServices.WindowsRuntime { [ComImport] diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IVectorViewToIReadOnlyListAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IVectorViewToIReadOnlyListAdapter.cs index 37f21307dc..76b0fff00d 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IVectorViewToIReadOnlyListAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IVectorViewToIReadOnlyListAdapter.cs @@ -43,7 +43,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime try { - return _this.GetAt((uint) index); + return _this.GetAt((uint)index); // We delegate bounds checking to the underlying collection and if it detected a fault, // we translate it to the right exception: @@ -62,15 +62,15 @@ namespace System.Runtime.InteropServices.WindowsRuntime { bool fUseString; Delegate target = System.StubHelpers.StubHelpers.GetTargetForAmbiguousVariantCall( - this, - typeof(IReadOnlyList<T>).TypeHandle.Value, + this, + typeof(IReadOnlyList<T>).TypeHandle.Value, out fUseString); if (target != null) { return (JitHelpers.UnsafeCast<Indexer_Get_Delegate<T>>(target))(index); } - + if (fUseString) { return JitHelpers.UnsafeCast<T>(Indexer_Get<string>(index)); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IteratorToEnumeratorAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IteratorToEnumeratorAdapter.cs index e219a86769..417476dbbe 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IteratorToEnumeratorAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IteratorToEnumeratorAdapter.cs @@ -31,7 +31,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime { Debug.Assert(false, "This class is never instantiated"); } - + // This method is invoked when GetEnumerator is called on a WinRT-backed implementation of IEnumerable<T>. internal IEnumerator<T> GetEnumerator_Stub<T>() { @@ -55,7 +55,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime { return (JitHelpers.UnsafeCast<GetEnumerator_Delegate<T>>(target))(); } - + if (fUseString) { return JitHelpers.UnsafeCast<IEnumerator<T>>(GetEnumerator_Stub<string>()); @@ -79,7 +79,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime 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(); } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs index b9fe11557d..6010eec6c8 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs @@ -36,7 +36,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal object GetAt(uint index) { IList _this = JitHelpers.UnsafeCast<IList>(this); - EnsureIndexInt32(index, _this.Count); + EnsureIndexInt32(index, _this.Count); try { @@ -119,7 +119,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal void RemoveAt(uint index) { IList _this = JitHelpers.UnsafeCast<IList>(this); - EnsureIndexInt32(index, _this.Count); + EnsureIndexInt32(index, _this.Count); try { diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorViewAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorViewAdapter.cs index 2e2ea9b876..0503b726dd 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorViewAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorViewAdapter.cs @@ -61,7 +61,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime try { return list[(int)index]; - } catch (ArgumentOutOfRangeException ex) { diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToVectorAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToVectorAdapter.cs index b73f4d7a99..8373885284 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToVectorAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToVectorAdapter.cs @@ -36,7 +36,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal T GetAt<T>(uint index) { IList<T> _this = JitHelpers.UnsafeCast<IList<T>>(this); - EnsureIndexInt32(index, _this.Count); + EnsureIndexInt32(index, _this.Count); try { @@ -128,7 +128,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal void RemoveAt<T>(uint index) { IList<T> _this = JitHelpers.UnsafeCast<IList<T>>(this); - EnsureIndexInt32(index, _this.Count); + EnsureIndexInt32(index, _this.Count); try { diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ManagedActivationFactory.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ManagedActivationFactory.cs index 2d08cab0ee..cace2047d9 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ManagedActivationFactory.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ManagedActivationFactory.cs @@ -42,7 +42,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // with at least one ActivatableAttribute or StaticAttribute. if (!(type is RuntimeType) || !type.IsExportedToWindowsRuntime) throw new ArgumentException(Environment.GetResourceString("Argument_TypeNotActivatableViaWindowsRuntime", type), nameof(type)); - + m_type = type; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs index 981972ca9f..a8a13c6912 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs @@ -110,7 +110,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime { _this.Remove(key); return true; - } catch (Exception ex) { @@ -158,7 +157,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime } catch (Exception ex) { - if (__HResults.E_BOUNDS == ex._HResult) throw new KeyNotFoundException(Environment.GetResourceString("Arg_KeyNotFound")); throw; diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/NativeMethods.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/NativeMethods.cs index 627de8d400..ccae412987 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/NativeMethods.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/NativeMethods.cs @@ -38,14 +38,14 @@ namespace System.Runtime.InteropServices.WindowsRuntime [SuppressUnmanagedCodeSecurity] internal static unsafe extern int WindowsCreateString([MarshalAs(UnmanagedType.LPWStr)] string sourceString, int length, - [Out] IntPtr *hstring); + [Out] IntPtr* hstring); [DllImport("api-ms-win-core-winrt-string-l1-1-0.dll", CallingConvention = CallingConvention.StdCall)] [SuppressUnmanagedCodeSecurity] - internal static unsafe extern int WindowsCreateStringReference(char *sourceString, + internal static unsafe extern int WindowsCreateStringReference(char* sourceString, int length, - [Out] HSTRING_HEADER *hstringHeader, - [Out] IntPtr *hstring); + [Out] HSTRING_HEADER* hstringHeader, + [Out] IntPtr* hstring); [DllImport("api-ms-win-core-winrt-string-l1-1-0.dll", CallingConvention = CallingConvention.StdCall)] [SuppressUnmanagedCodeSecurity] @@ -53,6 +53,6 @@ namespace System.Runtime.InteropServices.WindowsRuntime [DllImport("api-ms-win-core-winrt-string-l1-1-0.dll", CallingConvention = CallingConvention.StdCall)] [SuppressUnmanagedCodeSecurity] - internal static unsafe extern char* WindowsGetStringRawBuffer(IntPtr hstring, [Out] uint *length); + internal static unsafe extern char* WindowsGetStringRawBuffer(IntPtr hstring, [Out] uint* length); } } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/PropertyValue.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/PropertyValue.cs index ad64c9917f..8a3e2066cf 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/PropertyValue.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/PropertyValue.cs @@ -17,20 +17,20 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal enum PropertyType { // WARNING: These values have to match enum Windows.Foundation.PropertyType !!! - Empty = 0, - UInt8 = 1, + Empty = 0, + UInt8 = 1, Int16 = 2, UInt16 = 3, - Int32 = 4, - UInt32 = 5, - Int64 = 6, - UInt64 = 7, - Single = 8, - Double = 9, - Char16 = 10, - Boolean = 11, - String = 12, - Inspectable = 13, + Int32 = 4, + UInt32 = 5, + Int64 = 6, + UInt64 = 7, + Single = 8, + Double = 9, + Char16 = 10, + Boolean = 11, + String = 12, + Inspectable = 13, DateTime = 14, TimeSpan = 15, Guid = 16, diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/RuntimeClass.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/RuntimeClass.cs index cd3c53ab4e..fdc0d22632 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/RuntimeClass.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/RuntimeClass.cs @@ -10,15 +10,15 @@ ** ** ===========================================================*/ -namespace System.Runtime.InteropServices.WindowsRuntime { - - using System; - using System.Runtime.InteropServices; - using System.Runtime.InteropServices.WindowsRuntime; - using System.Runtime.CompilerServices; - using System.Security; +using System; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.WindowsRuntime; +using System.Runtime.CompilerServices; +using System.Security; +namespace System.Runtime.InteropServices.WindowsRuntime +{ // Local definition of Windows.Foundation.IStringable [ComImport] [Guid("96369f54-8eb6-48f0-abce-c1b211e627c3")] @@ -33,7 +33,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime { internal static string ToString(object obj) { IGetProxyTarget proxy = obj as IGetProxyTarget; - if (proxy != null) + if (proxy != null) obj = proxy.GetTarget(); // Check whether the type implements IStringable. @@ -41,12 +41,12 @@ namespace System.Runtime.InteropServices.WindowsRuntime { if (stringableType != null) { return stringableType.ToString(); - } - + } + return obj.ToString(); - } + } } - + // // Base class for every WinRT class // We'll make it a ComImport and WindowsRuntimeImport in the type loader @@ -57,11 +57,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime { // // Support for ToString/GetHashCode/Equals override // - [MethodImpl(MethodImplOptions.InternalCall)] - internal extern IntPtr GetRedirectedGetHashCodeMD(); - - [MethodImpl(MethodImplOptions.InternalCall)] - internal extern int RedirectGetHashCode(IntPtr pMD); + [MethodImpl(MethodImplOptions.InternalCall)] + internal extern IntPtr GetRedirectedGetHashCodeMD(); + + [MethodImpl(MethodImplOptions.InternalCall)] + internal extern int RedirectGetHashCode(IntPtr pMD); public override int GetHashCode() { @@ -71,10 +71,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime { return RedirectGetHashCode(pMD); } - [MethodImpl(MethodImplOptions.InternalCall)] - internal extern IntPtr GetRedirectedToStringMD(); + [MethodImpl(MethodImplOptions.InternalCall)] + internal extern IntPtr GetRedirectedToStringMD(); - [MethodImpl(MethodImplOptions.InternalCall)] + [MethodImpl(MethodImplOptions.InternalCall)] internal extern string RedirectToString(IntPtr pMD); public override string ToString() @@ -96,11 +96,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime { } } - [MethodImpl(MethodImplOptions.InternalCall)] - internal extern IntPtr GetRedirectedEqualsMD(); + [MethodImpl(MethodImplOptions.InternalCall)] + internal extern IntPtr GetRedirectedEqualsMD(); - [MethodImpl(MethodImplOptions.InternalCall)] - internal extern bool RedirectEquals(object obj, IntPtr pMD); + [MethodImpl(MethodImplOptions.InternalCall)] + internal extern bool RedirectEquals(object obj, IntPtr pMD); public override bool Equals(object obj) { diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeBufferHelper.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeBufferHelper.cs index 551ee65153..55c356de93 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeBufferHelper.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeBufferHelper.cs @@ -9,29 +9,26 @@ using System.Security; using System.Threading; -namespace System.Runtime.InteropServices.WindowsRuntime { - -/// <summary> -/// Exposes a helper method that allows <code>WindowsRuntimeBuffer : IBuffer, IBufferInternal</code> which is implemented in -/// <code>System.Runtime.WindowsRuntime.dll</code> to call into the VM. -/// </summary> -[FriendAccessAllowed] -internal static class WindowsRuntimeBufferHelper { - - - [DllImport(JitHelpers.QCall)] - [SuppressUnmanagedCodeSecurity] - private unsafe extern static void StoreOverlappedPtrInCCW(ObjectHandleOnStack windowsRuntimeBuffer, NativeOverlapped* overlapped); - - +namespace System.Runtime.InteropServices.WindowsRuntime +{ + /// <summary> + /// Exposes a helper method that allows <code>WindowsRuntimeBuffer : IBuffer, IBufferInternal</code> which is implemented in + /// <code>System.Runtime.WindowsRuntime.dll</code> to call into the VM. + /// </summary> [FriendAccessAllowed] - internal unsafe static void StoreOverlappedInCCW(Object windowsRuntimeBuffer, NativeOverlapped* overlapped) { - - StoreOverlappedPtrInCCW(JitHelpers.GetObjectHandleOnStack(ref windowsRuntimeBuffer), overlapped); - } - -} // class WindowsRuntimeBufferHelper - + internal static class WindowsRuntimeBufferHelper + { + [DllImport(JitHelpers.QCall)] + [SuppressUnmanagedCodeSecurity] + private unsafe extern static void StoreOverlappedPtrInCCW(ObjectHandleOnStack windowsRuntimeBuffer, NativeOverlapped* overlapped); + + + [FriendAccessAllowed] + internal unsafe static void StoreOverlappedInCCW(Object windowsRuntimeBuffer, NativeOverlapped* overlapped) + { + StoreOverlappedPtrInCCW(JitHelpers.GetObjectHandleOnStack(ref windowsRuntimeBuffer), overlapped); + } + } // class WindowsRuntimeBufferHelper } // namespace // WindowsRuntimeBufferHelper.cs diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMarshal.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMarshal.cs index 57655ec861..c9824af17e 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMarshal.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMarshal.cs @@ -75,9 +75,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime if (target == null || Marshal.IsComObject(target)) NativeOrStaticEventRegistrationImpl.RemoveEventHandler<T>(removeMethod, handler); else - ManagedEventRegistrationImpl.RemoveEventHandler<T>(removeMethod, handler); + ManagedEventRegistrationImpl.RemoveEventHandler<T>(removeMethod, handler); } - + public static void RemoveAllEventHandlers(Action<EventRegistrationToken> removeMethod) { if (removeMethod == null) @@ -108,7 +108,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime count += ManagedEventRegistrationImpl.s_eventRegistrations.Keys.Count; } } - + if (NativeOrStaticEventRegistrationImpl.s_eventRegistrations != null) { lock (NativeOrStaticEventRegistrationImpl.s_eventRegistrations) @@ -116,7 +116,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime count += NativeOrStaticEventRegistrationImpl.s_eventRegistrations.Count; } } - + return count; } @@ -124,11 +124,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Optimized version of List of EventRegistrationToken // It is made a struct to reduce overhead // - internal struct EventRegistrationTokenList + 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 EventRegistrationToken firstToken; // Optimization for common case where there is only one token + private List<EventRegistrationToken> restTokens; // Rest of the tokens + internal EventRegistrationTokenList(EventRegistrationToken token) { firstToken = token; @@ -141,18 +141,18 @@ namespace System.Runtime.InteropServices.WindowsRuntime public bool Push(EventRegistrationToken token) { bool needCopy = false; - + if (restTokens == null) { restTokens = new List<EventRegistrationToken>(); needCopy = true; } - + restTokens.Add(token); return needCopy; } - + // Pops the last token // Returns false if no more tokens left, true otherwise public bool Pop(out EventRegistrationToken token) @@ -163,14 +163,14 @@ namespace System.Runtime.InteropServices.WindowsRuntime token = firstToken; return false; } - + int last = restTokens.Count - 1; token = restTokens[last]; restTokens.RemoveAt(last); - + return true; } - + public void CopyTo(List<EventRegistrationToken> tokens) { tokens.Add(firstToken); @@ -183,7 +183,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Event registration support for managed objects events & static events // internal static class ManagedEventRegistrationImpl - { + { // Mappings of delegates registered for events -> their registration tokens. // These mappings are stored indexed by the remove method which can be used to undo the registrations. // @@ -208,10 +208,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime // If the delegates aren't alive, it means either they have been unsubscribed, or the object itself is gone, // and in either case, they've been already taken care of. // - internal volatile static - ConditionalWeakTable<object, Dictionary<MethodInfo, Dictionary<object, EventRegistrationTokenList>>> s_eventRegistrations = + internal volatile static + ConditionalWeakTable<object, Dictionary<MethodInfo, Dictionary<object, EventRegistrationTokenList>>> s_eventRegistrations = new ConditionalWeakTable<object, Dictionary<MethodInfo, Dictionary<object, EventRegistrationTokenList>>>(); - + internal static void AddEventHandler<T>(Func<T, EventRegistrationToken> addMethod, Action<EventRegistrationToken> removeMethod, T handler) @@ -239,18 +239,18 @@ namespace System.Runtime.InteropServices.WindowsRuntime if (needCopy) registrationTokens[handler] = tokens; } - + BCLDebug.Log("INTEROP", "[WinRT_Eventing] Event subscribed for managed instance = " + instance + ", handler = " + handler + "\n"); } } - + // Get the event registration token table for an event. These are indexed by the remove method of the event. private static Dictionary<object, EventRegistrationTokenList> GetEventRegistrationTokenTable(object instance, Action<EventRegistrationToken> removeMethod) { Contract.Requires(instance != null); Contract.Requires(removeMethod != null); - Contract.Requires(s_eventRegistrations != null); - + Contract.Requires(s_eventRegistrations != null); + lock (s_eventRegistrations) { Dictionary<MethodInfo, Dictionary<object, EventRegistrationTokenList>> instanceMap = null; @@ -259,14 +259,14 @@ namespace System.Runtime.InteropServices.WindowsRuntime instanceMap = new Dictionary<MethodInfo, Dictionary<object, EventRegistrationTokenList>>(); s_eventRegistrations.Add(instance, instanceMap); } - + Dictionary<object, EventRegistrationTokenList> tokens = null; if (!instanceMap.TryGetValue(removeMethod.Method, out tokens)) { tokens = new Dictionary<object, EventRegistrationTokenList>(); instanceMap.Add(removeMethod.Method, tokens); } - + return tokens; } } @@ -278,19 +278,19 @@ namespace System.Runtime.InteropServices.WindowsRuntime object instance = removeMethod.Target; Dictionary<object, EventRegistrationTokenList> registrationTokens = GetEventRegistrationTokenTable(instance, removeMethod); EventRegistrationToken token; - + lock (registrationTokens) { EventRegistrationTokenList tokens; - + // Failure to find a registration for a token is not an error - it's simply a no-op. if (!registrationTokens.TryGetValue(handler, out tokens)) { - BCLDebug.Log("INTEROP", "[WinRT_Eventing] no registrationTokens found for instance=" + instance + ", handler= " + handler + "\n"); - + BCLDebug.Log("INTEROP", "[WinRT_Eventing] no registrationTokens found for instance=" + instance + ", handler= " + handler + "\n"); + return; } - + // Select a registration token to unregister // We don't care which one but I'm returning the last registered token to be consistent // with native event registration implementation @@ -306,23 +306,23 @@ namespace System.Runtime.InteropServices.WindowsRuntime registrationTokens.Remove(handler); } } - + removeMethod(token); - BCLDebug.Log("INTEROP", "[WinRT_Eventing] Event unsubscribed for managed instance = " + instance + ", handler = " + handler + ", token = " + token.m_value + "\n"); + BCLDebug.Log("INTEROP", "[WinRT_Eventing] Event unsubscribed for managed instance = " + instance + ", handler = " + handler + ", token = " + token.m_value + "\n"); } internal static void RemoveAllEventHandlers(Action<EventRegistrationToken> removeMethod) { - Contract.Requires(removeMethod != null); + Contract.Requires(removeMethod != null); object instance = removeMethod.Target; Dictionary<object, EventRegistrationTokenList> registrationTokens = GetEventRegistrationTokenTable(instance, removeMethod); List<EventRegistrationToken> tokensToRemove = new List<EventRegistrationToken>(); - + lock (registrationTokens) - { + { // Copy all tokens to tokensToRemove array which later we'll call removeMethod on // outside this lock foreach (EventRegistrationTokenList tokens in registrationTokens.Values) @@ -339,9 +339,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime // // Remove all handlers outside the lock // - BCLDebug.Log("INTEROP", "[WinRT_Eventing] Start removing all events for instance = " + instance + "\n"); + BCLDebug.Log("INTEROP", "[WinRT_Eventing] Start removing all events for instance = " + instance + "\n"); CallRemoveMethods(removeMethod, tokensToRemove); - BCLDebug.Log("INTEROP", "[WinRT_Eventing] Finished removing all events for instance = " + instance + "\n"); + BCLDebug.Log("INTEROP", "[WinRT_Eventing] Finished removing all events for instance = " + instance + "\n"); } } @@ -349,15 +349,15 @@ namespace System.Runtime.InteropServices.WindowsRuntime // WinRT event registration implementation code // internal static class NativeOrStaticEventRegistrationImpl - { + { // // Key = (target object, event) // We use a key of object+event to save an extra dictionary // internal struct EventCacheKey { - internal object target; - internal MethodInfo method; + internal object target; + internal MethodInfo method; public override string ToString() { @@ -377,7 +377,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime return key.target.GetHashCode() ^ key.method.GetHashCode(); } } - + // // EventRegistrationTokenListWithCount // @@ -390,9 +390,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime // internal class EventRegistrationTokenListWithCount { - private TokenListCount _tokenListCount; - EventRegistrationTokenList _tokenList; - + private TokenListCount _tokenListCount; + private EventRegistrationTokenList _tokenList; + internal EventRegistrationTokenListWithCount(TokenListCount tokenListCount, EventRegistrationToken token) { _tokenListCount = tokenListCount; @@ -400,30 +400,30 @@ namespace System.Runtime.InteropServices.WindowsRuntime _tokenList = new EventRegistrationTokenList(token); } - + ~EventRegistrationTokenListWithCount() - { + { // Decrement token list count // This is need to correctly keep trace of number of tokens for EventCacheKey // and remove it from cache when the token count drop to 0 // we don't need to take locks for decrement the count - we only need to take a global // lock when we decide to destroy cache for the IUnknown */type instance - BCLDebug.Log("INTEROP", "[WinRT_Eventing] Finalizing EventRegistrationTokenList for " + _tokenListCount.Key + "\n"); + BCLDebug.Log("INTEROP", "[WinRT_Eventing] Finalizing EventRegistrationTokenList for " + _tokenListCount.Key + "\n"); _tokenListCount.Dec(); } - + public void Push(EventRegistrationToken token) { // Since EventRegistrationTokenListWithCount is a reference type, there is no need // to copy back. Ignore the return value _tokenList.Push(token); } - + public bool Pop(out EventRegistrationToken token) { return _tokenList.Pop(out token); } - + public void CopyTo(List<EventRegistrationToken> tokens) { _tokenList.CopyTo(tokens); @@ -438,8 +438,8 @@ namespace System.Runtime.InteropServices.WindowsRuntime // internal class TokenListCount { - private int _count; - private EventCacheKey _key; + private int _count; + private EventCacheKey _key; internal TokenListCount(EventCacheKey key) { @@ -448,14 +448,13 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal EventCacheKey Key { - get { return _key; } } - + internal void Inc() { int newCount = Interlocked.Increment(ref _count); - BCLDebug.Log("INTEROP", "[WinRT_Eventing] Incremented TokenListCount for " + _key + ", Value = " + newCount + "\n"); + BCLDebug.Log("INTEROP", "[WinRT_Eventing] Incremented TokenListCount for " + _key + ", Value = " + newCount + "\n"); } internal void Dec() @@ -466,7 +465,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime try { int newCount = Interlocked.Decrement(ref _count); - BCLDebug.Log("INTEROP", "[WinRT_Eventing] Decremented TokenListCount for " + _key + ", Value = " + newCount + "\n"); + BCLDebug.Log("INTEROP", "[WinRT_Eventing] Decremented TokenListCount for " + _key + ", Value = " + newCount + "\n"); if (newCount == 0) CleanupCache(); } @@ -482,7 +481,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // because the total token list count has dropped to 0 and we don't have any events subscribed Contract.Requires(s_eventRegistrations != null); - BCLDebug.Log("INTEROP", "[WinRT_Eventing] Removing " + _key + " from cache" + "\n"); + BCLDebug.Log("INTEROP", "[WinRT_Eventing] Removing " + _key + " from cache" + "\n"); s_eventRegistrations.Remove(_key); BCLDebug.Log("INTEROP", "[WinRT_Eventing] s_eventRegistrations size = " + s_eventRegistrations.Count + "\n"); } @@ -520,7 +519,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // b. The same delegate is subscribed then unsubscribed. We need to make sure give // them the latest token in this case. This is guaranteed by always giving the last token and always use equality to // add/remove event handlers - internal volatile static Dictionary<EventCacheKey, EventCacheEntry> s_eventRegistrations = + internal volatile static Dictionary<EventCacheKey, EventCacheEntry> s_eventRegistrations = new Dictionary<EventCacheKey, EventCacheEntry>(new EventCacheKeyEqualityComparer()); // Prevent add/remove handler code to run at the same with with cache cleanup code @@ -533,11 +532,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime Debug.Assert(target == null || Marshal.IsComObject(target), "Must be null or a RCW"); if (target == null) return removeMethod.Method.DeclaringType; - + // Need the "Raw" IUnknown pointer for the RCW that is not bound to the current context - return (object) Marshal.GetRawIUnknownForComObjectNoAddRef(target); + return (object)Marshal.GetRawIUnknownForComObjectNoAddRef(target); } - + internal static void AddEventHandler<T>(Func<T, EventRegistrationToken> addMethod, Action<EventRegistrationToken> removeMethod, T handler) @@ -552,11 +551,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime EventRegistrationToken token = addMethod(handler); bool tokenAdded = false; - + try { EventRegistrationTokenListWithCount tokens; - + // // The whole add/remove code has to be protected by a reader/writer lock // Add/Remove cannot run at the same time with cache cleanup but Add/Remove can run at the same time @@ -592,8 +591,8 @@ namespace System.Runtime.InteropServices.WindowsRuntime { tokens.Push(token); } - - tokenAdded = true; + + tokenAdded = true; } } finally @@ -601,10 +600,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime s_eventCacheRWLock.ReleaseReaderLock(); } - BCLDebug.Log("INTEROP", "[WinRT_Eventing] Event subscribed for instance = " + instanceKey + ", handler = " + handler + "\n"); + BCLDebug.Log("INTEROP", "[WinRT_Eventing] Event subscribed for instance = " + instanceKey + ", handler = " + handler + "\n"); } - catch(Exception) - { + catch (Exception) + { // If we've already added the token and go there, we don't need to "UNDO" anything if (!tokenAdded) { @@ -613,8 +612,8 @@ namespace System.Runtime.InteropServices.WindowsRuntime removeMethod(token); } - - throw; + + throw; } } @@ -633,18 +632,18 @@ namespace System.Runtime.InteropServices.WindowsRuntime 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) { Contract.Requires(instance != null); Contract.Requires(removeMethod != null); - Contract.Requires(s_eventRegistrations != null); + Contract.Requires(s_eventRegistrations != null); EventCacheKey eventCacheKey; eventCacheKey.target = instance; eventCacheKey.method = removeMethod.Method; - + lock (s_eventRegistrations) { EventCacheEntry eventCacheEntry; @@ -656,18 +655,18 @@ namespace System.Runtime.InteropServices.WindowsRuntime tokenListCount = null; return null; } - + BCLDebug.Log("INTEROP", "[WinRT_Eventing] Adding (" + instance + "," + removeMethod.Method + ") into cache" + "\n"); - + eventCacheEntry = new EventCacheEntry(); eventCacheEntry.registrationTable = new ConditionalWeakTable<object, EventRegistrationTokenListWithCount>(); eventCacheEntry.tokenListCount = new TokenListCount(eventCacheKey); - + s_eventRegistrations.Add(eventCacheKey, eventCacheEntry); } - + tokenListCount = eventCacheEntry.tokenListCount; - + return eventCacheEntry.registrationTable; } } @@ -677,7 +676,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime object instanceKey = GetInstanceKey(removeMethod); EventRegistrationToken token; - + // // The whole add/remove code has to be protected by a reader/writer lock // Add/Remove cannot run at the same time with cache cleanup but Add/Remove can run at the same time @@ -691,10 +690,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime { // We have no information regarding this particular instance (IUnknown*/type) - just return // This is necessary to avoid leaking empty dictionary/conditionalWeakTables for this instance - BCLDebug.Log("INTEROP", "[WinRT_Eventing] no registrationTokens found for instance=" + instanceKey + ", handler= " + handler + "\n"); + BCLDebug.Log("INTEROP", "[WinRT_Eventing] no registrationTokens found for instance=" + instanceKey + ", handler= " + handler + "\n"); return; } - + lock (registrationTokens) { EventRegistrationTokenListWithCount tokens; @@ -707,12 +706,12 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Note that inside TryGetValueWithValueEquality we assumes that any delegate // with the same value equality would have the same hash code object key = registrationTokens.FindEquivalentKeyUnsafe(handler, out tokens); - Debug.Assert((key != null && tokens != null) || (key == null && tokens == null), + Debug.Assert((key != null && tokens != null) || (key == null && tokens == null), "key and tokens must be both null or non-null"); if (tokens == null) { // Failure to find a registration for a token is not an error - it's simply a no-op. - BCLDebug.Log("INTEROP", "[WinRT_Eventing] no token list found for instance=" + instanceKey + ", handler= " + handler + "\n"); + BCLDebug.Log("INTEROP", "[WinRT_Eventing] no token list found for instance=" + instanceKey + ", handler= " + handler + "\n"); return; } @@ -721,7 +720,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // is created at the same address before the entry for the old one goes away. // See comments above s_eventRegistrations for more details bool moreItems = tokens.Pop(out token); - + // If the last token is removed from token list, we need to remove it from the cache // otherwise FindEquivalentKeyUnsafe may found this empty token list even though there could be other // equivalent keys in there with non-0 token list @@ -733,8 +732,8 @@ namespace System.Runtime.InteropServices.WindowsRuntime // EventRegistrationTokenList registrationTokens.Remove(key); } - - BCLDebug.Log("INTEROP", "[WinRT_Eventing] Event unsubscribed for managed instance = " + instanceKey + ", handler = " + handler + ", token = " + token.m_value + "\n"); + + BCLDebug.Log("INTEROP", "[WinRT_Eventing] Event unsubscribed for managed instance = " + instanceKey + ", handler = " + handler + ", token = " + token.m_value + "\n"); } } finally @@ -745,7 +744,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Call removeMethod outside of RW lock // At this point we don't need to worry about race conditions and we can avoid deadlocks // if removeMethod waits on finalizer thread - removeMethod(token); + removeMethod(token); } internal static void RemoveAllEventHandlers(Action<EventRegistrationToken> removeMethod) @@ -753,7 +752,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime object instanceKey = GetInstanceKey(removeMethod); List<EventRegistrationToken> tokensToRemove = new List<EventRegistrationToken>(); - + // // The whole add/remove code has to be protected by a reader/writer lock // Add/Remove cannot run at the same time with cache cleanup but Add/Remove can run at the same time @@ -769,7 +768,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // This is necessary to avoid leaking empty dictionary/conditionalWeakTables for this instance return; } - + lock (registrationTokens) { // Copy all tokens to tokensToRemove array which later we'll call removeMethod on @@ -782,7 +781,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Clear the table - at this point all event handlers are no longer in the cache // but they are not removed yet registrationTokens.Clear(); - BCLDebug.Log("INTEROP", "[WinRT_Eventing] Cache cleared for managed instance = " + instanceKey + "\n"); + BCLDebug.Log("INTEROP", "[WinRT_Eventing] Cache cleared for managed instance = " + instanceKey + "\n"); } } finally @@ -793,11 +792,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime // // Remove all handlers outside the lock // - BCLDebug.Log("INTEROP", "[WinRT_Eventing] Start removing all events for instance = " + instanceKey + "\n"); + BCLDebug.Log("INTEROP", "[WinRT_Eventing] Start removing all events for instance = " + instanceKey + "\n"); CallRemoveMethods(removeMethod, tokensToRemove); - BCLDebug.Log("INTEROP", "[WinRT_Eventing] Finished removing all events for instance = " + instanceKey + "\n"); + BCLDebug.Log("INTEROP", "[WinRT_Eventing] Finished removing all events for instance = " + instanceKey + "\n"); } - + internal class ReaderWriterLockTimedOutException : ApplicationException { @@ -821,19 +820,19 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Lock specifiation for myLock: This lock protects exactly the local fields associted // instance of MyReaderWriterLock. It does NOT protect the memory associted with the // the events that hang off this lock (eg writeEvent, readEvent upgradeEvent). - int myLock; + private int myLock; // Who owns the lock owners > 0 => readers // owners = -1 means there is one writer. Owners must be >= -1. - int owners; + private int owners; // These variables allow use to avoid Setting events (which is expensive) if we don't have to. - uint numWriteWaiters; // maximum number of threads that can be doing a WaitOne on the writeEvent - uint numReadWaiters; // maximum number of threads that can be doing a WaitOne on the readEvent + private uint numWriteWaiters; // maximum number of threads that can be doing a WaitOne on the writeEvent + private uint numReadWaiters; // maximum number of threads that can be doing a WaitOne on the readEvent // conditions we wait on. - EventWaitHandle writeEvent; // threads waiting to aquire a write lock go here. - EventWaitHandle readEvent; // threads waiting to aquire a read lock go here (will be released in bulk) + private EventWaitHandle writeEvent; // threads waiting to aquire a write lock go here. + private EventWaitHandle readEvent; // threads waiting to aquire a read lock go here (will be released in bulk) internal MyReaderWriterLock() { @@ -843,7 +842,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal void AcquireReaderLock(int millisecondsTimeout) { EnterMyLock(); - for (; ; ) + for (;;) { // We can enter a read lock if there are only read-locks have been given out // and a writer is not trying to get in. @@ -869,7 +868,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal void AcquireWriterLock(int millisecondsTimeout) { EnterMyLock(); - for (; ; ) + for (;;) { if (owners == 0) { @@ -912,15 +911,16 @@ namespace System.Runtime.InteropServices.WindowsRuntime /// 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"); ExitMyLock(); EventWaitHandle newEvent; - if (makeAutoResetEvent) + if (makeAutoResetEvent) newEvent = new AutoResetEvent(false); - else + else newEvent = new ManualResetEvent(false); EnterMyLock(); if (waitEvent == null) // maybe someone snuck in. @@ -944,7 +944,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime { if (!waitEvent.WaitOne(millisecondsTimeout, false)) throw new ReaderWriterLockTimedOutException(); - + waitSuccessful = true; } finally @@ -977,18 +977,19 @@ namespace System.Runtime.InteropServices.WindowsRuntime ExitMyLock(); } - private void EnterMyLock() { + private void EnterMyLock() + { if (Interlocked.CompareExchange(ref myLock, 1, 0) != 0) EnterMyLockSpin(); } private void EnterMyLockSpin() { - for (int i = 0; ;i++) + for (int i = 0; ; i++) { if (i < 3 && Environment.ProcessorCount > 1) Thread.SpinWait(20); // Wait a few dozen instructions to let another processor release lock. - else + else Thread.Sleep(0); // Give up my quantum. if (Interlocked.CompareExchange(ref myLock, 1, 0) == 0) @@ -1000,7 +1001,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime Debug.Assert(myLock != 0, "Exiting spin lock that is not held"); myLock = 0; } - }; + }; } // @@ -1008,27 +1009,26 @@ namespace System.Runtime.InteropServices.WindowsRuntime // internal static void CallRemoveMethods(Action<EventRegistrationToken> removeMethod, List<EventRegistrationToken> tokensToRemove) { - List<Exception> exceptions = new List<Exception>(); - + foreach (EventRegistrationToken token in tokensToRemove) { try { removeMethod(token); } - catch(Exception ex) + catch (Exception ex) { exceptions.Add(ex); } - + BCLDebug.Log("INTEROP", "[WinRT_Eventing] Event unsubscribed for token = " + token.m_value + "\n"); - } + } if (exceptions.Count > 0) throw new AggregateException(exceptions.ToArray()); } - + internal static unsafe string HStringToString(IntPtr hstring) { Contract.Requires(Environment.IsWinRTSupported); @@ -1109,7 +1109,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } private static Guid s_iidIErrorInfo = new Guid(0x1CF2B120, 0x547D, 0x101B, 0x8E, 0x65, 0x08, 0x00, 0x2B, 0x2B, 0xD1, 0x19); - + /// <summary> /// Report that an exception has occurred which went user unhandled. This allows the global error handler /// for the application to be invoked to process the error. @@ -1183,14 +1183,14 @@ namespace System.Runtime.InteropServices.WindowsRuntime // Get an IActivationFactory * for a managed type internal static IntPtr GetActivationFactoryForType(Type type) { - ManagedActivationFactory activationFactory = GetManagedActivationFactory(type); + ManagedActivationFactory activationFactory = GetManagedActivationFactory(type); return Marshal.GetComInterfaceForObject(activationFactory, typeof(IActivationFactory)); - } + } internal static ManagedActivationFactory GetManagedActivationFactory(Type type) { ManagedActivationFactory activationFactory = new ManagedActivationFactory(type); - + // If the type has any associated factory interfaces (i.e. supports non-default activation // or has statics), the CCW for this instance of ManagedActivationFactory must support them. Marshal.InitializeManagedWinRTFactoryObject(activationFactory, (RuntimeType)type); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMetadata.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMetadata.cs index 429112c8b0..b772a2252b 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMetadata.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMetadata.cs @@ -4,22 +4,22 @@ // +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics.Contracts; +using System.Reflection; +using System.Reflection.Emit; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security; + namespace System.Runtime.InteropServices.WindowsRuntime { - using System; - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Diagnostics.Contracts; - using System.Reflection; - using System.Reflection.Emit; - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; - using System.Security; - internal static class WindowsRuntimeMetadata { private static EventHandler<DesignerNamespaceResolveEventArgs> DesignerNamespaceResolve; - + internal static string[] OnDesignerNamespaceResolveEvent(AppDomain appDomain, string namespaceName) { EventHandler<DesignerNamespaceResolveEventArgs> eventHandler = DesignerNamespaceResolve; @@ -52,11 +52,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime } } } - + return null; } } - + internal class DesignerNamespaceResolveEventArgs : EventArgs { |