コード例 #1
0
        private void serializeObjects(List <IModelObject> list, StreamWriter wr)
        {
            //       // TODO: Haxor for debug info!!!
            //strm.WriteLine((string)obj.GetType().GetField("DEBUG_CREATEDBY", BindingFlags.NonPublic| BindingFlags.Instance).GetValue(obj));
            //(string)obj.GetType().GetField("DEBUG_CREATEDBY", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(obj,reader.ReadLine());
            //// TODO: Haxor for debug info!!!
            //strm.WriteLine(.GetValue(obj));

            var strm = new SectionedStreamWriter(wr);

            myObjectDictionary.Clear();

            // Write all objects
            strm.EnterSection(ObjectsSection);
            foreach (var obj in list)
            {
                var id = myObjectDictionary.getObjectID(obj);
                strm.WriteLine(id.ToString());
                strm.WriteLine(typeSerializer.Serialize(obj.GetType()));
            }
            strm.ExitSection();

            // Write all attributes
            strm.EnterSection(AttributesSection);
            foreach (var obj in list)
            {
                var id = myObjectDictionary.getObjectID(obj);
                strm.WriteLine(id.ToString());
                SerializeAttributes(obj, strm);
            }
            strm.ExitSection();
        }
コード例 #2
0
        /// <summary>
        /// Writes a string serialized attribute value to the stream
        /// </summary>
        /// <param name="strm"></param>
        /// <param name="serialized"></param>
        private static void writeAttributeData(SectionedStreamWriter strm, string serialized)
        {
            if (serialized.Contains('\n'))
            {
                var sublength = serialized.Length;
                if (serialized[serialized.Length - 1] == '\n')
                {
                    sublength--;
                }
                else
                {
                    throw new InvalidOperationException(
                              "Provided serialized data cannot be used since it doesnt end with \n");
                }
                if (serialized[serialized.Length - 2] == '\r')
                {
                    sublength--;
                }


                // Write section
                strm.EnterSection("AttributeData");
                strm.WriteLine(serialized.Substring(0, sublength));
                strm.ExitSection();
            }
            else
            {
                strm.WriteLine(serialized);
            }
        }
コード例 #3
0
        public void SerializeAttributes(IModelObject obj, SectionedStreamWriter strm)
        {
            var allAttributes = ReflectionHelper.GetAllAttributes(obj.GetType());


            strm.EnterSection("EntityAttributes");

            foreach (var att in allAttributes)
            {
                var value = att.GetData(obj);
                if (value == null)
                {
                    continue;
                }

                writeAttribute(strm, att, value);
            }
            strm.ExitSection();
        }