private void ReadParticleManager(IList <IAetherManager> particleManagers) { string managerName = reader.ReadString(); string assemblyQualifiedName = reader.ReadString(); Type managerType = Type.GetType(assemblyQualifiedName); IAetherManager manager = null; foreach (IAetherManager mgr in particleManagers) { if (mgr.Name == managerName) { manager = mgr; break; } } if (manager == null) { manager = (IAetherManager)Activator.CreateInstance(managerType); particleManagers.Add(manager); if (manager is IInitializable) { ((IInitializable)manager).Initialize(this.Engine); } } IAetherSerialization serialisableParticle = manager as IAetherSerialization; bool isSerialisableParticle = reader.ReadBoolean(); if (isSerialisableParticle) { System.Diagnostics.Debug.Assert(manager != null, "According to the binary file, manager should be IAetherSerialization."); serialisableParticle.Load(this); } }
private void WriteParticle(UniqueID uid, IAether particle) { string particleName = Engine.GetParticleName(particle); uid.Save(this); bool isParticleSerialized = serialisedParticles.Contains(uid); writer.Write(isParticleSerialized); if (!isParticleSerialized) { if (!uid.Equals(UniqueID.Unknown)) { serialisedParticles.Add(uid); } writer.Write(particleName); //name Type particleType = particle.GetType(); string typeName = particleType.FullName + ", " + particleType.Assembly.GetName().Name; writer.Write(typeName); //type IAetherSerialization serialisableParticle = particle as IAetherSerialization; bool isSerialisableParticle = serialisableParticle != null; writer.Write(isSerialisableParticle); //mark whether Particle has data to serialize if (isSerialisableParticle) { serialisableParticle.Save(this); } } return; }
private void ReadParticleManager(IList <IAetherManager> particleManagers) { string elementName = reader.Name; //read attribute string managerName = string.Empty; string type = string.Empty; while (reader.MoveToNextAttribute()) { switch (reader.Name) { case "Name": managerName = reader.ReadContentAsString(); break; case "Type": type = reader.ReadContentAsString(); break; } } reader.MoveToElement(); bool isEmptyElement = reader.IsEmptyElement; reader.ReadStartElement(); if (elementName == "AetherParticleManager") { IAetherManager manager = null; foreach (IAetherManager mgr in particleManagers) { if (mgr.Name == managerName) { manager = mgr; break; } } if (manager == null) { manager = (IAetherManager)Activator.CreateInstance(Type.GetType(type, false)); particleManagers.Add(manager); if (manager is IInitializable) { ((IInitializable)manager).Initialize(this.Engine); } } IAetherSerialization serialisableParticle = manager as IAetherSerialization; if (serialisableParticle != null) { serialisableParticle.Load(this); } if (!isEmptyElement) { reader.ReadEndElement(); } } return; }
private void WriteParticleManager(IAetherManager manager) { writer.Write(manager.Name); Type managerType = manager.GetType(); string typeName = managerType.FullName + ", " + managerType.Assembly.GetName().Name; writer.Write(typeName); IAetherSerialization serialisableParticle = manager as IAetherSerialization; bool isSerialisableParticle = serialisableParticle != null; writer.Write(isSerialisableParticle); if (isSerialisableParticle) { serialisableParticle.Save(this); } }
private void WriteParticleManager(IAetherManager manager) { Type managerType = manager.GetType(); writer.WriteStartElement("AetherParticleManager"); writer.WriteAttributeString("Name", manager.Name); string typeName = managerType.FullName + ", " + managerType.Assembly.GetName().Name; writer.WriteAttributeString("Type", typeName); IAetherSerialization serialisableParticle = manager as IAetherSerialization; if (serialisableParticle != null) { serialisableParticle.Save(this); } writer.WriteEndElement(); }
private void ReadParticle(out UniqueID uid, out IAether particle) { uid = new UniqueID(); uid.Load(this); bool isParticleSerialized = reader.ReadBoolean(); if (isParticleSerialized) { particle = deserialisedParticles[uid]; return; } string particleName = reader.ReadString(); string AssemblyQualifiedName = reader.ReadString(); if (Engine.ContainsName(particleName)) { particle = Engine[particleName]; } else { particle = TypeResolver.CreateInstance(AssemblyQualifiedName); } if (!uid.Equals(UniqueID.Unknown)) { deserialisedParticles.Add(uid, particle); } bool isSerialisableParticle = reader.ReadBoolean(); if (isSerialisableParticle) { IAetherSerialization serialisableParticle = particle as IAetherSerialization; serialisableParticle.Load(this); } if (particleName != string.Empty) { Engine.SetParticleName(particle, particleName); } return; }
private void WriteParticle(UniqueID uid, IAether particle) { string particleName = Engine.GetParticleName(particle); if (serialisedParticles.Contains(uid)) { writer.WriteStartElement("AetherParticleRef"); writer.WriteStartAttribute("UID"); uid.Save(this); writer.WriteEndAttribute(); if (particleName != String.Empty) { writer.WriteAttributeString("Name", particleName); } writer.WriteEndElement(); return; } else { Type particleType = particle.GetType(); if (!uid.Equals(UniqueID.Unknown)) { serialisedParticles.Add(uid); } writer.WriteStartElement("AetherParticle"); writer.WriteStartAttribute("UID"); uid.Save(this); writer.WriteEndAttribute(); if (particleName != String.Empty) { writer.WriteAttributeString("Name", particleName); } string typeName = particleType.FullName + ", " + particleType.Assembly.GetName().Name; writer.WriteAttributeString("Type", typeName); IAetherSerialization serialisableParticle = particle as IAetherSerialization; if (serialisableParticle != null) { serialisableParticle.Save(this); } writer.WriteEndElement(); } return; }
public void Write(string name, IAetherSerialization value) { writer.WriteStartElement(name); value.Save(this); writer.WriteEndElement(); }
public void Write(string name, IAetherSerialization value) { //writer.Write(name); value.Save(this); }
public void Read(string name, IAetherSerialization value) { reader.ReadStartElement(name); value.Load(this); reader.ReadEndElement(); }
private void ReadParticle(out UniqueID uid, out IAether particle) { uid = new UniqueID(); particle = null; string elementName = reader.Name; //read attribute string particleName = string.Empty; string typeName = string.Empty; while (reader.MoveToNextAttribute()) { switch (reader.Name) { case "UID": uid.Load(this); break; case "Name": particleName = reader.ReadContentAsString(); break; case "Type": typeName = reader.ReadContentAsString(); break; } } reader.MoveToElement(); bool isEmptyElement = reader.IsEmptyElement; reader.ReadStartElement(); if (elementName == "AetherParticleRef") { particle = deserialisedParticles[uid]; } else if (elementName == "AetherParticle") { if (Engine.ContainsName(particleName)) { //TOD: is this even possible? //isn't it a bug to deserialize an object using a name for cache key? //System.Diagnostics.Debug.Assert(false); particle = Engine[particleName]; } else { particle = TypeResolver.CreateInstance(typeName); } if (!uid.Equals(UniqueID.Unknown)) { deserialisedParticles.Add(uid, particle); } //particle = (IAetherParticle)FormatterServices.GetUninitializedObject(particleType); //this behaves the same the build in Serialisation. Not available on WP7 IAetherSerialization serialisableParticle = particle as IAetherSerialization; if (serialisableParticle != null) { serialisableParticle.Load(this); } particle = TypeResolver.Convert(particle); deserialisedParticles[uid] = particle; // update converted particle if (particleName != string.Empty) { Engine.SetParticleName(particle, particleName); } if (!isEmptyElement) { reader.ReadEndElement(); } } return; }
public void Read(string name, IAetherSerialization value) { //string name2 = reader.ReadString(); //System.Diagnostics.Debug.Assert(name == name2); value.Load(this); }