Example #1
0
 private static void SerializeMembers(IEnumerable <XmlClassMember> members, string dataTypeId, CodeFormatter code, bool isSerializableItem)
 {
     if (isSerializableItem)
     {
         code.Add("serializable.Id = ItemId.Id;");
         code.Add("serializable.FileName = ItemId.Name;");
         code.Add("serializable.ItemType = (int)ItemType.", dataTypeId, ";");
     }
     foreach (var item in members)
     {
         CommonCodeGenerator.WriteSerializationCode(item, code);
     }
 }
Example #2
0
        private void AddContentClasses(string objectName, Dictionary <string, List <XmlClassMember> > members, GeneratorSettings settings, CodeFormatter code)
        {
            var serializableName = CommonCodeGenerator.SerializableClass(objectName);

            code.Add("private interface ", ContentInterfaceName, " { ", serializableName, " ", settings.SerializeMethod, "(); }");
            code.NewLine();

            code.Class(EmptyContentClassName, false, ContentInterfaceName);
            CommonCodeGenerator.WriteObjectSerializer(objectName, settings, code);
            code.Add("return new ", serializableName, "();");
            code.CloseBraces();
            code.CloseBraces();

            foreach (var item in members)
            {
                var className = GetContentClassName(item.Key);
                code.Class(className, false, ContentInterfaceName);

                code.Add("public ", className, "(", serializableName, " serializable, ", settings.DatabaseClass, " database)");
                code.OpenBraces();
                code.Add("if (serializable == null || database == null) return;");
                foreach (var member in item.Value)
                {
                    CommonCodeGenerator.WriteDeserializationCode(member, code, settings);
                }
                code.CloseBraces();
                code.NewLine();

                CommonCodeGenerator.WriteObjectSerializer(objectName, settings, code);
                code.Add("var serializable = new ", serializableName, "();");
                foreach (var member in item.Value)
                {
                    CommonCodeGenerator.WriteSerializationCode(member, code);
                }
                code.Add("return serializable;");
                code.CloseBraces();
                code.NewLine();

                foreach (var member in item.Value)
                {
                    CommonCodeGenerator.WriteDataMember(member, code, _schema);
                }

                code.CloseBraces();
                code.NewLine();
            }
        }