예제 #1
0
 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);
 }
예제 #2
0
        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);
        }
예제 #3
0
 // 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;
     }
 }
예제 #4
0
        // 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;
            }
        }
예제 #5
0
        // 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);
        }
예제 #6
0
        // 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;
            }
        }
예제 #7
0
        // 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;
            }
        }