public void WriteSaveData(System.Xml.XmlWriter writer) { //We simply skip null values; if (value == null) { return; } writer.WriteStartElement("Data"); writer.WriteAttributeString("Key", key); // Todo: does this create a security hole? Though mods can do everything anyway, this may abuse a mod to do sth harmful. Consider it! writer.WriteAttributeString("Type", value.GetType().AssemblyQualifiedName); var dcs = new DataContractSerializer(value.GetType(), "", "", null, Int32.MaxValue, false, false, null, ModSaveFile.GetDataContractResolver()); dcs.WriteObjectContent(writer, value); //var dcjs = new System.Runtime.Serialization.Json.DataContractJsonSerializer(value.GetType() writer.WriteEndElement(); }
public DataItem(XElement el) { try { // Todo: handle invalid data properly!! key = el.Attribute("Key").Value; var type = Type.GetType(el.Attribute("Type").Value, true); //if( type.IsPrimitive ) // TODO: Complete member initialization# var dcs = new DataContractSerializer(type, null, int.MaxValue, false, false, null, ModSaveFile.GetDataContractResolver()); var tmpReader = el.CreateReader(); tmpReader.MoveToContent(); value = dcs.ReadObject(tmpReader, false); } catch (Exception) { isInvalid = true; } return; }