/// <summary> /// Constructor. /// </summary> public EnumItemTracerFilter(Tracer tracer) : base(tracer) { // Find all candidate enum types and assemblies they reside in. List <Type> possibleEnumTypes = ReflectionHelper.GatherTypeChildrenTypesFromAssemblies(typeof(Enum), ReflectionHelper.GetApplicationEntryAssemblyAndReferencedAssemblies()); for (int i = possibleEnumTypes.Count - 1; i >= 0; i--) { object[] attributes = possibleEnumTypes[i].GetCustomAttributes(typeof(TracerEnumAttribute), true); if (attributes == null || attributes.Length == 0) { possibleEnumTypes.RemoveAt(i); } else { _assemblies.Add(possibleEnumTypes[i].Assembly); } } }
/// <summary> /// Helper method allows to retrieve initial assembly referenced (static and runtime) assemblies. /// </summary> static public ListEx <Assembly> GetReferencedAssemblies(Assembly initialAssembly) { ListEx <Assembly> result = new ListEx <Assembly>(); AssemblyName[] names = initialAssembly.GetReferencedAssemblies(); for (int i = 0; i < names.Length; i++) { result.Add(Assembly.Load(names[i])); } lock (_dynamicReferencedAssemblies) { if (_dynamicReferencedAssemblies.ContainsKey(initialAssembly)) { result.AddRange(_dynamicReferencedAssemblies[initialAssembly]); } } return(result); }
/// <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); }
public virtual bool AddSlaveControl(ITimeControl control) { lock (_slaveControls) { return(_slaveControls.Add(control)); } }