Esempio n. 1
0
        private static Node     Browse(Node parent, object instance)
        {
            Type type = instance.GetType();
            Node node = new Node(parent, type.FullName);

            foreach (FieldInfo field in Utility.EachFieldHierarchyOrdered(type, typeof(object), SettingsExporter.SearchFlags))
            {
                if (field.IsDefined(typeof(ExportableAttribute), true) == true)
                {
                    node.children.Add(SettingsExporter.Browse(node, field, field.GetValue(instance)));
                }
            }

            foreach (PropertyInfo property in Utility.EachPropertyHierarchyOrdered(type, typeof(object), SettingsExporter.SearchFlags))
            {
                if (property.IsDefined(typeof(ExportableAttribute), true) == true)
                {
                    node.children.Add(SettingsExporter.Browse(node, property, property.GetValue(instance, null)));
                }
            }

            if (type.IsDefined(typeof(HideFromExportAttribute), true) == true)
            {
                node.options = Node.Option.Hidden;
            }

            return(node);
        }
Esempio n. 2
0
        public static Node      Collect(params object[] instances)
        {
            Node root = new Node(null, "ROOT");

            for (int i = 0; i < instances.Length; i++)
            {
                root.children.Add(SettingsExporter.Browse(null, instances[i]));
            }

            return(root);
        }
Esempio n. 3
0
        private static Node     Browse(Node parent, PropertyInfo property, object instance)
        {
            Node node = new Node(parent, property.Name);

            if (instance == null)
            {
                return(node);
            }

            if (property.PropertyType.IsPrimitive == true ||
                property.PropertyType == typeof(string))
            {
                node.value = instance.ToString();
            }
            else if (property.PropertyType.IsArray == true ||
                     instance is IEnumerable)
            {
                IEnumerable array = instance as IEnumerable;
                int         count = 0;

                foreach (var item in array)
                {
                    if (item.GetType().IsDefined(typeof(ExcludeFromExportAttribute), true) == false)
                    {
                        node.children.Add(SettingsExporter.Browse(node, item));
                        ++count;
                    }
                }
                node.value = count.ToString();
            }
            else if (property.PropertyType.IsClass == true ||
                     property.PropertyType.IsStruct() == true)
            {
                ExportableAttribute[] attributes = property.GetCustomAttributes(typeof(ExportableAttribute), true) as ExportableAttribute[];

                if (attributes.Length > 0 && attributes[0].fields != null)
                {
                    for (int j = 0; j < attributes[0].fields.Length; j++)
                    {
                        FieldInfo fi = property.PropertyType.GetField(attributes[0].fields[j]);

                        InternalNGDebug.Assert(fi != null, "Field \"" + attributes[0].fields[j] + "\" was not found in type " + property.PropertyType + ".");

                        node.children.Add(SettingsExporter.Browse(node, fi, fi.GetValue(instance)));
                    }
                }

                foreach (FieldInfo subField in Utility.EachFieldHierarchyOrdered(property.PropertyType, typeof(object), SettingsExporter.SearchFlags))
                {
                    if (subField.IsDefined(typeof(ExportableAttribute), true) == true)
                    {
                        node.children.Add(SettingsExporter.Browse(node, subField, subField.GetValue(instance)));
                    }
                }

                foreach (PropertyInfo subProperty in Utility.EachPropertyHierarchyOrdered(property.PropertyType, typeof(object), SettingsExporter.SearchFlags))
                {
                    if (subProperty.IsDefined(typeof(ExportableAttribute), true) == true)
                    {
                        node.children.Add(SettingsExporter.Browse(node, subProperty, subProperty.GetValue(instance, null)));
                    }
                }
            }

            if (property.IsDefined(typeof(HideFromExportAttribute), true) == true)
            {
                node.options = Node.Option.Hidden;
            }

            return(node);
        }