Exemplo n.º 1
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));
                }
            }
        }
Exemplo n.º 2
0
        void 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));
            }
        }
Exemplo n.º 3
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));
            }
        }
Exemplo n.º 4
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));
     }
 }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
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));
                }
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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));
                }
            }
        }
Exemplo n.º 10
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));
                }
            }
        }