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); }
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); }
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); }
/// <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); }
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); }
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); }