Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
        private NeoDatis.Odb.Core.Layers.Layer2.Meta.CollectionObjectInfo IntrospectCollection
            (System.Collections.ICollection collection, bool introspect, System.Collections.Generic.IDictionary
            <object, NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo> alreadyReadObjects
            , NeoDatis.Odb.Core.Layers.Layer2.Meta.ODBType type, NeoDatis.Odb.Core.Layers.Layer1.Introspector.IIntrospectionCallback
            callback)
        {
            if (collection == null)
            {
                return(new NeoDatis.Odb.Core.Layers.Layer2.Meta.CollectionObjectInfo());
            }
            // A collection that contain all meta representations of the collection
            // objects
            System.Collections.Generic.ICollection <NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo
                                                    > collectionCopy = new System.Collections.Generic.List <NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo
                                                                                                            >(collection.Count);
            // A collection to keep references all all non native objects of the
            // collection
            // This will be used later to get all non native objects contained in an
            // object
            System.Collections.Generic.ICollection <NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo
                                                    > nonNativesObjects = new System.Collections.Generic.List <NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo
                                                                                                               >(collection.Count);
            NeoDatis.Odb.Core.Layers.Layer2.Meta.AbstractObjectInfo aoi = null;
            System.Collections.IEnumerator iterator = collection.GetEnumerator();
            while (iterator.MoveNext())
            {
                object o = iterator.Current;
                NeoDatis.Odb.Core.Layers.Layer2.Meta.ClassInfo ci = null;
                // Null objects are not inserted in list
                if (o != null)
                {
                    ci  = GetClassInfo(OdbClassUtil.GetFullName(o.GetType()));
                    aoi = GetObjectInfo(o, ci, introspect, alreadyReadObjects, callback);
                    collectionCopy.Add(aoi);
                    if (aoi.IsNonNativeObject())
                    {
                        // o is not null, call the callback with it
                        //callback.objectFound(o);
                        // This is a non native object
                        nonNativesObjects.Add((NeoDatis.Odb.Core.Layers.Layer2.Meta.NonNativeObjectInfo)aoi
                                              );
                    }
                }
            }
            NeoDatis.Odb.Core.Layers.Layer2.Meta.CollectionObjectInfo coi = new NeoDatis.Odb.Core.Layers.Layer2.Meta.CollectionObjectInfo
                                                                                (collectionCopy, nonNativesObjects);
            string realCollectionClassName = OdbClassUtil.GetFullName(collection.GetType());

            if (realCollectionClassName.IndexOf("$") != -1)
            {
                coi.SetRealCollectionClassName(type.GetDefaultInstanciationClass().FullName);
            }
            else
            {
                coi.SetRealCollectionClassName(realCollectionClassName);
            }
            return(coi);
        }
Beispiel #7
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;
            }
        }
Beispiel #8
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);
        }
Beispiel #9
0
            /// <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
                {
                    method = target.GetType().GetMethod("removeAll");

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

                        while (e.MoveNext() == true)
                        {
                            while ((bool)methodContains.Invoke(target, new Object[] { e.Current }) == true)
                            {
                                method.Invoke(target, new Object[] { e.Current });
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                return(true);
            }
        GetStandardValues(ITypeDescriptorContext context)
        {
            var  obj     = context.Instance;
            Type objType = obj.GetType();

            // Get the field that DropdownListConverter was applied to
            string       fieldName = context.PropertyDescriptor.Name;
            PropertyInfo pi        = objType.GetProperty(fieldName);

            // Get the field containing respective Value List from attributes
            string listfieldName = ((DropdownListAttribute)pi.GetCustomAttribute(typeof(DropdownListAttribute))).ListfieldName;

            pi = objType.GetProperty(listfieldName);

            System.Collections.ICollection valueCollection = pi.GetValue(obj) as System.Collections.ICollection;

            if ((valueCollection != null) && typeof(System.Collections.IDictionary).IsAssignableFrom(valueCollection.GetType()))
            {
                return(new StandardValuesCollection(((System.Collections.IDictionary)valueCollection).Keys));
            }

            return(new StandardValuesCollection(valueCollection));
        }