/// <summary> /// Will create a control using reflection, corresponding to the object passed it. In order for the control to be recognized /// it must take as a constructor paramterer the type passed in. /// </summary> /// <param name="component"></param> /// <param name="allowComponentBaseTypes">This indicates whether the search for corresponding control should also cover parent types of the given type</param> /// <returns></returns> static public CommonBaseControl CreateCorrespondingControl(object component, bool allowComponentBaseTypes) { Type componentType = component.GetType(); ListEx <Assembly> assemblies = ReflectionHelper.GetReferencedAndInitialAssembly(Assembly.GetEntryAssembly()); assemblies.Add(Assembly.GetAssembly(componentType)); List <Type> types = ReflectionHelper.GatherTypeChildrenTypesFromAssemblies(typeof(CommonBaseControl), true, false, assemblies, new Type[] { componentType }); if (types.Count == 0 && allowComponentBaseTypes) { while (componentType != typeof(object) && types.Count == 0) { componentType = componentType.BaseType; types = ReflectionHelper.GatherTypeChildrenTypesFromAssemblies(typeof(CommonBaseControl), true, false, assemblies, new Type[] { componentType }); } } if (types.Count == 0) {// Type not found. return(null); } string typesNames = string.Empty; if (types.Count > 1) { foreach (Type type in types) { typesNames += type.Name + "();"; } SystemMonitor.CheckWarning(types.Count == 1, "More than 1 control found for this type [" + component.GetType().Name + "][" + typesNames + "] of component, creating the first one."); } // Return the first proper object. CommonBaseControl control = (CommonBaseControl)types[0].GetConstructor(new Type[] { componentType }).Invoke(new object[] { component }); control.Tag = component; return(control); }
/// <summary> /// /// </summary> public ApplicationControlAutomationManager(Control topLevelControl) { SystemMonitor.CheckWarning(topLevelControl.Parent == null, "Application control automation manager is expected to start at top level control; some controls may be missed."); RegisterControl(topLevelControl); }