/// <summary>
        /// Adds a new element to the specified collection.
        /// </summary>
        /// <param name="c">Collection where the new element will be added.</param>
        /// <param name="obj">Object to add.</param>
        /// <returns>true</returns>
        public static bool Add(System.Collections.ICollection c, System.Object obj)
        {
            bool added = false;

            //Reflection. Invoke either the "add" or "Add" method.
            System.Reflection.MethodInfo method;
            try
            {
                //Get the "add" method for proprietary classes
#if NETFX_CORE && UNITY_METRO && !UNITY_EDITOR
                method = Type_WP_8_1.Type.GetMethod(c.GetType(), "Add");
#else
                method = c.GetType().GetMethod("Add");
#endif
                if (method == null)
#if NETFX_CORE && UNITY_METRO && !UNITY_EDITOR
                { method = Type_WP_8_1.Type.GetMethod(c.GetType(), "add"); }
#else
                { method = c.GetType().GetMethod("add"); }
#endif
                int index = (int)method.Invoke(c, new System.Object[] { obj });
                if (index >= 0)
                {
                    added = true;
                }
            }
            catch (System.Exception e)
            {
                throw e;
            }
            return(added);
        }
        /// <summary>
        /// Determines whether the collection contains the specified element.
        /// </summary>
        /// <param name="c">The collection to check.</param>
        /// <param name="obj">The object to locate in the collection.</param>
        /// <returns>true if the element is in the collection.</returns>
        public static bool Contains(System.Collections.ICollection c, System.Object obj)
        {
            bool contains = false;

            //Reflection. Invoke "contains" method for proprietary classes
            System.Reflection.MethodInfo method;
            try
            {
#if NETFX_CORE && UNITY_METRO && !UNITY_EDITOR
                method = Type_WP_8_1.Type.GetMethod(c.GetType(), "Contains");
#else
                method = c.GetType().GetMethod("Contains");
#endif
                if (method == null)
#if NETFX_CORE && UNITY_METRO && !UNITY_EDITOR
                { method = Type_WP_8_1.Type.GetMethod(c.GetType(), "contains"); }
#else
                { method = c.GetType().GetMethod("contains"); }
#endif

                contains = (bool)method.Invoke(c, new System.Object[] { obj });
            }
            catch (System.Exception e)
            {
                throw e;
            }

            return(contains);
        }
Пример #3
0
        /// <summary>
        /// Retains the elements in the target collection that are contained in the specified collection
        /// </summary>
        /// <param name="target">Collection where the elements will be removed.</param>
        /// <param name="c">Elements to be retained in the target collection.</param>
        /// <returns>true</returns>
        public static bool RetainAll(System.Collections.ICollection target, System.Collections.ICollection c)
        {
            System.Collections.IEnumerator e  = new System.Collections.ArrayList(target).GetEnumerator();
            System.Collections.ArrayList   al = new System.Collections.ArrayList(c);

            //Reflection. Invoke "retainAll" method for proprietary classes or "Remove" for each element in the collection
            System.Reflection.MethodInfo method;
            try
            {
                method = c.GetType().GetMethod("retainAll");

                if (method != null)
                {
                    method.Invoke(target, new System.Object[] { c });
                }
                else
                {
                    method = c.GetType().GetMethod("Remove");

                    while (e.MoveNext() == true)
                    {
                        if (al.Contains(e.Current) == false)
                        {
                            method.Invoke(target, new System.Object[] { e.Current });
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }

            return(true);
        }
        /// <summary>
        /// Removes all the elements from the collection.
        /// </summary>
        /// <param name="c">The collection to remove elements.</param>
        public static void Clear(System.Collections.ICollection c)
        {
            //Reflection. Invoke "Clear" method or "clear" method for proprietary classes
            System.Reflection.MethodInfo method;
            try
            {
#if NETFX_CORE && UNITY_METRO && !UNITY_EDITOR
                method = Type_WP_8_1.Type.GetMethod(c.GetType(), "Clear");
#else
                method = c.GetType().GetMethod("Clear");
#endif
                if (method == null)
#if NETFX_CORE && UNITY_METRO && !UNITY_EDITOR
                { method = Type_WP_8_1.Type.GetMethod(c.GetType(), "clear"); }
#else
                { method = c.GetType().GetMethod("clear"); }
#endif

                method.Invoke(c, new System.Object[] {});
            }
            catch (System.Exception e)
            {
                throw e;
            }
        }
Пример #5
0
        /// <summary>
        /// Adds all of the elements of the "c" collection to the "target" collection.
        /// </summary>
        /// <param name="target">Collection where the new elements will be added.</param>
        /// <param name="c">Collection whose elements will be added.</param>
        /// <returns>Returns true if at least one element was added, false otherwise.</returns>
        public static bool AddAll(System.Collections.ICollection target, System.Collections.ICollection c)
        {
            System.Collections.IEnumerator e = new System.Collections.ArrayList(c).GetEnumerator();
            bool added = false;

            //Reflection. Invoke "addAll" method for proprietary classes
            System.Reflection.MethodInfo method;
            try
            {
                method = target.GetType().GetMethod("addAll");

                if (method != null)
                {
                    added = (bool)method.Invoke(target, new System.Object[] { c });
                }
                else
                {
                    method = target.GetType().GetMethod("Add");
                    while (e.MoveNext() == true)
                    {
                        bool tempBAdded = (int)method.Invoke(target, new System.Object[] { e.Current }) >= 0;
                        added = added ? added : tempBAdded;
                    }
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            return(added);
        }
Пример #6
0
        /// <summary>
        /// Adds a new element to the specified collection.
        /// </summary>
        /// <param name="c">Collection where the new element will be added.</param>
        /// <param name="obj">Object to add.</param>
        /// <returns>true</returns>
        public static bool Add(System.Collections.ICollection c, System.Object obj)
        {
            bool added = false;

            //Reflection. Invoke either the "add" or "Add" method.
            System.Reflection.MethodInfo method;
            try
            {
                //Get the "add" method for proprietary classes
                method = c.GetType().GetMethod("Add");
                if (method == null)
                {
                    method = c.GetType().GetMethod("add");
                }
                int index = (int)method.Invoke(c, new System.Object[] { obj });
                if (index >= 0)
                {
                    added = true;
                }
            }
            catch (System.Exception e)
            {
                throw e;
            }
            return(added);
        }
Пример #7
0
        /// <summary>
        /// Removes the specified element from the collection.
        /// </summary>
        /// <param name="c">The collection where the element will be removed.</param>
        /// <param name="obj">The element to remove from the collection.</param>
        public static bool Remove(System.Collections.ICollection c, System.Object obj)
        {
            bool changed = false;

            //Reflection. Invoke "remove" method for proprietary classes or "Remove" method
            System.Reflection.MethodInfo method;
            try
            {
                method = c.GetType().GetMethod("remove");

                if (method != null)
                {
                    method.Invoke(c, new System.Object[] { obj });
                }
                else
                {
                    method  = c.GetType().GetMethod("Contains");
                    changed = (bool)method.Invoke(c, new System.Object[] { obj });
                    method  = c.GetType().GetMethod("Remove");
                    method.Invoke(c, new System.Object[] { obj });
                }
            }
            catch (System.Exception e)
            {
                throw e;
            }

            return(changed);
        }
Пример #8
0
        /// <summary>
        /// Determines whether the collection contains all the elements in the specified collection.
        /// </summary>
        /// <param name="target">The collection to check.</param>
        /// <param name="c">Collection whose elements would be checked for containment.</param>
        /// <returns>true id the target collection contains all the elements of the specified collection.</returns>
        public static bool ContainsAll(System.Collections.ICollection target, System.Collections.ICollection c)
        {
            System.Collections.IEnumerator e = c.GetEnumerator();

            bool contains = false;

            //Reflection. Invoke "containsAll" method for proprietary classes or "Contains" method for each element in the collection
            System.Reflection.MethodInfo method;
            try
            {
                method = target.GetType().GetMethod("containsAll");

                if (method != null)
                {
                    contains = (bool)method.Invoke(target, new Object[] { c });
                }
                else
                {
                    method = target.GetType().GetMethod("Contains");
                    while (e.MoveNext() == true)
                    {
                        if ((contains = (bool)method.Invoke(target, new Object[] { e.Current })) == false)
                        {
                            break;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }

            return(contains);
        }
        /// <summary>
        /// Removes all the elements from the specified collection that are contained in the target collection.
        /// </summary>
        /// <param name="target">Collection where the elements will be removed.</param>
        /// <param name="c">Elements to remove from the target collection.</param>
        /// <returns>true</returns>
        public static bool RemoveAll(System.Collections.ICollection target, System.Collections.ICollection c)
        {
            System.Collections.ArrayList   al = ToArrayList(c);
            System.Collections.IEnumerator e  = al.GetEnumerator();

            //Reflection. Invoke "removeAll" method for proprietary classes or "Remove" for each element in the collection
            System.Reflection.MethodInfo method;
            try
            {
#if NETFX_CORE && UNITY_METRO && !UNITY_EDITOR
                method = Type_WP_8_1.Type.GetMethod(target.GetType(), "removeAll");
#else
                method = target.GetType().GetMethod("removeAll");
#endif
                if (method != null)
                {
                    method.Invoke(target, new System.Object[] { al });
                }
                else
                {
#if NETFX_CORE && UNITY_METRO && !UNITY_EDITOR
                    method = Type_WP_8_1.Type.GetMethod(target.GetType(), "Remove");
#else
                    method = target.GetType().GetMethod("Remove");
#endif
#if NETFX_CORE && UNITY_METRO && !UNITY_EDITOR
                    System.Reflection.MethodInfo methodContains = Type_WP_8_1.Type.GetMethod(target.GetType(), "Contains");
#else
                    System.Reflection.MethodInfo methodContains = target.GetType().GetMethod("Contains");
#endif

                    while (e.MoveNext() == true)
                    {
                        while ((bool)methodContains.Invoke(target, new System.Object[] { e.Current }) == true)
                        {
                            method.Invoke(target, new System.Object[] { e.Current });
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            return(true);
        }
Пример #10
0
        /// <summary>
        /// Removes all the elements from the collection.
        /// </summary>
        /// <param name="c">The collection to remove elements.</param>
        public static void Clear(System.Collections.ICollection c)
        {
            //Reflection. Invoke "Clear" method or "clear" method for proprietary classes
            System.Reflection.MethodInfo method;
            try
            {
                method = c.GetType().GetMethod("Clear");

                if (method == null)
                {
                    method = c.GetType().GetMethod("clear");
                }

                method.Invoke(c, new System.Object[] {});
            }
            catch (System.Exception e)
            {
                throw e;
            }
        }
Пример #11
0
        /// <summary>
        /// Determines whether the collection contains the specified element.
        /// </summary>
        /// <param name="c">The collection to check.</param>
        /// <param name="obj">The object to locate in the collection.</param>
        /// <returns>true if the element is in the collection.</returns>
        public static bool Contains(System.Collections.ICollection c, System.Object obj)
        {
            bool contains = false;

            //Reflection. Invoke "contains" method for proprietary classes
            System.Reflection.MethodInfo method;
            try
            {
                method = c.GetType().GetMethod("Contains");

                if (method == null)
                {
                    method = c.GetType().GetMethod("contains");
                }

                contains = (bool)method.Invoke(c, new System.Object[] { obj });
            }
            catch (System.Exception e)
            {
                throw e;
            }

            return(contains);
        }
 public static System.Collections.ICollection EmptyCollectionClone(ICollectionSource source, System.Collections.ICollection
                                                                   original)
 {
     if (original is System.Collections.ArrayList)
     {
         return(new System.Collections.ArrayList(original.Count));
     }
     try
     {
         return((System.Collections.ICollection)Activator.CreateInstance(original.GetType()));
     }
     catch (MissingMethodException x)
     {
         throw new ArgumentException(string.Format("Parameterless ctor required for type '{0}'", original.GetType()), x);
     }
 }
        /// <summary>
        /// Removes the specified element from the collection.
        /// </summary>
        /// <param name="c">The collection where the element will be removed.</param>
        /// <param name="obj">The element to remove from the collection.</param>
        public static bool Remove(System.Collections.ICollection c, System.Object obj)
        {
            bool changed = false;

            //Reflection. Invoke "remove" method for proprietary classes or "Remove" method
            System.Reflection.MethodInfo method;
            try
            {
#if NETFX_CORE && UNITY_METRO && !UNITY_EDITOR
                method = Type_WP_8_1.Type.GetMethod(c.GetType(), "remove");
#else
                method = c.GetType().GetMethod("remove");
#endif
                if (method != null)
                {
                    method.Invoke(c, new System.Object[] { obj });
                }
                else
                {
#if NETFX_CORE && UNITY_METRO && !UNITY_EDITOR
                    method = Type_WP_8_1.Type.GetMethod(c.GetType(), "Contains");
#else
                    method = c.GetType().GetMethod("Contains");
#endif
                    changed = (bool)method.Invoke(c, new System.Object[] { obj });
#if NETFX_CORE && UNITY_METRO && !UNITY_EDITOR
                    method = Type_WP_8_1.Type.GetMethod(c.GetType(), "Remove");
#else
                    method = c.GetType().GetMethod("Remove");
#endif
                    method.Invoke(c, new System.Object[] { obj });
                }
            }
            catch (System.Exception e)
            {
                throw e;
            }

            return(changed);
        }