private static System.InvalidCastException CreateExceptionForInvalidCast(
     PropertyType type,
     PropertyType unboxType)
 {
     System.InvalidCastException ex = new System.InvalidCastException(SR.Format(SR.PropertyValue_InvalidCast, type, unboxType));
     McgMarshal.SetExceptionErrorCode(ex, Interop.COM.TYPE_E_TYPEMISMATCH);
     return(ex);
 }
        private static System.InvalidCastException CreateExceptionForInvalidCoersion(
            PropertyType type,
            object value,
            PropertyType unboxType,
            int hr)
        {
            InvalidCastException ex = new InvalidCastException(SR.Format(SR.PropertyValue_InvalidCoersion, type, value, unboxType));

            McgMarshal.SetExceptionErrorCode(ex, hr);
            return(ex);
        }
 // V Lookup(K key)
 public static V Lookup <K, V>(global::System.Collections.Generic.IReadOnlyDictionary <K, V> _this, K key)
 {
     try
     {
         return(_this[key]);
     }
     catch (KeyNotFoundException ex)
     {
         // Change error code to match what WinRT expects
         McgMarshal.SetExceptionErrorCode(ex, global::McgInterop.McgHelpers.__HResults.E_BOUNDS);
         throw;
     }
 }
        // T GetAt(uint index)
        public static T GetAt <T>(
            global::System.Collections.Generic.IList <T> _this,
            uint index)
        {
            EnsureIndexInt32(index);

            try
            {
                return(_this[(int)index]);
            }
            catch (System.ArgumentOutOfRangeException ex)
            {
                McgMarshal.SetExceptionErrorCode(ex, global::McgInterop.McgHelpers.__HResults.E_BOUNDS);
                throw;
            }
        }
        // void RemoveAtEnd()
        public static void RemoveAtEnd <T>(
            global::System.Collections.Generic.IList <T> _this)
        {
            uint size = (uint)_this.Count;

            if (size == 0)
            {
                InvalidOperationException ex = new InvalidOperationException(global::Mcg.System.SR.GetString(global::Mcg.System.SR.Excep_CannotRemoveFromEmptyCollection));

                // Change error code to match what WinRT expects
                McgMarshal.SetExceptionErrorCode(ex, global::McgInterop.McgHelpers.__HResults.E_BOUNDS);
                throw ex;
            }

            RemoveAt <T>(_this, size - 1);
        }
        // void RemoveAt(uint index)
        public static void RemoveAt <T>(
            global::System.Collections.Generic.IList <T> _this,
            uint index)
        {
            EnsureIndexInt32(index);

            try
            {
                _this.RemoveAt((int)index);
            }
            catch (System.ArgumentOutOfRangeException ex)
            {
                // Change error code to match what WinRT expects
                McgMarshal.SetExceptionErrorCode(ex, global::McgInterop.McgHelpers.__HResults.E_BOUNDS);
                throw;
            }
        }
        // void InsertAt(uint index, T value)
        public static void InsertAt <T>(
            global::System.Collections.Generic.IList <T> _this,
            uint index,
            T value)
        {
            // Inserting at an index one past the end of the list is equivalent to appending
            // so we need to ensure that we're within (0, count + 1).
            EnsureIndexInt32(index);

            try
            {
                _this.Insert((int)index, value);
            }
            catch (System.ArgumentOutOfRangeException ex)
            {
                // Change error code to match what WinRT expects
                McgMarshal.SetExceptionErrorCode(ex, global::McgInterop.McgHelpers.__HResults.E_BOUNDS);
                throw;
            }
        }