private void CreateBinaryLoadMethod() { StringBuilder loadMethodBody = new StringBuilder(); foreach (var p in _SaveClass.Properties) { switch (p.Type) { case PropertyType.Primitive: PrimitivePropertyData pp = (PrimitivePropertyData)p; loadMethodBody.AppendLine(string.Format("this.{0} = stream.{1}();", Variable.GetName(p.Name), GetLoadMethodName(pp.PrimitiveType, pp.IsArray, pp.SafeMemory))); break; case PropertyType.Class: ClassPropertyData cp = (ClassPropertyData)p; loadMethodBody.AppendLine(string.Format("this.{0} = stream.{1}( {2}.{3} );", Variable.GetName(p.Name), GetSavableMethodName(cp.ClassName, cp.IsArray), cp.ClassName, GetStaticCreatorMethodName(cp.ClassName))); break; } } loadMethodBody.AppendLine("SetAsClean();"); Method loadBinaryMethod = new Method("void", "Load", loadMethodBody.ToString(), "Skill.Framework.IO.BinaryLoadStream stream"); loadBinaryMethod.Modifier = Modifiers.Public; Add(loadBinaryMethod); }
/// <summary> /// Create variables and properties /// </summary> private void CreateProperties() { foreach (var p in _SaveClass.Properties) { switch (p.Type) { case PropertyType.Primitive: PrimitivePropertyData pp = p as PrimitivePropertyData; if (p.IsArray) { Add(new Variable(string.Format("{0}[]", ConvertToString(pp.PrimitiveType, pp.SafeMemory)), p.Name)); Add(new Property(string.Format("{0}[]", ConvertToString(pp.PrimitiveType, pp.SafeMemory)), p.Name, Variable.GetName(p.Name), true, Property.DirtyMode.CheckAndSet) { Comment = p.Comment }); } else { Add(new Variable(ConvertToString(pp.PrimitiveType, pp.SafeMemory), p.Name)); Add(new Property(ConvertToString(pp.PrimitiveType, pp.SafeMemory), p.Name, Variable.GetName(p.Name), true, Property.DirtyMode.CheckAndSet) { Comment = p.Comment }); } break; case PropertyType.Class: ClassPropertyData cp = p as ClassPropertyData; if (p.IsArray) { Add(new Variable(string.Format("{0}[]", cp.ClassName), p.Name)); Add(new Property(string.Format("{0}[]", cp.ClassName), p.Name, Variable.GetName(p.Name), true, Property.DirtyMode.CheckAndSet) { Comment = p.Comment }); } else { Add(new Variable(cp.ClassName, p.Name)); ClassData cd = FindClass(cp.ClassName); Add(new Property(cp.ClassName, p.Name, Variable.GetName(p.Name), true, cd.IsStruct ? Property.DirtyMode.Set : Property.DirtyMode.CheckAndSet) { Comment = p.Comment }); } break; default: break; } } }
private void CreateXmlLoadMethods() { StringBuilder loadXmlBody = new StringBuilder(); loadXmlBody.AppendLine("Skill.Framework.IO.XmlElement element = e.FirstChild as Skill.Framework.IO.XmlElement;"); loadXmlBody.AppendLine("while (element != null)"); loadXmlBody.AppendLine("{"); loadXmlBody.AppendLine("switch (element.Name)"); loadXmlBody.AppendLine("{"); foreach (var p in _SaveClass.Properties) { loadXmlBody.AppendLine(string.Format("case \"{0}\":", p.Name)); switch (p.Type) { case PropertyType.Primitive: PrimitivePropertyData pp = (PrimitivePropertyData)p; loadXmlBody.AppendLine(string.Format("this.{0} = stream.{1}( element );", Variable.GetName(p.Name), GetLoadMethodName(pp.PrimitiveType, pp.IsArray, pp.SafeMemory))); break; case PropertyType.Class: ClassPropertyData cp = (ClassPropertyData)p; loadXmlBody.AppendLine(string.Format("this.{0} = stream.{1}( element , {2}.{3} );", Variable.GetName(p.Name), GetSavableMethodName(cp.ClassName, cp.IsArray), cp.ClassName, GetStaticCreatorMethodName(cp.ClassName))); break; } loadXmlBody.AppendLine("break;"); } loadXmlBody.AppendLine("}"); loadXmlBody.AppendLine("element = e.GetNextSibling(element);"); loadXmlBody.AppendLine("}"); loadXmlBody.AppendLine("SetAsClean();"); Method loadMethod = new Method("void", "Load", loadXmlBody.ToString(), "Skill.Framework.IO.XmlElement e", "Skill.Framework.IO.XmlLoadStream stream"); loadMethod.Modifier = Modifiers.Public; Add(loadMethod); }