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 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; }