Ejemplo n.º 1
0
        static void ConvertVariableToABSave(ABSaveType type, StringBuilder sb, ABSaveSettings settings, Helpers.ABSaveObjectItems members, ref bool notFirst, ref ABSavePrimitiveType lastType, int i)
        {
            // If we're doing it named - write the name.
            if (type == ABSaveType.WithNames)
            {
                // Write the name out, don't write the Next Instruction character if it's the first item or the last item had a "lowerInnerlevel" sign after it.
                ABSaveWriter.WriteString(members.Items[i].Info.Name, ABSaveUtils.RequiresLowerInnerLevelSymbol(lastType) ? false : notFirst, true, sb);

                // Since we've written the name out... And the "notFirst" variable is used to determine whether to write the next instruction symbol or not... Set "notFirst" to true since it will HAVE to have the next instruction symbol now.
                notFirst = true;
            }

            // Serialize each variable, to the StringBuilder. If the last member was an array or object, then instead of getting it to write the
            // "next instruction" character, we need to get it to write the "lower" symbol instead.
            ABSaveSerializer.Serialize(members.Items[i].Value, type, settings, out lastType, true, sb, ABSaveUtils.RequiresLowerInnerLevelSymbol(lastType) ? false : notFirst, i == members.Count - 1);

            // Update the "notFirst" variable if it's false and we've gone through one item.
            if (!notFirst)
            {
                notFirst = true;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Turns a whole object into ABSave, and places the result in a StringBuilder.
        /// (Does not include anything extra, such as "\u0003" or the type that goes before - for that, use <see cref="ABSaveSerializer.SerializeObject(object, ABSaveType, System.Type, ABSaveSettings, bool, bool, StringBuilder, bool)"/>)
        /// </summary>
        public static void ObjectToABSave(object obj, ABSaveType type, StringBuilder sb, ABSaveSettings settings)
        {
            // If the object is null, don't bother with doing anything.
            if (obj == null)
            {
                return;
            }

            // Get all of the variables inside this object.
            var members = ABSaveUtils.GetFieldsAndPropertiesWithValues(obj);

            // This is a variable used across the whole process to decide whether this is the first one or not (to write the "Next Item" character or not).
            var notFirst = false;

            // Keep track of what type the last property was - this allows us to decide whether to add the Next Item character to the next item.
            var lastType = ABSavePrimitiveType.Unknown;

            // Go through each variable, and process it.
            for (var i = 0; i < members.Count; i++)
            {
                ConvertVariableToABSave(type, sb, settings, members, ref notFirst, ref lastType, i);
            }
        }