Exemplo n.º 1
0
        public static Table Table(string name, List <IBHoMObject> bhomObjects, bool ignoreName = false, bool ignoreGuid = true, bool ignoreTags = true)
        {
            IBHoMObject first = bhomObjects.First();

            Dictionary <string, Type> propertyTypes = first.PropertyTypeDictionary();

            List <DataColumn> columns = new List <DataColumn>();

            propertyTypes.CleanUnwantedProperties(ignoreName, ignoreGuid, ignoreTags);

            foreach (var kvp in propertyTypes)
            {
                columns.Add(new DataColumn(kvp.Key, kvp.Value));
            }

            DataTable table = new DataTable();

            table.Columns.AddRange(columns.ToArray());

            foreach (IBHoMObject obj in bhomObjects)
            {
                Dictionary <string, object> props = obj.PropertyDictionary();
                props.CleanUnwantedProperties(ignoreName, ignoreGuid, ignoreTags);

                DataRow row = table.NewRow();

                foreach (var kvp in props)
                {
                    row[kvp.Key] = kvp.Value;
                }
                table.Rows.Add(row);
            }

            return(new Table {
                Data = table, Name = name
            });
        }