public static string Save(string fullFileName, BH.oM.XML.GBXML gbx) { try { System.Reflection.PropertyInfo[] bhomProperties = typeof(BHoMObject).GetProperties(); XmlAttributeOverrides overrides = new XmlAttributeOverrides(); foreach (System.Reflection.PropertyInfo pi in bhomProperties) { overrides.Add(typeof(BHoMObject), pi.Name, new XmlAttributes { XmlIgnore = true }); } XmlSerializerNamespaces xns = new XmlSerializerNamespaces(); XmlSerializer szer = new XmlSerializer(typeof(BH.oM.XML.GBXML), overrides); TextWriter ms = new StreamWriter(fullFileName); szer.Serialize(ms, gbx, xns); ms.Close(); return("Written Ok"); } catch (Exception e) { return(e.ToString()); } }
public static BH.oM.XML.GBXML Load(string fileName) { BH.oM.XML.GBXML gbx = null; TextReader reader = new StreamReader(fileName); XmlSerializer szer = new XmlSerializer(typeof(BH.oM.XML.GBXML)); gbx = (BH.oM.XML.GBXML)szer.Deserialize(reader); reader.Close(); return(gbx); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static void SerializeCollection(IEnumerable <Building> inputBuildings, BH.oM.XML.GBXML gbx, XMLSettings settings) { List <Building> buildings = inputBuildings.ToList(); gbx.Campus.Building = new oM.XML.Building[buildings.Count]; for (int x = 0; x < buildings.Count; x++) { gbx.Campus.Building[x] = buildings[x].ToGBXML(); gbx.Campus.Location = buildings[x].ToGBXMLLocation(); BHP.BuildingContextFragment props = buildings[x].FindFragment <BHP.BuildingContextFragment>(typeof(BHP.BuildingContextFragment)); if (props != null) { gbx.Campus.Building[x].StreetAddress = props.PlaceName; } if (buildings[x].CustomData.ContainsKey("Building Name")) { gbx.Campus.Building[x].BuildingType = (buildings[x].CustomData["Building Name"]).ToString(); } } }