Esempio n. 1
0
 private static void VerifyValueType(object value)
 {
     if (!List <T> .IsCompatibleObject(value))
     {
         ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(T));
     }
 }
Esempio n. 2
0
        void System.Collections.IDictionary.Add(Object key, Object value)
        {
            if (key == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
            }

            ThrowHelper.IfNullAndNullsAreIllegalThenThrow <TValue>(value, ExceptionArgument.value);

            try
            {
                TKey tempKey = (TKey)key;

                try
                {
                    Add(tempKey, (TValue)value);
                }
                catch (InvalidCastException)
                {
                    ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(TValue));
                }
            }
            catch (InvalidCastException)
            {
                ThrowHelper.ThrowWrongKeyTypeArgumentException(key, typeof(TKey));
            }
        }
Esempio n. 3
0
        object IDictionary.this[object key] {
            get {
                if (IsCompatibleKey(key))
                {
                    int i = FindEntry((TKey)key);
                    if (i >= 0)
                    {
                        return(entries[i].value);
                    }
                }
                return(null);
            }
            set {
                if (key == null)
                {
                    ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
                }
                ThrowHelper.IfNullAndNullsAreIllegalThenThrow <TValue>(value, ExceptionArgument.value);

                try {
                    TKey tempKey = (TKey)key;
                    try {
                        this[tempKey] = (TValue)value;
                    }
                    catch (InvalidCastException) {
                        ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(TValue));
                    }
                }
                catch (InvalidCastException) {
                    ThrowHelper.ThrowWrongKeyTypeArgumentException(key, typeof(TKey));
                }
            }
        }
 private static void VerifyValueType(object value)
 {
     if ((value is TValue) || (value == null && !typeof(TValue).IsValueType))
     {
         return;
     }
     ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(TValue));
 }
Esempio n. 5
0
        void System.Collections.IList.Insert(int index, Object item)
        {
            ThrowHelper.IfNullAndNullsAreIllegalThenThrow <T>(item, ExceptionArgument.item);

            try {
                Insert(index, (T)item);
            }
            catch (InvalidCastException) {
                ThrowHelper.ThrowWrongValueTypeArgumentException(item, typeof(T));
            }
        }
Esempio n. 6
0
 void IList.Insert(int index, object item)
 {
     ThrowHelper.IfNullAndNullsAreIllegalThenThrow <T>(item, ExceptionArgument.item);
     try
     {
         this.Insert(index, (T)item);
     }
     catch (InvalidCastException ex)
     {
         ThrowHelper.ThrowWrongValueTypeArgumentException <object>(item, typeof(T));
     }
 }
Esempio n. 7
0
        int System.Collections.IList.Add(Object item)
        {
            ThrowHelper.IfNullAndNullsAreIllegalThenThrow <T>(item, ExceptionArgument.item);

            try {
                Add((T)item);
            }
            catch (InvalidCastException) {
                ThrowHelper.ThrowWrongValueTypeArgumentException(item, typeof(T));
            }

            return(Count - 1);
        }
Esempio n. 8
0
 int IList.Add(object item)
 {
     ThrowHelper.IfNullAndNullsAreIllegalThenThrow <T>(item, ExceptionArgument.item);
     try
     {
         this.Add((T)item);
     }
     catch (InvalidCastException ex)
     {
         ThrowHelper.ThrowWrongValueTypeArgumentException(item, typeof(T));
     }
     return(this.Count - 1);
 }
Esempio n. 9
0
        Object System.Collections.IList.this[int index] {
            get {
                return(this[index]);
            }
            set {
                ThrowHelper.IfNullAndNullsAreIllegalThenThrow <T>(value, ExceptionArgument.value);

                try {
                    this[index] = (T)value;
                }
                catch (InvalidCastException) {
                    ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(T));
                }
            }
        }
Esempio n. 10
0
        int IList.Add(object?item)  // TODO-NULLABLE-GENERIC: nullable if default(T) can be null
        {
            ThrowHelper.IfNullAndNullsAreIllegalThenThrow <T>(item, ExceptionArgument.item);

            try
            {
                Add((T)item !);
            }
            catch (InvalidCastException)
            {
                ThrowHelper.ThrowWrongValueTypeArgumentException(item, typeof(T));
            }

            return(Count - 1);
        }
Esempio n. 11
0
        public virtual Object this[Object key]
        {
            get
            {
                if (IsCompatibleKey(key))
                {
                    int i = IndexOfKey((TKey)key);
                    if (i >= 0)
                    {
                        return(values[i]);
                    }
                }

                return(null);
            }
            set
            {
                if (!IsCompatibleKey(key))
                {
                    ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
                }

                ThrowHelper.IfNullAndNullsAreIllegalThenThrow <TValue>(value, ExceptionArgument.value);

                try
                {
                    TKey tempKey = (TKey)key;
                    try
                    {
                        this[tempKey] = (TValue)value;
                    }
                    catch (InvalidCastException)
                    {
                        ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(TValue));
                    }
                }
                catch (InvalidCastException)
                {
                    ThrowHelper.ThrowWrongKeyTypeArgumentException(key, typeof(TKey));
                }
            }
        }
Esempio n. 12
0
        object?IList.this[int index]  // TODO-NULLABLE-GENERIC: nullability is the same as of T
        {
            get
            {
                return(this[index]);
            }
            set
            {
                ThrowHelper.IfNullAndNullsAreIllegalThenThrow <T>(value, ExceptionArgument.value);

                try
                {
                    this[index] = (T)value !;
                }
                catch (InvalidCastException)
                {
                    ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(T));
                }
            }
        }
 void IDictionary.Add(object key, object value)
 {
     if (key == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
     }
     ThrowHelper.IfNullAndNullsAreIllegalThenThrow <TValue>(value, ExceptionArgument.value);
     try
     {
         TKey local = (TKey)key;
         try
         {
             this.Add(local, (TValue)value);
         }
         catch (InvalidCastException)
         {
             ThrowHelper.ThrowWrongValueTypeArgumentException(value, typeof(TValue));
         }
     }
     catch (InvalidCastException)
     {
         ThrowHelper.ThrowWrongKeyTypeArgumentException(key, typeof(TKey));
     }
 }