Beispiel #1
0
        /// <summary>
        /// Find all the configurable fields in the given types by searching for XmlConfigFile attributes.
        /// </summary>
        /// <param name="ConfigTypes">Array of types to search</param>
        /// <param name="CategoryToFields">Dictionaries populated with category -> name -> field mappings on return</param>
        static void FindConfigurableFields(IEnumerable <Type> ConfigTypes, Dictionary <string, Dictionary <string, FieldInfo> > CategoryToFields)
        {
            foreach (Type ConfigType in ConfigTypes)
            {
                foreach (FieldInfo FieldInfo in ConfigType.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic))
                {
                    IEnumerable <XmlConfigFileAttribute> Attributes = FieldInfo.GetCustomAttributes <XmlConfigFileAttribute>();
                    foreach (XmlConfigFileAttribute Attribute in Attributes)
                    {
                        string CategoryName = Attribute.Category ?? ConfigType.Name;

                        Dictionary <string, FieldInfo> NameToField;
                        if (!CategoryToFields.TryGetValue(CategoryName, out NameToField))
                        {
                            NameToField = new Dictionary <string, FieldInfo>();
                            CategoryToFields.Add(CategoryName, NameToField);
                        }

                        NameToField[Attribute.Name ?? FieldInfo.Name] = FieldInfo;
                    }
                }
            }
        }