IsTypeOf() public static method

public static IsTypeOf ( Object obj, Type type ) : bool
obj Object
type System.Type
return bool
Ejemplo n.º 1
0
        public static List <T> FindControls <T>(Control seed, string typeFullName, bool shallow) where T : Control
        {
            if (seed == null || string.IsNullOrEmpty(typeFullName))
            {
                return(null);
            }

            seed = (seed is INamingContainer) ? seed : seed.NamingContainer;
            List <T> foundControls = new List <T>();

            foreach (Control control in seed.Controls)
            {
                if (ReflectionUtils.IsTypeOf(control, typeFullName, shallow))
                {
                    foundControls.Add(control as T);
                }

                if (ControlUtils.HasControls(control))
                {
                    foundControls.AddRange(ControlUtils.FindChildControls <T>(control, typeFullName, shallow));
                }
            }

            return(foundControls);
        }
Ejemplo n.º 2
0
        public static Control FindChildControl(Control seed, string typeFullName, bool shallow)
        {
            if (seed == null || string.IsNullOrEmpty(typeFullName))
            {
                return(null);
            }

            Control found = null;

            foreach (Control control in seed.Controls)
            {
                if (ReflectionUtils.IsTypeOf(control, typeFullName, shallow))
                {
                    found = control;
                }
                else if (ControlUtils.HasControls(control))
                {
                    found = ControlUtils.FindChildControl(control, typeFullName, shallow);
                }

                if (found != null)
                {
                    break;
                }
            }

            return(found);
        }
Ejemplo n.º 3
0
        public static T FindChildControl <T>(Control seed, string id) where T : Control
        {
            Control c = ControlUtils.FindChildControl(seed, id);

            if (c != null && !ReflectionUtils.IsTypeOf(c, typeof(T)))
            {
                throw new InvalidCastException(string.Format("The Control ID ('{0}') was found, but it was not a type of {1}. The found Control was a type of {2}.", id, typeof(T).ToString(), c.GetType().ToString()));
            }

            return(c as T);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="control"></param>
        /// <param name="typeFullName"></param>
        /// <returns></returns>
        public static Control GetTypeOfParent(Control control, string typeFullName)
        {
            for (Control parent = control.Parent; parent != null; parent = parent.Parent)
            {
                if (ReflectionUtils.IsTypeOf(parent, typeFullName))
                {
                    return(parent);
                }
            }

            return(null);
        }
Ejemplo n.º 5
0
        private static Control FindControlByTypeName(Control seed, string typeFullName, bool shallow, bool traverse, Control branch)
        {
            if (seed == null || string.IsNullOrEmpty(typeFullName))
            {
                return(null);
            }

            Control root = (seed is INamingContainer) ? seed : seed.NamingContainer;

            if (ReflectionUtils.IsTypeOf(root, typeFullName, shallow))
            {
                return(root);
            }

            Control found   = null;
            string  exclude = (branch != null) ? branch.ID ?? "" : "";

            foreach (Control control in root.Controls)
            {
                if (!exclude.Equals(control.ID))
                {
                    if (ReflectionUtils.IsTypeOf(control, typeFullName, shallow))
                    {
                        found = control;
                    }
                    else if (ControlUtils.HasControls(control))
                    {
                        found = ControlUtils.FindChildControl(control, typeFullName, shallow);
                    }

                    if (found != null)
                    {
                        break;
                    }
                }
            }

            if (traverse && found == null)
            {
                found = ControlUtils.FindControlByTypeName(root.NamingContainer, typeFullName, shallow, traverse, root);
            }

            return(found);
        }
Ejemplo n.º 6
0
        public static List <T> FindChildControls <T>(Control seed, bool shallow) where T : Control
        {
            if (seed == null)
            {
                return(null);
            }

            List <T> foundControls = new List <T>();

            foreach (Control control in seed.Controls)
            {
                if (ReflectionUtils.IsTypeOf(control, typeof(T), shallow))
                {
                    foundControls.Add(control as T);
                }

                if (ControlUtils.HasControls(control))
                {
                    foundControls.AddRange(ControlUtils.FindChildControls <T>(control, shallow));
                }
            }

            return(foundControls);
        }